liff-functions.js 9.2 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": "多做一小步,創造難以取代的價值",
  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://i.imgur.com/zrXwElj.jpg",
  99. "offsetTop": "-15px"
  100. }
  101. ],
  102. "paddingStart": "5px",
  103. "paddingEnd": "5px",
  104. "height": "200px"
  105. }
  106. ]
  107. },
  108. "body": {
  109. "type": "box",
  110. "layout": "vertical",
  111. "contents": [
  112. {
  113. "type": "text",
  114. "text": "「多一小步服務」的思維",
  115. "weight": "bold",
  116. "size": "sm",
  117. "align": "center",
  118. "wrap": true
  119. },
  120. {
  121. "type": "text",
  122. "text": "可以從 3 個層面進行發想",
  123. "weight": "bold",
  124. "size": "sm",
  125. "align": "center",
  126. "wrap": true,
  127. "margin": "sm"
  128. },
  129. {
  130. "type": "text",
  131. "text": "「範圍」、「服務對象」、「角色」",
  132. "weight": "bold",
  133. "size": "sm",
  134. "align": "center",
  135. "wrap": true,
  136. "margin": "sm"
  137. },
  138. {
  139. "type": "text",
  140. "text": "來探討適合運用在",
  141. "weight": "bold",
  142. "size": "sm",
  143. "align": "center",
  144. "wrap": true,
  145. "margin": "sm"
  146. },
  147. {
  148. "type": "text",
  149. "text": "企業、職場、家庭、關係",
  150. "weight": "bold",
  151. "size": "sm",
  152. "align": "center",
  153. "wrap": true,
  154. "margin": "sm"
  155. },
  156. {
  157. "type": "text",
  158. "text": "任何人都可隨手從",
  159. "weight": "bold",
  160. "size": "sm",
  161. "align": "center",
  162. "wrap": true,
  163. "margin": "sm"
  164. },
  165. {
  166. "type": "text",
  167. "text": "「不方便」、「不滿意」中",
  168. "weight": "bold",
  169. "size": "sm",
  170. "align": "center",
  171. "wrap": true,
  172. "margin": "sm"
  173. },
  174. {
  175. "type": "text",
  176. "text": "找到機會與創新",
  177. "weight": "bold",
  178. "size": "sm",
  179. "align": "center",
  180. "wrap": true,
  181. "margin": "sm"
  182. },
  183. {
  184. "type": "separator",
  185. "margin": "xl"
  186. },
  187. {
  188. "type": "text",
  189. "text": "課程分享 12 種「多一小步」的作法",
  190. "weight": "bold",
  191. "size": "sm",
  192. "align": "center",
  193. "margin": "xl",
  194. "wrap": true
  195. },
  196. {
  197. "type": "text",
  198. "text": "讓企業從 A 提昇到 A+",
  199. "weight": "bold",
  200. "size": "sm",
  201. "align": "center",
  202. "margin": "sm",
  203. "wrap": true
  204. },
  205. {
  206. "type": "text",
  207. "text": "讓你從工作中找到快樂",
  208. "weight": "bold",
  209. "size": "sm",
  210. "align": "center",
  211. "margin": "sm",
  212. "wrap": true
  213. }
  214. ],
  215. "offsetTop": "-20px"
  216. },
  217. "footer": {
  218. "type": "box",
  219. "layout": "vertical",
  220. "spacing": "sm",
  221. "contents": [
  222. {
  223. "type": "box",
  224. "layout": "vertical",
  225. "contents": [
  226. {
  227. "type": "button",
  228. "style": "link",
  229. "height": "sm",
  230. "action": {
  231. "type": "uri",
  232. "label": "報名參加",
  233. "uri": "https://www.misaglobal.org/program-packages/af22d5d7-b856-4486-ac15-c9a9deb3b292"
  234. },
  235. "color": "#ffffff"
  236. }
  237. ],
  238. "backgroundColor": "#f39a00",
  239. "cornerRadius": "md"
  240. },
  241. {
  242. "type": "box",
  243. "layout": "vertical",
  244. "contents": [
  245. {
  246. "type": "button",
  247. "style": "link",
  248. "height": "sm",
  249. "action": {
  250. "type": "uri",
  251. "label": "活動分享",
  252. "uri": "https://liff.googo.org/misa-aPlus/?openInAppBrowser=1&openExternalBrowser=1"
  253. },
  254. "color": "#f39a00"
  255. }
  256. ],
  257. "cornerRadius": "md",
  258. "margin": "lg",
  259. "borderColor": "#f39a00",
  260. "borderWidth": "normal"
  261. },
  262. {
  263. "type": "box",
  264. "layout": "vertical",
  265. "contents": [
  266. {
  267. "type": "button",
  268. "style": "link",
  269. "height": "sm",
  270. "action": {
  271. "type": "uri",
  272. "label": "課程片段搶先看",
  273. "uri": "https://youtu.be/kay-uYWkAzQ"
  274. },
  275. "color": "#f39a00"
  276. }
  277. ],
  278. "cornerRadius": "md",
  279. "margin": "lg",
  280. "borderColor": "#f39a00",
  281. "borderWidth": "normal"
  282. },
  283. {
  284. "type": "box",
  285. "layout": "vertical",
  286. "contents": [
  287. {
  288. "type": "image",
  289. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  290. }
  291. ],
  292. "margin": "none",
  293. "position": "absolute",
  294. "offsetStart": "108px",
  295. "offsetTop": "135px"
  296. }
  297. ],
  298. "flex": 0,
  299. "height": "200px",
  300. "offsetTop": "-10px"
  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. }