liff-functions.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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/5Dqezpb.jpg",
  108. "offsetTop": "-0px"
  109. }
  110. ],
  111. "paddingStart": "5px",
  112. "paddingEnd": "5px",
  113. "height": "210px"
  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": "lg"
  142. },
  143. {
  144. "type": "text",
  145. "text": "重視員工、儲備人才",
  146. "weight": "bold",
  147. "size": "md",
  148. "align": "center",
  149. "wrap": true,
  150. "margin": "lg"
  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": "sm"
  178. },
  179. {
  180. "type": "text",
  181. "text": "幫助員工解決工作上遇到的難題",
  182. "weight": "bold",
  183. "size": "md",
  184. "align": "center",
  185. "wrap": true,
  186. "margin": "sm"
  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. "offsetTop": "-10px"
  199. },
  200. "footer": {
  201. "type": "box",
  202. "layout": "vertical",
  203. "spacing": "sm",
  204. "contents": [
  205. {
  206. "type": "box",
  207. "layout": "vertical",
  208. "contents": [
  209. {
  210. "type": "button",
  211. "style": "link",
  212. "height": "sm",
  213. "action": {
  214. "type": "uri",
  215. "label": "立即上課",
  216. "uri": "https://www.misaglobal.org/program-packages/52fe849d-84c2-4b99-97f7-c24878a4d3af"
  217. },
  218. "color": "#ffffff"
  219. }
  220. ],
  221. "backgroundColor": "#f39a00",
  222. "cornerRadius": "md"
  223. },
  224. {
  225. "type": "box",
  226. "layout": "vertical",
  227. "contents": [
  228. {
  229. "type": "button",
  230. "style": "link",
  231. "height": "sm",
  232. "action": {
  233. "type": "uri",
  234. "label": "活動分享",
  235. "uri": "https://liff.googo.org/misa-program-3/?openInAppBrowser=1&openExternalBrowser=1"
  236. },
  237. "color": "#f39a00"
  238. }
  239. ],
  240. "cornerRadius": "md",
  241. "margin": "lg",
  242. "borderColor": "#f39a00",
  243. "borderWidth": "normal"
  244. },
  245. {
  246. "type": "box",
  247. "layout": "vertical",
  248. "contents": [
  249. {
  250. "type": "button",
  251. "style": "link",
  252. "height": "sm",
  253. "action": {
  254. "type": "uri",
  255. "label": "10 分鐘精華",
  256. "uri": "https://www.youtube.com/watch?v=O27PYwI1ri0&t=15s"
  257. },
  258. "color": "#f39a00"
  259. }
  260. ],
  261. "cornerRadius": "md",
  262. "margin": "lg",
  263. "borderColor": "#f39a00",
  264. "borderWidth": "normal"
  265. },
  266. {
  267. "type": "box",
  268. "layout": "vertical",
  269. "contents": [
  270. {
  271. "type": "image",
  272. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  273. }
  274. ],
  275. "margin": "none",
  276. "position": "absolute",
  277. "offsetStart": "108px",
  278. "offsetTop": "135px"
  279. }
  280. ],
  281. "flex": 0,
  282. "height": "195px",
  283. "offsetTop": "-10px"
  284. }
  285. };
  286. var flex = {
  287. "type": "flex",
  288. "altText": _title,
  289. "contents": myFlexContent,
  290. };
  291. return flex;
  292. }
  293. var redisdata = '';
  294. function shareTargetPicker() {
  295. liff.shareTargetPicker([
  296. createFlexMessageData()
  297. ])
  298. .then(function (res) {
  299. if (res) {
  300. // succeeded in sending a message through TargetPicker
  301. console.log(`[${res.status}] Message sent!`)
  302. } else {
  303. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  304. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  305. // LINE 10.3.0 - 10.10.0
  306. // Old LINE will access here regardless of user's action
  307. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  308. } else {
  309. // LINE 10.11.0 -
  310. // sending message canceled
  311. console.log('TargetPicker was closed!')
  312. }
  313. }
  314. }).catch(function (error) {
  315. // something went wrong before sending a message
  316. console.log('something wrong happen', error)
  317. })
  318. // const url = 'https://liff.googo.org:9898/misa-liff'
  319. // axios
  320. // .get(url)
  321. // .then(({data}) => {
  322. // redisdata=data.data;
  323. // redistitle=data.title;
  324. // console.log(redistitle);
  325. // console.log(redisdata);
  326. // liff.shareTargetPicker([
  327. // {
  328. // type: "text",
  329. // text: "Test!"
  330. // }
  331. // ])
  332. // .then(
  333. // console.log("ShareTargetPicker was launched")
  334. // ).catch(function (res) {
  335. // alert(res);
  336. // console.log("Failed to launch ShareTargetPicker", res)
  337. // })
  338. // // liff
  339. // // .shareTargetPicker([
  340. // // createFlexMessageData()
  341. // // ])
  342. // // .then(() => {
  343. // // alert("Shared to the friend(s) you picked");
  344. // // })
  345. // // .catch(function(res) {
  346. // // alert(res);
  347. // // });
  348. // });
  349. }