liff-functions.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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": "MISA 行動 EMBA 學程",
  81. "color": "#f39a00",
  82. "align": "center",
  83. "offsetTop": "3px",
  84. "size": "md",
  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/TN7Nfyc.jpg"
  99. }
  100. ],
  101. "paddingStart": "5px",
  102. "paddingEnd": "5px",
  103. "height": "200px"
  104. }
  105. ]
  106. },
  107. "body": {
  108. "type": "box",
  109. "layout": "vertical",
  110. "contents": [
  111. {
  112. "type": "text",
  113. "text": "周青麟董事長白手起家創立至寶光電",
  114. "weight": "bold",
  115. "size": "sm",
  116. "align": "center",
  117. "wrap": true
  118. },
  119. {
  120. "type": "text",
  121. "text": "產品以多品牌行銷全球",
  122. "weight": "bold",
  123. "size": "sm",
  124. "align": "center",
  125. "wrap": true,
  126. "margin": "sm"
  127. },
  128. {
  129. "type": "text",
  130. "text": "並於 2004 年上櫃",
  131. "weight": "bold",
  132. "size": "sm",
  133. "align": "center",
  134. "wrap": true,
  135. "margin": "sm"
  136. },
  137. {
  138. "type": "text",
  139. "text": "他以自己的創業過程",
  140. "weight": "bold",
  141. "size": "sm",
  142. "align": "center",
  143. "wrap": true,
  144. "margin": "sm"
  145. },
  146. {
  147. "type": "text",
  148. "text": "輔導中小企業、新創公司得到無數大獎",
  149. "weight": "bold",
  150. "size": "sm",
  151. "align": "center",
  152. "wrap": true,
  153. "margin": "sm"
  154. },
  155. {
  156. "type": "text",
  157. "text": "並攜手開拓國際市場",
  158. "weight": "bold",
  159. "size": "sm",
  160. "align": "center",
  161. "wrap": true,
  162. "margin": "sm"
  163. },
  164. {
  165. "type": "separator",
  166. "margin": "xl"
  167. },
  168. {
  169. "type": "text",
  170. "text": "行動 EMBA 課程的精華:",
  171. "weight": "bold",
  172. "size": "sm",
  173. "align": "center",
  174. "margin": "xl",
  175. "wrap": true
  176. },
  177. {
  178. "type": "text",
  179. "text": "邀請具有產業實務經驗的成功企業家",
  180. "weight": "bold",
  181. "size": "sm",
  182. "align": "center",
  183. "margin": "sm",
  184. "wrap": true
  185. },
  186. {
  187. "type": "text",
  188. "text": "講授他們的經驗與心法",
  189. "weight": "bold",
  190. "size": "sm",
  191. "align": "center",
  192. "margin": "sm",
  193. "wrap": true
  194. }
  195. ],
  196. "offsetTop": "-5px"
  197. },
  198. "footer": {
  199. "type": "box",
  200. "layout": "vertical",
  201. "spacing": "sm",
  202. "contents": [
  203. {
  204. "type": "box",
  205. "layout": "vertical",
  206. "contents": [
  207. {
  208. "type": "button",
  209. "style": "link",
  210. "height": "sm",
  211. "action": {
  212. "type": "uri",
  213. "label": "立即上課",
  214. "uri": "https://www.misaglobal.org/program-packages/2d002dd6-c44f-4309-84d5-23890b3e02e8"
  215. },
  216. "color": "#ffffff"
  217. }
  218. ],
  219. "backgroundColor": "#f39a00",
  220. "cornerRadius": "md"
  221. },
  222. {
  223. "type": "box",
  224. "layout": "vertical",
  225. "contents": [
  226. {
  227. "type": "button",
  228. "style": "link",
  229. "height": "sm",
  230. "action": {
  231. "type": "uri",
  232. "label": "活動分享",
  233. "uri": "https://liff.googo.org/misa-emba/?openInAppBrowser=1&openExternalBrowser=1"
  234. },
  235. "color": "#f39a00"
  236. }
  237. ],
  238. "cornerRadius": "md",
  239. "margin": "lg",
  240. "borderColor": "#f39a00",
  241. "borderWidth": "normal"
  242. },
  243. {
  244. "type": "box",
  245. "layout": "vertical",
  246. "contents": [
  247. {
  248. "type": "button",
  249. "style": "link",
  250. "height": "sm",
  251. "action": {
  252. "type": "uri",
  253. "label": "給企業經營者的建議",
  254. "uri": "https://www.youtube.com/watch?v=5NBQ01Jn-S0"
  255. },
  256. "color": "#f39a00"
  257. }
  258. ],
  259. "cornerRadius": "md",
  260. "margin": "lg",
  261. "borderColor": "#f39a00",
  262. "borderWidth": "normal"
  263. },
  264. {
  265. "type": "box",
  266. "layout": "vertical",
  267. "contents": [
  268. {
  269. "type": "image",
  270. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  271. }
  272. ],
  273. "margin": "none",
  274. "position": "absolute",
  275. "offsetStart": "108px",
  276. "offsetTop": "135px"
  277. }
  278. ],
  279. "flex": 0,
  280. "height": "200px",
  281. "offsetTop": "-10px"
  282. }
  283. };
  284. var flex = {
  285. "type": "flex",
  286. "altText": _title,
  287. "contents": myFlexContent,
  288. };
  289. return flex;
  290. }
  291. var redisdata = '';
  292. function shareTargetPicker() {
  293. liff.shareTargetPicker([
  294. createFlexMessageData()
  295. ])
  296. .then(function (res) {
  297. if (res) {
  298. // succeeded in sending a message through TargetPicker
  299. console.log(`[${res.status}] Message sent!`)
  300. } else {
  301. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  302. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  303. // LINE 10.3.0 - 10.10.0
  304. // Old LINE will access here regardless of user's action
  305. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  306. } else {
  307. // LINE 10.11.0 -
  308. // sending message canceled
  309. console.log('TargetPicker was closed!')
  310. }
  311. }
  312. }).catch(function (error) {
  313. // something went wrong before sending a message
  314. console.log('something wrong happen', error)
  315. })
  316. // const url = 'https://liff.googo.org:9898/misa-liff'
  317. // axios
  318. // .get(url)
  319. // .then(({data}) => {
  320. // redisdata=data.data;
  321. // redistitle=data.title;
  322. // console.log(redistitle);
  323. // console.log(redisdata);
  324. // liff.shareTargetPicker([
  325. // {
  326. // type: "text",
  327. // text: "Test!"
  328. // }
  329. // ])
  330. // .then(
  331. // console.log("ShareTargetPicker was launched")
  332. // ).catch(function (res) {
  333. // alert(res);
  334. // console.log("Failed to launch ShareTargetPicker", res)
  335. // })
  336. // // liff
  337. // // .shareTargetPicker([
  338. // // createFlexMessageData()
  339. // // ])
  340. // // .then(() => {
  341. // // alert("Shared to the friend(s) you picked");
  342. // // })
  343. // // .catch(function(res) {
  344. // // alert(res);
  345. // // });
  346. // });
  347. }