liff-functions.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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://sirateek.me",
  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 redisdata = '';
  67. function shareTargetPicker() {
  68. alert('Test');
  69. liff.shareTargetPicker([
  70. {
  71. 'type': 'flex',
  72. "altText": 'Test',
  73. "contents": [{
  74. "type": "bubble",
  75. "hero": {
  76. "type": "box",
  77. "layout": "vertical",
  78. "contents": [
  79. {
  80. "type": "box",
  81. "layout": "vertical",
  82. "contents": [
  83. {
  84. "type": "text",
  85. "text": "MISA 沙龍小聚",
  86. "color": "#ffffff",
  87. "align": "center",
  88. "offsetTop": "3px",
  89. "size": "lg",
  90. "weight": "bold"
  91. }
  92. ],
  93. "backgroundColor": "#f39a00",
  94. "paddingAll": "15px"
  95. },
  96. {
  97. "type": "box",
  98. "layout": "vertical",
  99. "contents": [
  100. {
  101. "type": "image",
  102. "size": "full",
  103. "margin": "none",
  104. "url": "https://upload.cc/i1/2022/12/02/TrCvmp.jpg"
  105. }
  106. ],
  107. "paddingStart": "5px",
  108. "paddingEnd": "5px",
  109. "height": "220px",
  110. "paddingTop": "10px"
  111. }
  112. ]
  113. },
  114. "body": {
  115. "type": "box",
  116. "layout": "vertical",
  117. "contents": [
  118. {
  119. "type": "text",
  120. "text": "2022 年即將過去,",
  121. "weight": "bold",
  122. "size": "sm",
  123. "align": "center"
  124. },
  125. {
  126. "type": "text",
  127. "text": "MISA 將在 12 月份舉辦兩場沙龍小聚",
  128. "weight": "bold",
  129. "size": "sm",
  130. "align": "center",
  131. "wrap": true,
  132. "margin": "sm"
  133. },
  134. {
  135. "type": "text",
  136. "text": "歡迎各位 MISA 校友前來共襄盛舉!",
  137. "weight": "bold",
  138. "size": "sm",
  139. "align": "center",
  140. "margin": "sm"
  141. },
  142. {
  143. "type": "separator",
  144. "margin": "md"
  145. },
  146. {
  147. "type": "text",
  148. "text": "本次 12/21 的沙龍小聚由",
  149. "weight": "bold",
  150. "size": "sm",
  151. "align": "center",
  152. "margin": "md"
  153. },
  154. {
  155. "type": "text",
  156. "text": "「數位行銷賈伯斯」 之稱的王偉羽校友",
  157. "weight": "bold",
  158. "size": "sm",
  159. "align": "center",
  160. "margin": "sm"
  161. },
  162. {
  163. "type": "text",
  164. "text": "以及邀請商周 CEO 學院",
  165. "weight": "bold",
  166. "size": "sm",
  167. "align": "center",
  168. "margin": "sm"
  169. },
  170. {
  171. "type": "text",
  172. "text": "「最高滿意度講師」 吳兆田博士",
  173. "weight": "bold",
  174. "size": "sm",
  175. "align": "center",
  176. "margin": "sm"
  177. },
  178. {
  179. "type": "text",
  180. "text": "透過互動體驗帶領企業主利用策略、工具",
  181. "weight": "bold",
  182. "size": "sm",
  183. "align": "center",
  184. "wrap": true,
  185. "margin": "sm"
  186. },
  187. {
  188. "type": "text",
  189. "text": "應對現代「人才荒」的挑戰",
  190. "weight": "bold",
  191. "size": "sm",
  192. "align": "center",
  193. "margin": "sm"
  194. }
  195. ]
  196. },
  197. "footer": {
  198. "type": "box",
  199. "layout": "vertical",
  200. "spacing": "sm",
  201. "contents": [
  202. {
  203. "type": "box",
  204. "layout": "vertical",
  205. "contents": [
  206. {
  207. "type": "button",
  208. "style": "link",
  209. "height": "sm",
  210. "action": {
  211. "type": "uri",
  212. "label": "馬上報名",
  213. "uri": "https://pse.is/4k9ysk"
  214. },
  215. "color": "#ffffff"
  216. }
  217. ],
  218. "backgroundColor": "#f39a00",
  219. "cornerRadius": "md"
  220. },
  221. {
  222. "type": "box",
  223. "layout": "vertical",
  224. "contents": [
  225. {
  226. "type": "button",
  227. "style": "link",
  228. "height": "sm",
  229. "action": {
  230. "type": "uri",
  231. "label": "官方網站",
  232. "uri": "https://www.misaglobal.org/"
  233. },
  234. "color": "#f39a00"
  235. }
  236. ],
  237. "cornerRadius": "md",
  238. "margin": "lg",
  239. "borderColor": "#f39a00",
  240. "borderWidth": "normal"
  241. },
  242. {
  243. "type": "box",
  244. "layout": "vertical",
  245. "contents": [
  246. {
  247. "type": "image",
  248. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  249. }
  250. ],
  251. "margin": "none",
  252. "position": "absolute",
  253. "offsetStart": "108px",
  254. "offsetTop": "77px"
  255. }
  256. ],
  257. "flex": 0,
  258. "height": "150px"
  259. }
  260. }],
  261. }
  262. ])
  263. .then(function (res) {
  264. if (res) {
  265. // succeeded in sending a message through TargetPicker
  266. console.log(`[${res.status}] Message sent!`)
  267. } else {
  268. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  269. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  270. // LINE 10.3.0 - 10.10.0
  271. // Old LINE will access here regardless of user's action
  272. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  273. } else {
  274. // LINE 10.11.0 -
  275. // sending message canceled
  276. console.log('TargetPicker was closed!')
  277. }
  278. }
  279. }).catch(function (error) {
  280. // something went wrong before sending a message
  281. console.log('something wrong happen', error)
  282. })
  283. // const url = 'https://liff.googo.org:9898/yuri'
  284. // axios
  285. // .get(url)
  286. // .then(({data}) => {
  287. // redisdata=data.data;
  288. // redistitle=data.title;
  289. // console.log(redistitle);
  290. // console.log(redisdata);
  291. // liff.shareTargetPicker([
  292. // {
  293. // type: "text",
  294. // text: "Test!"
  295. // }
  296. // ])
  297. // .then(
  298. // console.log("ShareTargetPicker was launched")
  299. // ).catch(function (res) {
  300. // alert(res);
  301. // console.log("Failed to launch ShareTargetPicker", res)
  302. // })
  303. // // liff
  304. // // .shareTargetPicker([
  305. // // createFlexMessageData()
  306. // // ])
  307. // // .then(() => {
  308. // // alert("Shared to the friend(s) you picked");
  309. // // })
  310. // // .catch(function(res) {
  311. // // alert(res);
  312. // // });
  313. // });
  314. }