liff-functions.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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": "邀請永續國際顧問(股)公司 任家治執行長",
  192. "weight": "bold",
  193. "size": "sm",
  194. "align": "center",
  195. "margin": "xl",
  196. "wrap": true
  197. },
  198. {
  199. "type": "text",
  200. "text": "解析 ESG 對企業經營",
  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": "text",
  218. "text": "以及如何搶先布局",
  219. "weight": "bold",
  220. "size": "sm",
  221. "align": "center",
  222. "margin": "sm",
  223. "wrap": true
  224. }
  225. ],
  226. "offsetTop": "-15px"
  227. },
  228. "footer": {
  229. "type": "box",
  230. "layout": "vertical",
  231. "spacing": "sm",
  232. "contents": [
  233. {
  234. "type": "box",
  235. "layout": "vertical",
  236. "contents": [
  237. {
  238. "type": "button",
  239. "style": "link",
  240. "height": "sm",
  241. "action": {
  242. "type": "uri",
  243. "label": "報名參加",
  244. "uri": "https://s.aiii.ai/g/f48722"
  245. },
  246. "color": "#ffffff"
  247. }
  248. ],
  249. "backgroundColor": "#0E363E",
  250. "cornerRadius": "md"
  251. },
  252. {
  253. "type": "box",
  254. "layout": "vertical",
  255. "contents": [
  256. {
  257. "type": "button",
  258. "style": "link",
  259. "height": "sm",
  260. "action": {
  261. "type": "uri",
  262. "label": "活動分享",
  263. "uri": "https://liff.googo.org/misa-0212/?openInAppBrowser=1&openExternalBrowser=1"
  264. },
  265. "color": "#0E363E"
  266. }
  267. ],
  268. "cornerRadius": "md",
  269. "margin": "lg",
  270. "borderColor": "#0E363E",
  271. "borderWidth": "normal"
  272. },
  273. {
  274. "type": "box",
  275. "layout": "vertical",
  276. "contents": [
  277. {
  278. "type": "button",
  279. "style": "link",
  280. "height": "sm",
  281. "action": {
  282. "type": "uri",
  283. "label": "官方網站",
  284. "uri": "https://www.misaglobal.org/"
  285. },
  286. "color": "#0E363E"
  287. }
  288. ],
  289. "cornerRadius": "md",
  290. "margin": "lg",
  291. "borderColor": "#0E363E",
  292. "borderWidth": "normal"
  293. },
  294. {
  295. "type": "box",
  296. "layout": "vertical",
  297. "contents": [
  298. {
  299. "type": "image",
  300. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  301. }
  302. ],
  303. "margin": "none",
  304. "position": "absolute",
  305. "offsetStart": "108px",
  306. "offsetTop": "130px"
  307. }
  308. ],
  309. "flex": 0,
  310. "height": "200px"
  311. }
  312. };
  313. var flex = {
  314. "type": "flex",
  315. "altText": _title,
  316. "contents": myFlexContent,
  317. };
  318. return flex;
  319. }
  320. var redisdata = '';
  321. function shareTargetPicker() {
  322. liff.shareTargetPicker([
  323. createFlexMessageData()
  324. ])
  325. .then(function (res) {
  326. if (res) {
  327. // succeeded in sending a message through TargetPicker
  328. console.log(`[${res.status}] Message sent!`)
  329. } else {
  330. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  331. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  332. // LINE 10.3.0 - 10.10.0
  333. // Old LINE will access here regardless of user's action
  334. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  335. } else {
  336. // LINE 10.11.0 -
  337. // sending message canceled
  338. console.log('TargetPicker was closed!')
  339. }
  340. }
  341. }).catch(function (error) {
  342. // something went wrong before sending a message
  343. console.log('something wrong happen', error)
  344. })
  345. // const url = 'https://liff.googo.org:9898/misa-liff'
  346. // axios
  347. // .get(url)
  348. // .then(({data}) => {
  349. // redisdata=data.data;
  350. // redistitle=data.title;
  351. // console.log(redistitle);
  352. // console.log(redisdata);
  353. // liff.shareTargetPicker([
  354. // {
  355. // type: "text",
  356. // text: "Test!"
  357. // }
  358. // ])
  359. // .then(
  360. // console.log("ShareTargetPicker was launched")
  361. // ).catch(function (res) {
  362. // alert(res);
  363. // console.log("Failed to launch ShareTargetPicker", res)
  364. // })
  365. // // liff
  366. // // .shareTargetPicker([
  367. // // createFlexMessageData()
  368. // // ])
  369. // // .then(() => {
  370. // // alert("Shared to the friend(s) you picked");
  371. // // })
  372. // // .catch(function(res) {
  373. // // alert(res);
  374. // // });
  375. // });
  376. }