liff-functions.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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": "#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://cmm.ai/img/MISA_0212.jpg",
  99. "offsetTop": "-10px"
  100. }
  101. ],
  102. "paddingStart": "5px",
  103. "paddingEnd": "5px",
  104. "height": "240px"
  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": "none"
  120. },
  121. {
  122. "type": "text",
  123. "text": "本次「2/12 沙龍小聚」",
  124. "weight": "bold",
  125. "size": "sm",
  126. "align": "center",
  127. "wrap": true,
  128. "margin": "lg"
  129. },
  130. {
  131. "type": "text",
  132. "text": "由王品集團 李森斌 副董事長",
  133. "weight": "bold",
  134. "size": "sm",
  135. "align": "center",
  136. "wrap": true,
  137. "margin": "sm"
  138. },
  139. {
  140. "type": "text",
  141. "text": "在王品擔任管理工作 30 年",
  142. "weight": "bold",
  143. "size": "sm",
  144. "align": "center",
  145. "wrap": true,
  146. "margin": "sm"
  147. },
  148. {
  149. "type": "text",
  150. "text": "經歷過人才出走潮、品牌經營失敗等事件",
  151. "weight": "bold",
  152. "size": "sm",
  153. "align": "center",
  154. "wrap": true,
  155. "margin": "sm"
  156. },
  157. {
  158. "type": "text",
  159. "text": "以自身經歷為大家分享",
  160. "weight": "bold",
  161. "size": "sm",
  162. "align": "center",
  163. "wrap": true,
  164. "margin": "sm"
  165. },
  166. {
  167. "type": "text",
  168. "text": "經營理念與團隊文化塑造!",
  169. "weight": "bold",
  170. "size": "sm",
  171. "align": "center",
  172. "wrap": true,
  173. "margin": "sm"
  174. },
  175. {
  176. "type": "separator",
  177. "margin": "xl"
  178. },
  179. {
  180. "type": "text",
  181. "text": "並且於當天也是 康博集團",
  182. "weight": "bold",
  183. "size": "sm",
  184. "align": "center",
  185. "margin": "xl",
  186. "wrap": true
  187. },
  188. {
  189. "type": "text",
  190. "text": "「榮耀20,再創新局」",
  191. "weight": "bold",
  192. "size": "sm",
  193. "align": "center",
  194. "margin": "sm",
  195. "wrap": true
  196. },
  197. {
  198. "type": "text",
  199. "text": "周年春酒晚宴",
  200. "weight": "bold",
  201. "size": "sm",
  202. "align": "center",
  203. "margin": "sm",
  204. "wrap": true
  205. },
  206. {
  207. "type": "text",
  208. "text": "敬邀 MISA 校友們一起同樂並獻上祝福!",
  209. "weight": "bold",
  210. "size": "sm",
  211. "align": "center",
  212. "margin": "sm",
  213. "wrap": true
  214. }
  215. ],
  216. "offsetTop": "-15px"
  217. },
  218. "footer": {
  219. "type": "box",
  220. "layout": "vertical",
  221. "spacing": "sm",
  222. "contents": [
  223. {
  224. "type": "box",
  225. "layout": "vertical",
  226. "contents": [
  227. {
  228. "type": "button",
  229. "style": "link",
  230. "height": "sm",
  231. "action": {
  232. "type": "uri",
  233. "label": "報名參加",
  234. "uri": "https://s.aiii.ai/g/f48722"
  235. },
  236. "color": "#ffffff"
  237. }
  238. ],
  239. "backgroundColor": "#f39a00",
  240. "cornerRadius": "md"
  241. },
  242. {
  243. "type": "box",
  244. "layout": "vertical",
  245. "contents": [
  246. {
  247. "type": "button",
  248. "style": "link",
  249. "height": "sm",
  250. "action": {
  251. "type": "uri",
  252. "label": "活動分享",
  253. "uri": "https://liff.googo.org/misa-0212/?openInAppBrowser=1&openExternalBrowser=1"
  254. },
  255. "color": "#f39a00"
  256. }
  257. ],
  258. "cornerRadius": "md",
  259. "margin": "lg",
  260. "borderColor": "#f39a00",
  261. "borderWidth": "normal"
  262. },
  263. {
  264. "type": "box",
  265. "layout": "vertical",
  266. "contents": [
  267. {
  268. "type": "button",
  269. "style": "link",
  270. "height": "sm",
  271. "action": {
  272. "type": "uri",
  273. "label": "官方網站",
  274. "uri": "https://www.misaglobal.org/"
  275. },
  276. "color": "#f39a00"
  277. }
  278. ],
  279. "cornerRadius": "md",
  280. "margin": "lg",
  281. "borderColor": "#f39a00",
  282. "borderWidth": "normal"
  283. },
  284. {
  285. "type": "box",
  286. "layout": "vertical",
  287. "contents": [
  288. {
  289. "type": "image",
  290. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  291. }
  292. ],
  293. "margin": "none",
  294. "position": "absolute",
  295. "offsetStart": "108px",
  296. "offsetTop": "130px"
  297. }
  298. ],
  299. "flex": 0,
  300. "height": "200px"
  301. }
  302. };
  303. var flex = {
  304. "type": "flex",
  305. "altText": _title,
  306. "contents": myFlexContent,
  307. };
  308. return flex;
  309. }
  310. var redisdata = '';
  311. function shareTargetPicker() {
  312. liff.shareTargetPicker([
  313. createFlexMessageData()
  314. ])
  315. .then(function (res) {
  316. if (res) {
  317. // succeeded in sending a message through TargetPicker
  318. console.log(`[${res.status}] Message sent!`)
  319. } else {
  320. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  321. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  322. // LINE 10.3.0 - 10.10.0
  323. // Old LINE will access here regardless of user's action
  324. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  325. } else {
  326. // LINE 10.11.0 -
  327. // sending message canceled
  328. console.log('TargetPicker was closed!')
  329. }
  330. }
  331. }).catch(function (error) {
  332. // something went wrong before sending a message
  333. console.log('something wrong happen', error)
  334. })
  335. // const url = 'https://liff.googo.org:9898/misa-liff'
  336. // axios
  337. // .get(url)
  338. // .then(({data}) => {
  339. // redisdata=data.data;
  340. // redistitle=data.title;
  341. // console.log(redistitle);
  342. // console.log(redisdata);
  343. // liff.shareTargetPicker([
  344. // {
  345. // type: "text",
  346. // text: "Test!"
  347. // }
  348. // ])
  349. // .then(
  350. // console.log("ShareTargetPicker was launched")
  351. // ).catch(function (res) {
  352. // alert(res);
  353. // console.log("Failed to launch ShareTargetPicker", res)
  354. // })
  355. // // liff
  356. // // .shareTargetPicker([
  357. // // createFlexMessageData()
  358. // // ])
  359. // // .then(() => {
  360. // // alert("Shared to the friend(s) you picked");
  361. // // })
  362. // // .catch(function(res) {
  363. // // alert(res);
  364. // // });
  365. // });
  366. }