liff-functions.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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": "#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://imgur.com/jxUmUig.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": "sm",
  117. "align": "center",
  118. "wrap": true,
  119. "margin": "lg"
  120. },
  121. {
  122. "type": "text",
  123. "text": "卻不知從何開始?」",
  124. "weight": "bold",
  125. "size": "sm",
  126. "align": "center",
  127. "wrap": true,
  128. "margin": "sm"
  129. },
  130. {
  131. "type": "text",
  132. "text": "「鎖定研發項目與構思後, ",
  133. "weight": "bold",
  134. "size": "sm",
  135. "align": "center",
  136. "wrap": true,
  137. "margin": "sm"
  138. },
  139. {
  140. "type": "text",
  141. "text": "卻不知政府有提供資金與資源?」",
  142. "weight": "bold",
  143. "size": "sm",
  144. "align": "center",
  145. "wrap": true,
  146. "margin": "sm"
  147. },
  148. {
  149. "type": "text",
  150. "text": "「政府申請規範太繁複, 令人想放棄?」",
  151. "weight": "bold",
  152. "size": "sm",
  153. "align": "center",
  154. "wrap": true,
  155. "margin": "sm"
  156. },
  157. {
  158. "type": "separator",
  159. "margin": "xl"
  160. },
  161. {
  162. "type": "text",
  163. "text": "這一道道關卡往往讓",
  164. "weight": "bold",
  165. "size": "sm",
  166. "align": "center",
  167. "margin": "xl",
  168. "wrap": true
  169. },
  170. {
  171. "type": "text",
  172. "text": "企業主對政府補助望洋興嘆。",
  173. "weight": "bold",
  174. "size": "sm",
  175. "align": "center",
  176. "margin": "sm",
  177. "wrap": true
  178. },
  179. {
  180. "type": "text",
  181. "text": "想要突破困境",
  182. "weight": "bold",
  183. "size": "sm",
  184. "align": "center",
  185. "margin": "sm",
  186. "wrap": true
  187. },
  188. {
  189. "type": "text",
  190. "text": "本次MISA沙龍小聚邀請:",
  191. "weight": "bold",
  192. "size": "sm",
  193. "align": "center",
  194. "margin": "sm",
  195. "wrap": true
  196. },
  197. {
  198. "type": "text",
  199. "text": "南京資訊 吳宗寶董事長與",
  200. "weight": "bold",
  201. "size": "sm",
  202. "align": "center",
  203. "margin": "sm",
  204. "wrap": true
  205. },
  206. {
  207. "type": "text",
  208. "text": "工研院 陳亞詩講師",
  209. "weight": "bold",
  210. "size": "sm",
  211. "align": "center",
  212. "margin": "sm",
  213. "wrap": true
  214. },
  215. {
  216. "type": "text",
  217. "text": "帶領你解析政府補助計畫!",
  218. "weight": "bold",
  219. "size": "sm",
  220. "align": "center",
  221. "margin": "sm",
  222. "wrap": true
  223. }
  224. ],
  225. "offsetTop": "-15px"
  226. },
  227. "footer": {
  228. "type": "box",
  229. "layout": "vertical",
  230. "spacing": "sm",
  231. "contents": [
  232. {
  233. "type": "box",
  234. "layout": "vertical",
  235. "contents": [
  236. {
  237. "type": "button",
  238. "style": "link",
  239. "height": "sm",
  240. "action": {
  241. "type": "uri",
  242. "label": "報名參加",
  243. "uri": "https://s.aiii.ai/g/4f08a7"
  244. },
  245. "color": "#ffffff"
  246. }
  247. ],
  248. "backgroundColor": "#f39a00",
  249. "cornerRadius": "md"
  250. },
  251. {
  252. "type": "box",
  253. "layout": "vertical",
  254. "contents": [
  255. {
  256. "type": "button",
  257. "style": "link",
  258. "height": "sm",
  259. "action": {
  260. "type": "uri",
  261. "label": "活動分享",
  262. "uri": "https://liff.googo.org/misa-0420/?openInAppBrowser=1&openExternalBrowser=1"
  263. },
  264. "color": "#f39a00"
  265. }
  266. ],
  267. "cornerRadius": "md",
  268. "margin": "lg",
  269. "borderColor": "#f39a00",
  270. "borderWidth": "normal"
  271. },
  272. {
  273. "type": "box",
  274. "layout": "vertical",
  275. "contents": [
  276. {
  277. "type": "button",
  278. "style": "link",
  279. "height": "sm",
  280. "action": {
  281. "type": "uri",
  282. "label": "官方網站",
  283. "uri": "https://www.misaglobal.org/"
  284. },
  285. "color": "#f39a00"
  286. }
  287. ],
  288. "cornerRadius": "md",
  289. "margin": "lg",
  290. "borderColor": "#f39a00",
  291. "borderWidth": "normal"
  292. },
  293. {
  294. "type": "box",
  295. "layout": "vertical",
  296. "contents": [
  297. {
  298. "type": "image",
  299. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  300. }
  301. ],
  302. "margin": "none",
  303. "position": "absolute",
  304. "offsetStart": "108px",
  305. "offsetTop": "130px"
  306. }
  307. ],
  308. "flex": 0,
  309. "height": "200px"
  310. }
  311. };
  312. var flex = {
  313. "type": "flex",
  314. "altText": _title,
  315. "contents": myFlexContent,
  316. };
  317. return flex;
  318. }
  319. var redisdata = '';
  320. function shareTargetPicker() {
  321. liff.shareTargetPicker([
  322. createFlexMessageData()
  323. ])
  324. .then(function (res) {
  325. if (res) {
  326. // succeeded in sending a message through TargetPicker
  327. console.log(`[${res.status}] Message sent!`)
  328. } else {
  329. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  330. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  331. // LINE 10.3.0 - 10.10.0
  332. // Old LINE will access here regardless of user's action
  333. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  334. } else {
  335. // LINE 10.11.0 -
  336. // sending message canceled
  337. console.log('TargetPicker was closed!')
  338. }
  339. }
  340. }).catch(function (error) {
  341. // something went wrong before sending a message
  342. console.log('something wrong happen', error)
  343. })
  344. // const url = 'https://liff.googo.org:9898/misa-liff'
  345. // axios
  346. // .get(url)
  347. // .then(({data}) => {
  348. // redisdata=data.data;
  349. // redistitle=data.title;
  350. // console.log(redistitle);
  351. // console.log(redisdata);
  352. // liff.shareTargetPicker([
  353. // {
  354. // type: "text",
  355. // text: "Test!"
  356. // }
  357. // ])
  358. // .then(
  359. // console.log("ShareTargetPicker was launched")
  360. // ).catch(function (res) {
  361. // alert(res);
  362. // console.log("Failed to launch ShareTargetPicker", res)
  363. // })
  364. // // liff
  365. // // .shareTargetPicker([
  366. // // createFlexMessageData()
  367. // // ])
  368. // // .then(() => {
  369. // // alert("Shared to the friend(s) you picked");
  370. // // })
  371. // // .catch(function(res) {
  372. // // alert(res);
  373. // // });
  374. // });
  375. }