liff-functions.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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": "md",
  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://imgur.com/NhQsUfG.jpg"
  99. }
  100. ],
  101. "paddingStart": "5px",
  102. "paddingEnd": "5px",
  103. "height": "160px"
  104. }
  105. ]
  106. },
  107. "body": {
  108. "type": "box",
  109. "layout": "vertical",
  110. "contents": [
  111. {
  112. "type": "text",
  113. "text": "職場態度很重要",
  114. "weight": "bold",
  115. "size": "sm",
  116. "align": "center",
  117. "wrap": true
  118. },
  119. {
  120. "type": "text",
  121. "text": "影響了我們的動力及職場行為!!",
  122. "weight": "bold",
  123. "size": "sm",
  124. "align": "center",
  125. "wrap": true,
  126. "margin": "sm"
  127. },
  128. {
  129. "type": "text",
  130. "text": "集團董事長不藏私分享",
  131. "weight": "bold",
  132. "size": "sm",
  133. "align": "center",
  134. "wrap": true,
  135. "margin": "xl"
  136. },
  137. {
  138. "type": "text",
  139. "text": "自身在帶領集團主管所體悟到的關鍵心法",
  140. "weight": "bold",
  141. "size": "sm",
  142. "align": "center",
  143. "wrap": true,
  144. "margin": "sm"
  145. },
  146. {
  147. "type": "text",
  148. "text": "翻轉你的慣性思考",
  149. "weight": "bold",
  150. "size": "sm",
  151. "align": "center",
  152. "wrap": true,
  153. "margin": "sm"
  154. },
  155. {
  156. "type": "text",
  157. "text": "讓你在職場更有競爭力",
  158. "weight": "bold",
  159. "size": "sm",
  160. "align": "center",
  161. "wrap": true,
  162. "margin": "sm"
  163. },
  164. {
  165. "type": "text",
  166. "text": "成為卓越的經理人",
  167. "weight": "bold",
  168. "size": "sm",
  169. "align": "center",
  170. "wrap": true,
  171. "margin": "sm"
  172. }
  173. ],
  174. "offsetTop": "-5px"
  175. },
  176. "footer": {
  177. "type": "box",
  178. "layout": "vertical",
  179. "spacing": "sm",
  180. "contents": [
  181. {
  182. "type": "box",
  183. "layout": "vertical",
  184. "contents": [
  185. {
  186. "type": "button",
  187. "style": "link",
  188. "height": "sm",
  189. "action": {
  190. "type": "uri",
  191. "label": "立即上課",
  192. "uri": "https://www.misaglobal.org/program-packages/08904629-401b-468f-a72f-4227feb66403"
  193. },
  194. "color": "#ffffff"
  195. }
  196. ],
  197. "backgroundColor": "#f39a00",
  198. "cornerRadius": "md"
  199. },
  200. {
  201. "type": "box",
  202. "layout": "vertical",
  203. "contents": [
  204. {
  205. "type": "button",
  206. "style": "link",
  207. "height": "sm",
  208. "action": {
  209. "type": "uri",
  210. "label": "活動分享",
  211. "uri": "https://liff.googo.org/misa-course-2/?openInAppBrowser=1&openExternalBrowser=1"
  212. },
  213. "color": "#f39a00"
  214. }
  215. ],
  216. "cornerRadius": "md",
  217. "margin": "lg",
  218. "borderColor": "#f39a00",
  219. "borderWidth": "normal"
  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.youtube.com/watch?v=O27PYwI1ri0&t=15s"
  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": "135px"
  255. }
  256. ],
  257. "flex": 0,
  258. "height": "200px",
  259. "offsetTop": "-10px"
  260. }
  261. };
  262. var flex = {
  263. "type": "flex",
  264. "altText": _title,
  265. "contents": myFlexContent,
  266. };
  267. return flex;
  268. }
  269. var redisdata = '';
  270. function shareTargetPicker() {
  271. liff.shareTargetPicker([
  272. createFlexMessageData()
  273. ])
  274. .then(function (res) {
  275. if (res) {
  276. // succeeded in sending a message through TargetPicker
  277. console.log(`[${res.status}] Message sent!`)
  278. } else {
  279. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  280. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  281. // LINE 10.3.0 - 10.10.0
  282. // Old LINE will access here regardless of user's action
  283. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  284. } else {
  285. // LINE 10.11.0 -
  286. // sending message canceled
  287. console.log('TargetPicker was closed!')
  288. }
  289. }
  290. }).catch(function (error) {
  291. // something went wrong before sending a message
  292. console.log('something wrong happen', error)
  293. })
  294. // const url = 'https://liff.googo.org:9898/misa-liff'
  295. // axios
  296. // .get(url)
  297. // .then(({data}) => {
  298. // redisdata=data.data;
  299. // redistitle=data.title;
  300. // console.log(redistitle);
  301. // console.log(redisdata);
  302. // liff.shareTargetPicker([
  303. // {
  304. // type: "text",
  305. // text: "Test!"
  306. // }
  307. // ])
  308. // .then(
  309. // console.log("ShareTargetPicker was launched")
  310. // ).catch(function (res) {
  311. // alert(res);
  312. // console.log("Failed to launch ShareTargetPicker", res)
  313. // })
  314. // // liff
  315. // // .shareTargetPicker([
  316. // // createFlexMessageData()
  317. // // ])
  318. // // .then(() => {
  319. // // alert("Shared to the friend(s) you picked");
  320. // // })
  321. // // .catch(function(res) {
  322. // // alert(res);
  323. // // });
  324. // });
  325. }