liff-functions.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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://imgur.com/je9ERTY.jpg"
  99. }
  100. ],
  101. "paddingStart": "5px",
  102. "paddingEnd": "5px",
  103. "height": "160px"
  104. }
  105. ]
  106. },
  107. "body": {
  108. "type": "box",
  109. "layout": "vertical",
  110. "contents": [
  111. {
  112. "type": "text",
  113. "text": "集團董事長給公司主管的 11 堂成功秘方",
  114. "weight": "bold",
  115. "size": "sm",
  116. "align": "center",
  117. "wrap": true
  118. },
  119. {
  120. "type": "text",
  121. "text": "讓您工作順利進行、下屬服從、",
  122. "weight": "bold",
  123. "size": "sm",
  124. "align": "center",
  125. "wrap": true,
  126. "margin": "sm"
  127. },
  128. {
  129. "type": "text",
  130. "text": "同事願意合作以及和老闆溝通沒有障礙",
  131. "weight": "bold",
  132. "size": "sm",
  133. "align": "center",
  134. "wrap": true,
  135. "margin": "sm"
  136. },
  137. {
  138. "type": "text",
  139. "text": "您提出來的企劃案客戶全買單",
  140. "weight": "bold",
  141. "size": "sm",
  142. "align": "center",
  143. "wrap": true,
  144. "margin": "sm"
  145. }
  146. ],
  147. "offsetTop": "-5px"
  148. },
  149. "footer": {
  150. "type": "box",
  151. "layout": "vertical",
  152. "spacing": "sm",
  153. "contents": [
  154. {
  155. "type": "box",
  156. "layout": "vertical",
  157. "contents": [
  158. {
  159. "type": "button",
  160. "style": "link",
  161. "height": "sm",
  162. "action": {
  163. "type": "uri",
  164. "label": "立即上課",
  165. "uri": "https://www.misaglobal.org/program-packages/1f4afee6-d34c-448e-9710-685b202eecb7"
  166. },
  167. "color": "#ffffff"
  168. }
  169. ],
  170. "backgroundColor": "#f39a00",
  171. "cornerRadius": "md"
  172. },
  173. {
  174. "type": "box",
  175. "layout": "vertical",
  176. "contents": [
  177. {
  178. "type": "button",
  179. "style": "link",
  180. "height": "sm",
  181. "action": {
  182. "type": "uri",
  183. "label": "活動分享",
  184. "uri": "https://liff.googo.org/misa-course-1/?openInAppBrowser=1&openExternalBrowser=1"
  185. },
  186. "color": "#f39a00"
  187. }
  188. ],
  189. "cornerRadius": "md",
  190. "margin": "lg",
  191. "borderColor": "#f39a00",
  192. "borderWidth": "normal"
  193. },
  194. {
  195. "type": "box",
  196. "layout": "vertical",
  197. "contents": [
  198. {
  199. "type": "button",
  200. "style": "link",
  201. "height": "sm",
  202. "action": {
  203. "type": "uri",
  204. "label": "課程片段搶先看",
  205. "uri": "https://www.youtube.com/watch?v=aw8rGObY83U"
  206. },
  207. "color": "#f39a00"
  208. }
  209. ],
  210. "cornerRadius": "md",
  211. "margin": "lg",
  212. "borderColor": "#f39a00",
  213. "borderWidth": "normal"
  214. },
  215. {
  216. "type": "box",
  217. "layout": "vertical",
  218. "contents": [
  219. {
  220. "type": "image",
  221. "url": "https://static.kolable.com/images/misa/logo.png/120?v=1641520480847"
  222. }
  223. ],
  224. "margin": "none",
  225. "position": "absolute",
  226. "offsetStart": "108px",
  227. "offsetTop": "135px"
  228. }
  229. ],
  230. "flex": 0,
  231. "height": "200px",
  232. "offsetTop": "-10px"
  233. }
  234. };
  235. var flex = {
  236. "type": "flex",
  237. "altText": _title,
  238. "contents": myFlexContent,
  239. };
  240. return flex;
  241. }
  242. var redisdata = '';
  243. function shareTargetPicker() {
  244. liff.shareTargetPicker([
  245. createFlexMessageData()
  246. ])
  247. .then(function (res) {
  248. if (res) {
  249. // succeeded in sending a message through TargetPicker
  250. console.log(`[${res.status}] Message sent!`)
  251. } else {
  252. const [majorVer, minorVer] = (liff.getLineVersion() || "").split('.');
  253. if (parseInt(majorVer) == 10 && parseInt(minorVer) < 11) {
  254. // LINE 10.3.0 - 10.10.0
  255. // Old LINE will access here regardless of user's action
  256. console.log('TargetPicker was opened at least. Whether succeeded to send message is unclear')
  257. } else {
  258. // LINE 10.11.0 -
  259. // sending message canceled
  260. console.log('TargetPicker was closed!')
  261. }
  262. }
  263. }).catch(function (error) {
  264. // something went wrong before sending a message
  265. console.log('something wrong happen', error)
  266. })
  267. // const url = 'https://liff.googo.org:9898/misa-liff'
  268. // axios
  269. // .get(url)
  270. // .then(({data}) => {
  271. // redisdata=data.data;
  272. // redistitle=data.title;
  273. // console.log(redistitle);
  274. // console.log(redisdata);
  275. // liff.shareTargetPicker([
  276. // {
  277. // type: "text",
  278. // text: "Test!"
  279. // }
  280. // ])
  281. // .then(
  282. // console.log("ShareTargetPicker was launched")
  283. // ).catch(function (res) {
  284. // alert(res);
  285. // console.log("Failed to launch ShareTargetPicker", res)
  286. // })
  287. // // liff
  288. // // .shareTargetPicker([
  289. // // createFlexMessageData()
  290. // // ])
  291. // // .then(() => {
  292. // // alert("Shared to the friend(s) you picked");
  293. // // })
  294. // // .catch(function(res) {
  295. // // alert(res);
  296. // // });
  297. // });
  298. }