liff-functions.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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": "ESG 國際領袖班",
  81. "color": "#f39a00",
  82. "align": "center",
  83. "offsetTop": "3px",
  84. "size": "lg",
  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://cmm.ai/img/misa-esg.jpg",
  99. "offsetTop": "-10px"
  100. }
  101. ],
  102. "paddingStart": "5px",
  103. "paddingEnd": "5px",
  104. "height": "240px"
  105. }
  106. ]
  107. },
  108. "body": {
  109. "type": "box",
  110. "layout": "vertical",
  111. "contents": [
  112. {
  113. "type": "text",
  114. "text": "【 身為企業高階領導人",
  115. "weight": "bold",
  116. "size": "md",
  117. "align": "center",
  118. "wrap": true
  119. },
  120. {
  121. "type": "text",
  122. "text": "您就是企業實踐永續發展",
  123. "weight": "bold",
  124. "size": "md",
  125. "align": "center",
  126. "wrap": true,
  127. "margin": "sm"
  128. },
  129. {
  130. "type": "text",
  131. "text": "最重要的關鍵推手 】",
  132. "weight": "bold",
  133. "size": "md",
  134. "align": "center",
  135. "wrap": true,
  136. "margin": "sm"
  137. },
  138. {
  139. "type": "text",
  140. "text": "MISA 智享會與永續國際合作",
  141. "weight": "bold",
  142. "size": "sm",
  143. "align": "center",
  144. "wrap": true,
  145. "margin": "xl"
  146. },
  147. {
  148. "type": "text",
  149. "text": "首次在台開設 ESG 國際領袖班",
  150. "weight": "bold",
  151. "size": "sm",
  152. "align": "center",
  153. "wrap": true,
  154. "margin": "sm"
  155. },
  156. {
  157. "type": "text",
  158. "text": "以精煉 36 小時實戰課程",
  159. "weight": "bold",
  160. "size": "sm",
  161. "align": "center",
  162. "wrap": true,
  163. "margin": "sm"
  164. },
  165. {
  166. "type": "text",
  167. "text": "協助您取得法國標協集團 AFNOR 頒發的國際 ESG 永續策略管理師 證照",
  168. "weight": "bold",
  169. "size": "sm",
  170. "align": "center",
  171. "margin": "sm",
  172. "wrap": true
  173. },
  174. {
  175. "type": "text",
  176. "text": "立即帶領您的企業提昇 ESG 價值!",
  177. "weight": "bold",
  178. "size": "sm",
  179. "align": "center",
  180. "margin": "sm",
  181. "wrap": true
  182. }
  183. ],
  184. "offsetTop": "-10px"
  185. },
  186. "footer": {
  187. "type": "box",
  188. "layout": "vertical",
  189. "spacing": "sm",
  190. "contents": [
  191. {
  192. "type": "box",
  193. "layout": "vertical",
  194. "contents": [
  195. {
  196. "type": "button",
  197. "style": "link",
  198. "height": "sm",
  199. "action": {
  200. "type": "uri",
  201. "label": "活動主頁",
  202. "uri": "https://www.misaglobal.org/esg"
  203. },
  204. "color": "#ffffff"
  205. }
  206. ],
  207. "backgroundColor": "#f39a00",
  208. "cornerRadius": "md"
  209. },
  210. {
  211. "type": "box",
  212. "layout": "vertical",
  213. "contents": [
  214. {
  215. "type": "button",
  216. "style": "link",
  217. "height": "sm",
  218. "action": {
  219. "type": "uri",
  220. "label": "活動分享",
  221. "uri": "https://liff.googo.org/misa-esg/?openInAppBrowser=1&openExternalBrowser=1"
  222. },
  223. "color": "#f39a00"
  224. }
  225. ],
  226. "cornerRadius": "md",
  227. "margin": "lg",
  228. "borderColor": "#f39a00",
  229. "borderWidth": "normal"
  230. },
  231. {
  232. "type": "box",
  233. "layout": "vertical",
  234. "contents": [
  235. {
  236. "type": "button",
  237. "style": "link",
  238. "height": "sm",
  239. "action": {
  240. "type": "uri",
  241. "label": "官方網站",
  242. "uri": "https://www.misaglobal.org/"
  243. },
  244. "color": "#f39a00"
  245. }
  246. ],
  247. "cornerRadius": "md",
  248. "margin": "lg",
  249. "borderColor": "#f39a00",
  250. "borderWidth": "normal"
  251. },
  252. {
  253. "type": "box",
  254. "layout": "vertical",
  255. "contents": [
  256. {
  257. "type": "image",
  258. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  259. }
  260. ],
  261. "margin": "none",
  262. "position": "absolute",
  263. "offsetStart": "108px",
  264. "offsetTop": "130px"
  265. }
  266. ],
  267. "flex": 0,
  268. "height": "200px"
  269. }
  270. };
  271. var flex = {
  272. "type": "flex",
  273. "altText": _title,
  274. "contents": myFlexContent,
  275. };
  276. return flex;
  277. }
  278. var redisdata = '';
  279. function shareTargetPicker() {
  280. liff.shareTargetPicker([
  281. createFlexMessageData()
  282. ])
  283. .then(function (res) {
  284. if (res) {
  285. // succeeded in sending a message through TargetPicker
  286. console.log(`[${res.status}] Message sent!`)
  287. } else {
  288. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  289. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  290. // LINE 10.3.0 - 10.10.0
  291. // Old LINE will access here regardless of user's action
  292. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  293. } else {
  294. // LINE 10.11.0 -
  295. // sending message canceled
  296. console.log('TargetPicker was closed!')
  297. }
  298. }
  299. }).catch(function (error) {
  300. // something went wrong before sending a message
  301. console.log('something wrong happen', error)
  302. })
  303. // const url = 'https://liff.googo.org:9898/misa-liff'
  304. // axios
  305. // .get(url)
  306. // .then(({data}) => {
  307. // redisdata=data.data;
  308. // redistitle=data.title;
  309. // console.log(redistitle);
  310. // console.log(redisdata);
  311. // liff.shareTargetPicker([
  312. // {
  313. // type: "text",
  314. // text: "Test!"
  315. // }
  316. // ])
  317. // .then(
  318. // console.log("ShareTargetPicker was launched")
  319. // ).catch(function (res) {
  320. // alert(res);
  321. // console.log("Failed to launch ShareTargetPicker", res)
  322. // })
  323. // // liff
  324. // // .shareTargetPicker([
  325. // // createFlexMessageData()
  326. // // ])
  327. // // .then(() => {
  328. // // alert("Shared to the friend(s) you picked");
  329. // // })
  330. // // .catch(function(res) {
  331. // // alert(res);
  332. // // });
  333. // });
  334. }