liff-functions.js 8.6 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": "佳世達 陳其宏",
  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/pbLVOh1.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": "text",
  141. "text": "「互惠雙贏」的價值觀",
  142. "weight": "bold",
  143. "size": "md",
  144. "align": "center",
  145. "wrap": true,
  146. "margin": "sm"
  147. },
  148. {
  149. "type": "separator",
  150. "margin": "lg"
  151. },
  152. {
  153. "type": "text",
  154. "text": "投資布局超過 70 家",
  155. "weight": "bold",
  156. "size": "md",
  157. "align": "center",
  158. "wrap": true,
  159. "margin": "lg"
  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. "offsetTop": "-10px"
  190. },
  191. "footer": {
  192. "type": "box",
  193. "layout": "vertical",
  194. "spacing": "sm",
  195. "contents": [
  196. {
  197. "type": "box",
  198. "layout": "vertical",
  199. "contents": [
  200. {
  201. "type": "button",
  202. "style": "link",
  203. "height": "sm",
  204. "action": {
  205. "type": "uri",
  206. "label": "立即上課",
  207. "uri": "https://www.misaglobal.org/program-packages/2d002dd6-c44f-4309-84d5-23890b3e02e8"
  208. },
  209. "color": "#ffffff"
  210. }
  211. ],
  212. "backgroundColor": "#f39a00",
  213. "cornerRadius": "md"
  214. },
  215. {
  216. "type": "box",
  217. "layout": "vertical",
  218. "contents": [
  219. {
  220. "type": "button",
  221. "style": "link",
  222. "height": "sm",
  223. "action": {
  224. "type": "uri",
  225. "label": "活動分享",
  226. "uri": "https://liff.googo.org/misa-program-4/?openInAppBrowser=1&openExternalBrowser=1"
  227. },
  228. "color": "#f39a00"
  229. }
  230. ],
  231. "cornerRadius": "md",
  232. "margin": "lg",
  233. "borderColor": "#f39a00",
  234. "borderWidth": "normal"
  235. },
  236. {
  237. "type": "box",
  238. "layout": "vertical",
  239. "contents": [
  240. {
  241. "type": "button",
  242. "style": "link",
  243. "height": "sm",
  244. "action": {
  245. "type": "uri",
  246. "label": "3 分鐘精華",
  247. "uri": "https://www.youtube.com/watch?v=aIogpHhSGVg&t=47s"
  248. },
  249. "color": "#f39a00"
  250. }
  251. ],
  252. "cornerRadius": "md",
  253. "margin": "lg",
  254. "borderColor": "#f39a00",
  255. "borderWidth": "normal"
  256. },
  257. {
  258. "type": "box",
  259. "layout": "vertical",
  260. "contents": [
  261. {
  262. "type": "image",
  263. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  264. }
  265. ],
  266. "margin": "none",
  267. "position": "absolute",
  268. "offsetStart": "108px",
  269. "offsetTop": "135px"
  270. }
  271. ],
  272. "flex": 0,
  273. "height": "195px",
  274. "offsetTop": "-10px"
  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. }