liff-functions.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. function getProfile() {
  2. liff
  3. .getProfile()
  4. .then(profile => {
  5. console.log(JSON.stringify(profile));
  6. window.alert(JSON.stringify(profile));
  7. })
  8. .catch(e => {
  9. console.log(e);
  10. window.alert(e);
  11. });
  12. }
  13. function getAccessToken() {
  14. window.alert(liff.getAccessToken());
  15. }
  16. function getContext() {
  17. window.alert(JSON.stringify(liff.getContext()));
  18. }
  19. function sendMessage() {
  20. liff
  21. .sendMessages([{ type: "text", text: "中文測試 Hello from LIFF2.0" }])
  22. .then(() => {
  23. window.alert("Message has been sent");
  24. })
  25. .catch(e => {
  26. window.alert(e);
  27. });
  28. }
  29. function login() {
  30. liff.login();
  31. }
  32. function scanCode() {
  33. liff
  34. .scanCode()
  35. .then(result => {
  36. window.alert(JSON.stringify(result));
  37. })
  38. .catch(e => {
  39. window.alert(e);
  40. });
  41. }
  42. function openWindow() {
  43. liff.openWindow({
  44. url: "https://line.me/1657386781-XARmDogn",
  45. external: true
  46. });
  47. }
  48. function closeWindow() {
  49. liff.closeWindow();
  50. }
  51. function logout() {
  52. if (liff.isLoggedIn()) {
  53. liff.logout();
  54. window.alert("Successfully to Logout");
  55. location.reload();
  56. }
  57. }
  58. // function createFlexMessageData() {
  59. // var flex = {
  60. // "type": "flex",
  61. // "altText": redistitle,
  62. // "contents": redisdata,
  63. // };
  64. // return flex;
  65. // }
  66. var _title = "MISA 向您分享了最新消息!";
  67. function createFlexMessageData() {
  68. var myFlexContent = {
  69. "type": "bubble",
  70. "hero": {
  71. "type": "box",
  72. "layout": "vertical",
  73. "contents": [
  74. {
  75. "type": "box",
  76. "layout": "vertical",
  77. "contents": [
  78. {
  79. "type": "text",
  80. "text": "有貪婪老闆,必有貪污員工",
  81. "color": "#f39a00",
  82. "align": "center",
  83. "offsetTop": "3px",
  84. "size": "lg",
  85. "weight": "bold"
  86. }
  87. ],
  88. "paddingAll": "15px"
  89. },
  90. {
  91. "type": "box",
  92. "layout": "vertical",
  93. "contents": [
  94. {
  95. "type": "image",
  96. "size": "full",
  97. "margin": "none",
  98. "url": "https://imgur.com/r8w9gsF.jpg",
  99. "offsetTop": "-10px"
  100. }
  101. ],
  102. "paddingStart": "5px",
  103. "paddingEnd": "5px",
  104. "height": "190px"
  105. }
  106. ]
  107. },
  108. "body": {
  109. "type": "box",
  110. "layout": "vertical",
  111. "contents": [
  112. {
  113. "type": "text",
  114. "text": "老闆的道德標準",
  115. "weight": "bold",
  116. "size": "md",
  117. "align": "center",
  118. "wrap": true,
  119. "margin": "sm"
  120. },
  121. {
  122. "type": "text",
  123. "text": "是員工道德標準的上限",
  124. "weight": "bold",
  125. "size": "md",
  126. "align": "center",
  127. "wrap": true,
  128. "margin": "sm"
  129. },
  130. {
  131. "type": "text",
  132. "text": "絕對是公司每個人的「榜樣」",
  133. "weight": "bold",
  134. "size": "md",
  135. "align": "center",
  136. "wrap": true,
  137. "margin": "sm"
  138. },
  139. {
  140. "type": "text",
  141. "text": "而身為老闆最好的態度是:",
  142. "weight": "bold",
  143. "size": "md",
  144. "align": "center",
  145. "wrap": true,
  146. "margin": "xxl"
  147. },
  148. {
  149. "type": "text",
  150. "text": "利益迴避,公私分明",
  151. "weight": "bold",
  152. "size": "md",
  153. "align": "center",
  154. "wrap": true,
  155. "margin": "sm"
  156. },
  157. {
  158. "type": "separator",
  159. "margin": "lg"
  160. },
  161. {
  162. "type": "text",
  163. "text": "城邦媒體 何飛鵬社長 用真實案例",
  164. "weight": "bold",
  165. "size": "md",
  166. "align": "center",
  167. "wrap": true,
  168. "margin": "lg"
  169. },
  170. {
  171. "type": "text",
  172. "text": "帶領你進入主管必修的私房學",
  173. "weight": "bold",
  174. "size": "md",
  175. "align": "center",
  176. "wrap": true,
  177. "margin": "sm"
  178. }
  179. ],
  180. "offsetTop": "-20px"
  181. },
  182. "footer": {
  183. "type": "box",
  184. "layout": "vertical",
  185. "spacing": "sm",
  186. "contents": [
  187. {
  188. "type": "box",
  189. "layout": "vertical",
  190. "contents": [
  191. {
  192. "type": "button",
  193. "style": "link",
  194. "height": "sm",
  195. "action": {
  196. "type": "uri",
  197. "label": "立即上課",
  198. "uri": "https://www.misaglobal.org/program-packages/37397536-2d1e-44eb-b59a-fb0baa4646bf"
  199. },
  200. "color": "#ffffff"
  201. }
  202. ],
  203. "backgroundColor": "#f39a00",
  204. "cornerRadius": "md"
  205. },
  206. {
  207. "type": "box",
  208. "layout": "vertical",
  209. "contents": [
  210. {
  211. "type": "button",
  212. "style": "link",
  213. "height": "sm",
  214. "action": {
  215. "type": "uri",
  216. "label": "活動分享",
  217. "uri": "https://liff.googo.org/misa-program-5/?openInAppBrowser=1&openExternalBrowser=1"
  218. },
  219. "color": "#f39a00"
  220. }
  221. ],
  222. "cornerRadius": "md",
  223. "margin": "lg",
  224. "borderColor": "#f39a00",
  225. "borderWidth": "normal"
  226. },
  227. {
  228. "type": "box",
  229. "layout": "vertical",
  230. "contents": [
  231. {
  232. "type": "button",
  233. "style": "link",
  234. "height": "sm",
  235. "action": {
  236. "type": "uri",
  237. "label": "3 分鐘精華",
  238. "uri": "https://www.youtube.com/watch?v=hLGQN0qWDm0&t=7s"
  239. },
  240. "color": "#f39a00"
  241. }
  242. ],
  243. "cornerRadius": "md",
  244. "margin": "lg",
  245. "borderColor": "#f39a00",
  246. "borderWidth": "normal"
  247. },
  248. {
  249. "type": "box",
  250. "layout": "vertical",
  251. "contents": [
  252. {
  253. "type": "image",
  254. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  255. }
  256. ],
  257. "margin": "none",
  258. "position": "absolute",
  259. "offsetStart": "108px",
  260. "offsetTop": "135px"
  261. }
  262. ],
  263. "flex": 0,
  264. "height": "195px",
  265. "offsetTop": "-10px"
  266. }
  267. };
  268. var flex = {
  269. "type": "flex",
  270. "altText": _title,
  271. "contents": myFlexContent,
  272. };
  273. return flex;
  274. }
  275. var redisdata = '';
  276. function shareTargetPicker() {
  277. liff.shareTargetPicker([
  278. createFlexMessageData()
  279. ])
  280. .then(function (res) {
  281. if (res) {
  282. // succeeded in sending a message through TargetPicker
  283. console.log(`[${res.status}] Message sent!`)
  284. } else {
  285. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  286. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  287. // LINE 10.3.0 - 10.10.0
  288. // Old LINE will access here regardless of user's action
  289. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  290. } else {
  291. // LINE 10.11.0 -
  292. // sending message canceled
  293. console.log('TargetPicker was closed!')
  294. }
  295. }
  296. }).catch(function (error) {
  297. // something went wrong before sending a message
  298. console.log('something wrong happen', error)
  299. })
  300. // const url = 'https://liff.googo.org:9898/misa-liff'
  301. // axios
  302. // .get(url)
  303. // .then(({data}) => {
  304. // redisdata=data.data;
  305. // redistitle=data.title;
  306. // console.log(redistitle);
  307. // console.log(redisdata);
  308. // liff.shareTargetPicker([
  309. // {
  310. // type: "text",
  311. // text: "Test!"
  312. // }
  313. // ])
  314. // .then(
  315. // console.log("ShareTargetPicker was launched")
  316. // ).catch(function (res) {
  317. // alert(res);
  318. // console.log("Failed to launch ShareTargetPicker", res)
  319. // })
  320. // // liff
  321. // // .shareTargetPicker([
  322. // // createFlexMessageData()
  323. // // ])
  324. // // .then(() => {
  325. // // alert("Shared to the friend(s) you picked");
  326. // // })
  327. // // .catch(function(res) {
  328. // // alert(res);
  329. // // });
  330. // });
  331. }