liff-functions.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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 沙龍小聚",
  81. "color": "#0E363E",
  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://cmm.ai/img/MISA_0215.jpg",
  99. "offsetTop": "-10px"
  100. }
  101. ],
  102. "paddingStart": "5px",
  103. "paddingEnd": "5px",
  104. "height": "250px",
  105. "offsetTop": "-10px"
  106. }
  107. ]
  108. },
  109. "body": {
  110. "type": "box",
  111. "layout": "vertical",
  112. "contents": [
  113. {
  114. "type": "text",
  115. "text": "隨著疫情及氣候變遷對自然環境、",
  116. "weight": "bold",
  117. "size": "sm",
  118. "align": "center",
  119. "wrap": true,
  120. "margin": "none"
  121. },
  122. {
  123. "type": "text",
  124. "text": "社會及全球經濟產生嚴重影響",
  125. "weight": "bold",
  126. "size": "sm",
  127. "align": "center",
  128. "wrap": true,
  129. "margin": "sm"
  130. },
  131. {
  132. "type": "text",
  133. "text": "ESG 轉型風正在起飛",
  134. "weight": "bold",
  135. "size": "sm",
  136. "align": "center",
  137. "wrap": true,
  138. "margin": "sm"
  139. },
  140. {
  141. "type": "text",
  142. "text": "為了讓企業領導者",
  143. "weight": "bold",
  144. "size": "sm",
  145. "align": "center",
  146. "wrap": true,
  147. "margin": "sm"
  148. },
  149. {
  150. "type": "text",
  151. "text": "也能輕鬆參與 ESG 永續之路",
  152. "weight": "bold",
  153. "size": "sm",
  154. "align": "center",
  155. "wrap": true,
  156. "margin": "sm"
  157. },
  158. {
  159. "type": "separator",
  160. "margin": "xl"
  161. },
  162. {
  163. "type": "text",
  164. "text": "MISA 沙龍 2/15 日加開舉辦",
  165. "weight": "bold",
  166. "size": "md",
  167. "align": "center",
  168. "wrap": true,
  169. "margin": "xl"
  170. },
  171. {
  172. "type": "text",
  173. "text": "「ESG 浪潮來襲",
  174. "weight": "bold",
  175. "size": "md",
  176. "align": "center",
  177. "wrap": true,
  178. "margin": "sm"
  179. },
  180. {
  181. "type": "text",
  182. "text": "如何搶先佈局永續管理」",
  183. "weight": "bold",
  184. "size": "md",
  185. "align": "center",
  186. "margin": "sm",
  187. "wrap": true
  188. },
  189. {
  190. "type": "text",
  191. "text": "解析 ESG 對企業經營",
  192. "weight": "bold",
  193. "size": "sm",
  194. "align": "center",
  195. "margin": "xl",
  196. "wrap": true
  197. },
  198. {
  199. "type": "text",
  200. "text": "即將面臨的重大轉折",
  201. "weight": "bold",
  202. "size": "sm",
  203. "align": "center",
  204. "margin": "sm",
  205. "wrap": true
  206. },
  207. {
  208. "type": "text",
  209. "text": "以及如何搶先布局",
  210. "weight": "bold",
  211. "size": "sm",
  212. "align": "center",
  213. "margin": "sm",
  214. "wrap": true
  215. },
  216. {
  217. "type": "separator",
  218. "margin": "xl"
  219. },
  220. {
  221. "type": "text",
  222. "text": "日期:2023/02/15(三)",
  223. "weight": "bold",
  224. "size": "sm",
  225. "align": "center",
  226. "margin": "xl",
  227. "wrap": true
  228. },
  229. {
  230. "type": "text",
  231. "text": "時間:19:00~20:30(18:45報到)",
  232. "weight": "bold",
  233. "size": "sm",
  234. "align": "center",
  235. "margin": "sm",
  236. "wrap": true
  237. },
  238. {
  239. "type": "text",
  240. "text": "地點:MISA 智享會 (台北市內湖區洲子街12號4樓,內湖運動中心)",
  241. "weight": "bold",
  242. "size": "sm",
  243. "align": "center",
  244. "margin": "sm",
  245. "wrap": true
  246. }
  247. ],
  248. "offsetTop": "-15px"
  249. },
  250. "footer": {
  251. "type": "box",
  252. "layout": "vertical",
  253. "spacing": "sm",
  254. "contents": [
  255. {
  256. "type": "box",
  257. "layout": "vertical",
  258. "contents": [
  259. {
  260. "type": "button",
  261. "style": "link",
  262. "height": "sm",
  263. "action": {
  264. "type": "uri",
  265. "label": "報名參加",
  266. "uri": "https://s.aiii.ai/g/f8db1f"
  267. },
  268. "color": "#ffffff"
  269. }
  270. ],
  271. "backgroundColor": "#0E363E",
  272. "cornerRadius": "md"
  273. },
  274. {
  275. "type": "box",
  276. "layout": "vertical",
  277. "contents": [
  278. {
  279. "type": "button",
  280. "style": "link",
  281. "height": "sm",
  282. "action": {
  283. "type": "uri",
  284. "label": "活動分享",
  285. "uri": "https://liff.googo.org/misa-0215/?openInAppBrowser=1&openExternalBrowser=1"
  286. },
  287. "color": "#0E363E"
  288. }
  289. ],
  290. "cornerRadius": "md",
  291. "margin": "lg",
  292. "borderColor": "#0E363E",
  293. "borderWidth": "normal"
  294. },
  295. {
  296. "type": "box",
  297. "layout": "vertical",
  298. "contents": [
  299. {
  300. "type": "button",
  301. "style": "link",
  302. "height": "sm",
  303. "action": {
  304. "type": "uri",
  305. "label": "官方網站",
  306. "uri": "https://www.misaglobal.org/"
  307. },
  308. "color": "#0E363E"
  309. }
  310. ],
  311. "cornerRadius": "md",
  312. "margin": "lg",
  313. "borderColor": "#0E363E",
  314. "borderWidth": "normal"
  315. },
  316. {
  317. "type": "box",
  318. "layout": "vertical",
  319. "contents": [
  320. {
  321. "type": "image",
  322. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  323. }
  324. ],
  325. "margin": "none",
  326. "position": "absolute",
  327. "offsetStart": "108px",
  328. "offsetTop": "130px"
  329. }
  330. ],
  331. "flex": 0,
  332. "height": "200px"
  333. }
  334. };
  335. var flex = {
  336. "type": "flex",
  337. "altText": _title,
  338. "contents": myFlexContent,
  339. };
  340. return flex;
  341. }
  342. var redisdata = '';
  343. function shareTargetPicker() {
  344. liff.shareTargetPicker([
  345. createFlexMessageData()
  346. ])
  347. .then(function (res) {
  348. if (res) {
  349. // succeeded in sending a message through TargetPicker
  350. console.log(`[${res.status}] Message sent!`)
  351. } else {
  352. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  353. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  354. // LINE 10.3.0 - 10.10.0
  355. // Old LINE will access here regardless of user's action
  356. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  357. } else {
  358. // LINE 10.11.0 -
  359. // sending message canceled
  360. console.log('TargetPicker was closed!')
  361. }
  362. }
  363. }).catch(function (error) {
  364. // something went wrong before sending a message
  365. console.log('something wrong happen', error)
  366. })
  367. // const url = 'https://liff.googo.org:9898/misa-liff'
  368. // axios
  369. // .get(url)
  370. // .then(({data}) => {
  371. // redisdata=data.data;
  372. // redistitle=data.title;
  373. // console.log(redistitle);
  374. // console.log(redisdata);
  375. // liff.shareTargetPicker([
  376. // {
  377. // type: "text",
  378. // text: "Test!"
  379. // }
  380. // ])
  381. // .then(
  382. // console.log("ShareTargetPicker was launched")
  383. // ).catch(function (res) {
  384. // alert(res);
  385. // console.log("Failed to launch ShareTargetPicker", res)
  386. // })
  387. // // liff
  388. // // .shareTargetPicker([
  389. // // createFlexMessageData()
  390. // // ])
  391. // // .then(() => {
  392. // // alert("Shared to the friend(s) you picked");
  393. // // })
  394. // // .catch(function(res) {
  395. // // alert(res);
  396. // // });
  397. // });
  398. }