liff-functions.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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": "#ffffff",
  82. "align": "center",
  83. "offsetTop": "3px",
  84. "size": "lg",
  85. "weight": "bold"
  86. }
  87. ],
  88. "backgroundColor": "#dd462b",
  89. "paddingAll": "15px"
  90. },
  91. {
  92. "type": "box",
  93. "layout": "vertical",
  94. "contents": [
  95. {
  96. "type": "image",
  97. "size": "full",
  98. "margin": "none",
  99. "url": "https://upload.cc/i1/2023/01/07/U4iHYt.jpg"
  100. }
  101. ],
  102. "paddingStart": "5px",
  103. "paddingEnd": "5px",
  104. "height": "220px",
  105. "paddingTop": "10px"
  106. }
  107. ]
  108. },
  109. "body": {
  110. "type": "box",
  111. "layout": "vertical",
  112. "contents": [
  113. {
  114. "type": "text",
  115. "text": "【2023 新的一年如何翻轉慣性思考邏輯",
  116. "weight": "bold",
  117. "size": "sm",
  118. "align": "center",
  119. "wrap": true
  120. },
  121. {
  122. "type": "text",
  123. "text": "創造新思維模式】",
  124. "weight": "bold",
  125. "size": "sm",
  126. "align": "center",
  127. "wrap": true
  128. },
  129. {
  130. "type": "text",
  131. "text": "「經營管理」的面向非常廣泛",
  132. "weight": "bold",
  133. "size": "sm",
  134. "align": "center",
  135. "wrap": true,
  136. "margin": "xxl"
  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. "margin": "sm",
  163. "wrap": true
  164. },
  165. {
  166. "type": "text",
  167. "text": "幫助您減少摸索的時間",
  168. "weight": "bold",
  169. "size": "sm",
  170. "align": "center",
  171. "margin": "sm",
  172. "wrap": true
  173. },
  174. {
  175. "type": "text",
  176. "text": "新年度跨越思維",
  177. "weight": "bold",
  178. "size": "sm",
  179. "align": "center",
  180. "margin": "xxl"
  181. },
  182. {
  183. "type": "text",
  184. "text": "讓您瞭解成功領導者在想什麼!",
  185. "weight": "bold",
  186. "size": "sm",
  187. "align": "center",
  188. "margin": "sm"
  189. }
  190. ]
  191. },
  192. "footer": {
  193. "type": "box",
  194. "layout": "vertical",
  195. "spacing": "sm",
  196. "contents": [
  197. {
  198. "type": "box",
  199. "layout": "vertical",
  200. "contents": [
  201. {
  202. "type": "button",
  203. "style": "link",
  204. "height": "sm",
  205. "action": {
  206. "type": "uri",
  207. "label": "活動主頁",
  208. "uri": "https://www.misaglobal.org/event"
  209. },
  210. "color": "#ffffff"
  211. }
  212. ],
  213. "backgroundColor": "#dd462b",
  214. "cornerRadius": "md"
  215. },
  216. {
  217. "type": "box",
  218. "layout": "vertical",
  219. "contents": [
  220. {
  221. "type": "button",
  222. "style": "link",
  223. "height": "sm",
  224. "action": {
  225. "type": "uri",
  226. "label": "活動分享",
  227. "uri": "https://liff.googo.org/misa-liff/"
  228. },
  229. "color": "#dd462b"
  230. }
  231. ],
  232. "cornerRadius": "md",
  233. "margin": "lg",
  234. "borderColor": "#dd462b",
  235. "borderWidth": "normal"
  236. },
  237. {
  238. "type": "box",
  239. "layout": "vertical",
  240. "contents": [
  241. {
  242. "type": "button",
  243. "style": "link",
  244. "height": "sm",
  245. "action": {
  246. "type": "uri",
  247. "label": "官方網站",
  248. "uri": "https://www.misaglobal.org/"
  249. },
  250. "color": "#dd462b"
  251. }
  252. ],
  253. "cornerRadius": "md",
  254. "margin": "lg",
  255. "borderColor": "#dd462b",
  256. "borderWidth": "normal"
  257. },
  258. {
  259. "type": "box",
  260. "layout": "vertical",
  261. "contents": [
  262. {
  263. "type": "image",
  264. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  265. }
  266. ],
  267. "margin": "none",
  268. "position": "absolute",
  269. "offsetStart": "108px",
  270. "offsetTop": "130px"
  271. }
  272. ],
  273. "flex": 0,
  274. "height": "200px"
  275. }
  276. };
  277. var flex = {
  278. "type": "flex",
  279. "altText": _title,
  280. "contents": myFlexContent,
  281. };
  282. return flex;
  283. }
  284. var redisdata = '';
  285. function shareTargetPicker() {
  286. liff.shareTargetPicker([
  287. createFlexMessageData()
  288. ])
  289. .then(function (res) {
  290. if (res) {
  291. // succeeded in sending a message through TargetPicker
  292. console.log(`[${res.status}] Message sent!`)
  293. } else {
  294. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  295. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  296. // LINE 10.3.0 - 10.10.0
  297. // Old LINE will access here regardless of user's action
  298. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  299. } else {
  300. // LINE 10.11.0 -
  301. // sending message canceled
  302. console.log('TargetPicker was closed!')
  303. }
  304. }
  305. }).catch(function (error) {
  306. // something went wrong before sending a message
  307. console.log('something wrong happen', error)
  308. })
  309. // const url = 'https://liff.googo.org:9898/misa-liff'
  310. // axios
  311. // .get(url)
  312. // .then(({data}) => {
  313. // redisdata=data.data;
  314. // redistitle=data.title;
  315. // console.log(redistitle);
  316. // console.log(redisdata);
  317. // liff.shareTargetPicker([
  318. // {
  319. // type: "text",
  320. // text: "Test!"
  321. // }
  322. // ])
  323. // .then(
  324. // console.log("ShareTargetPicker was launched")
  325. // ).catch(function (res) {
  326. // alert(res);
  327. // console.log("Failed to launch ShareTargetPicker", res)
  328. // })
  329. // // liff
  330. // // .shareTargetPicker([
  331. // // createFlexMessageData()
  332. // // ])
  333. // // .then(() => {
  334. // // alert("Shared to the friend(s) you picked");
  335. // // })
  336. // // .catch(function(res) {
  337. // // alert(res);
  338. // // });
  339. // });
  340. }