liff-functions.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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": "「高爾夫球」教我的決策思維!",
  81. "color": "#f39a00",
  82. "align": "center",
  83. "offsetTop": "3px",
  84. "size": "lg",
  85. "weight": "bold"
  86. },
  87. {
  88. "type": "text",
  89. "text": "危機意識,步步為營",
  90. "color": "#f39a00",
  91. "align": "center",
  92. "offsetTop": "3px",
  93. "size": "lg",
  94. "weight": "bold"
  95. }
  96. ],
  97. "paddingAll": "15px"
  98. },
  99. {
  100. "type": "box",
  101. "layout": "vertical",
  102. "contents": [
  103. {
  104. "type": "image",
  105. "size": "full",
  106. "margin": "none",
  107. "url": "https://imgur.com/q9CAJyY.jpg",
  108. "offsetTop": "-10px"
  109. }
  110. ],
  111. "paddingStart": "5px",
  112. "paddingEnd": "5px",
  113. "height": "190px"
  114. }
  115. ]
  116. },
  117. "body": {
  118. "type": "box",
  119. "layout": "vertical",
  120. "contents": [
  121. {
  122. "type": "text",
  123. "text": "曾國棟董事長從打球過程中",
  124. "weight": "bold",
  125. "size": "md",
  126. "align": "center",
  127. "wrap": true,
  128. "margin": "lg"
  129. },
  130. {
  131. "type": "text",
  132. "text": "淬鍊出一套高爾夫的企業經營心法",
  133. "weight": "bold",
  134. "size": "md",
  135. "align": "center",
  136. "wrap": true,
  137. "margin": "sm"
  138. },
  139. {
  140. "type": "separator",
  141. "margin": "xl"
  142. },
  143. {
  144. "type": "text",
  145. "text": "前面打得很順",
  146. "weight": "bold",
  147. "size": "md",
  148. "align": "center",
  149. "wrap": true,
  150. "margin": "xl"
  151. },
  152. {
  153. "type": "text",
  154. "text": "後面卻沒有步步為營",
  155. "weight": "bold",
  156. "size": "md",
  157. "align": "center",
  158. "wrap": true,
  159. "margin": "sm"
  160. },
  161. {
  162. "type": "text",
  163. "text": "反而導致慘敗",
  164. "weight": "bold",
  165. "size": "md",
  166. "align": "center",
  167. "wrap": true,
  168. "margin": "sm"
  169. },
  170. {
  171. "type": "text",
  172. "text": "企業經營如同",
  173. "weight": "bold",
  174. "size": "md",
  175. "align": "center",
  176. "wrap": true,
  177. "margin": "xl"
  178. },
  179. {
  180. "type": "text",
  181. "text": "一帆風順時更要保持警醒",
  182. "weight": "bold",
  183. "size": "md",
  184. "align": "center",
  185. "margin": "sm",
  186. "wrap": true
  187. },
  188. {
  189. "type": "text",
  190. "text": "建立避險機制",
  191. "weight": "bold",
  192. "size": "md",
  193. "align": "center",
  194. "margin": "sm",
  195. "wrap": true
  196. },
  197. {
  198. "type": "text",
  199. "text": "做好風險管控",
  200. "weight": "bold",
  201. "size": "md",
  202. "align": "center",
  203. "margin": "sm",
  204. "wrap": true
  205. }
  206. ],
  207. "offsetTop": "-20px"
  208. },
  209. "footer": {
  210. "type": "box",
  211. "layout": "vertical",
  212. "spacing": "sm",
  213. "contents": [
  214. {
  215. "type": "box",
  216. "layout": "vertical",
  217. "contents": [
  218. {
  219. "type": "button",
  220. "style": "link",
  221. "height": "sm",
  222. "action": {
  223. "type": "uri",
  224. "label": "立即上課",
  225. "uri": "https://www.misaglobal.org/program-packages/736f4c40-d411-4f1f-bc05-c4bcc417dc43"
  226. },
  227. "color": "#ffffff"
  228. }
  229. ],
  230. "backgroundColor": "#f39a00",
  231. "cornerRadius": "md"
  232. },
  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://liff.googo.org/misa-program-1/?openInAppBrowser=1&openExternalBrowser=1"
  245. },
  246. "color": "#f39a00"
  247. }
  248. ],
  249. "cornerRadius": "md",
  250. "margin": "lg",
  251. "borderColor": "#f39a00",
  252. "borderWidth": "normal"
  253. },
  254. {
  255. "type": "box",
  256. "layout": "vertical",
  257. "contents": [
  258. {
  259. "type": "button",
  260. "style": "link",
  261. "height": "sm",
  262. "action": {
  263. "type": "uri",
  264. "label": "3 分鐘精華",
  265. "uri": "https://www.youtube.com/watch?v=OJmSi2vk_nI"
  266. },
  267. "color": "#f39a00"
  268. }
  269. ],
  270. "cornerRadius": "md",
  271. "margin": "lg",
  272. "borderColor": "#f39a00",
  273. "borderWidth": "normal"
  274. },
  275. {
  276. "type": "box",
  277. "layout": "vertical",
  278. "contents": [
  279. {
  280. "type": "image",
  281. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  282. }
  283. ],
  284. "margin": "none",
  285. "position": "absolute",
  286. "offsetStart": "108px",
  287. "offsetTop": "135px"
  288. }
  289. ],
  290. "flex": 0,
  291. "height": "195px",
  292. "offsetTop": "-10px"
  293. }
  294. };
  295. var flex = {
  296. "type": "flex",
  297. "altText": _title,
  298. "contents": myFlexContent,
  299. };
  300. return flex;
  301. }
  302. var redisdata = '';
  303. function shareTargetPicker() {
  304. liff.shareTargetPicker([
  305. createFlexMessageData()
  306. ])
  307. .then(function (res) {
  308. if (res) {
  309. // succeeded in sending a message through TargetPicker
  310. console.log(`[${res.status}] Message sent!`)
  311. } else {
  312. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  313. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  314. // LINE 10.3.0 - 10.10.0
  315. // Old LINE will access here regardless of user's action
  316. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  317. } else {
  318. // LINE 10.11.0 -
  319. // sending message canceled
  320. console.log('TargetPicker was closed!')
  321. }
  322. }
  323. }).catch(function (error) {
  324. // something went wrong before sending a message
  325. console.log('something wrong happen', error)
  326. })
  327. // const url = 'https://liff.googo.org:9898/misa-liff'
  328. // axios
  329. // .get(url)
  330. // .then(({data}) => {
  331. // redisdata=data.data;
  332. // redistitle=data.title;
  333. // console.log(redistitle);
  334. // console.log(redisdata);
  335. // liff.shareTargetPicker([
  336. // {
  337. // type: "text",
  338. // text: "Test!"
  339. // }
  340. // ])
  341. // .then(
  342. // console.log("ShareTargetPicker was launched")
  343. // ).catch(function (res) {
  344. // alert(res);
  345. // console.log("Failed to launch ShareTargetPicker", res)
  346. // })
  347. // // liff
  348. // // .shareTargetPicker([
  349. // // createFlexMessageData()
  350. // // ])
  351. // // .then(() => {
  352. // // alert("Shared to the friend(s) you picked");
  353. // // })
  354. // // .catch(function(res) {
  355. // // alert(res);
  356. // // });
  357. // });
  358. }