liff-functions.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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://sirateek.me",
  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 myFlexContent =
  60. {
  61. "type": "bubble",
  62. "size": "mega",
  63. "header": {
  64. "type": "box",
  65. "layout": "vertical",
  66. "contents": [
  67. {
  68. "type": "box",
  69. "layout": "vertical",
  70. "contents": [
  71. {
  72. "type": "text",
  73. "text": "ChoozMo x 引新聞",
  74. "color": "#ffffff66",
  75. "size": "sm"
  76. },
  77. {
  78. "type": "text",
  79. "text": "AI主播新聞曝光服務",
  80. "color": "#ffffff",
  81. "size": "xl",
  82. "flex": 4,
  83. "weight": "bold"
  84. }
  85. ]
  86. }
  87. ],
  88. "paddingAll": "20px",
  89. "backgroundColor": "#0367D3",
  90. "spacing": "md",
  91. "height": "100px",
  92. "paddingTop": "22px"
  93. },
  94. "body": {
  95. "type": "box",
  96. "layout": "vertical",
  97. "contents": [
  98. {
  99. "type": "image",
  100. "url": "https://img.youtube.com/vi/K5DEJXajtqA/0.jpg",
  101. "size": "full",
  102. "aspectRatio": "16:9",
  103. "aspectMode": "cover",
  104. "margin": "none",
  105. "offsetTop": "none"
  106. },
  107. {
  108. "type": "text",
  109. "text": "以集仕多為例。您也能享有同等級曝光。",
  110. "color": "#b7b7b7",
  111. "size": "xs"
  112. },
  113. {
  114. "type": "box",
  115. "layout": "horizontal",
  116. "contents": [
  117. {
  118. "type": "image",
  119. "url": "https://s.yimg.com/rz/p/yahoo_news_zh-Hant-TW_h_p_newsv2.png",
  120. "margin": "xs"
  121. },
  122. {
  123. "type": "box",
  124. "layout": "vertical",
  125. "contents": [],
  126. "flex": 0
  127. },
  128. {
  129. "type": "text",
  130. "text": "線上活動不受疫情影響 逆勢催生台灣元宇宙策展創新服務",
  131. "gravity": "center",
  132. "flex": 4,
  133. "size": "sm",
  134. "wrap": true
  135. }
  136. ],
  137. "spacing": "xs",
  138. "cornerRadius": "30px",
  139. "margin": "xl",
  140. "action": {
  141. "type": "uri",
  142. "label": "action",
  143. "uri": "https://tw.news.yahoo.com/%E7%B7%9A%E4%B8%8A%E6%B4%BB%E5%8B%95%E4%B8%8D%E5%8F%97%E7%96%AB%E6%83%85%E5%BD%B1%E9%9F%BF-%E9%80%86%E5%8B%A2%E5%82%AC%E7%94%9F%E5%8F%B0%E7%81%A3%E5%85%83%E5%AE%87%E5%AE%99%E7%AD%96%E5%B1%95%E5%89%B5%E6%96%B0%E6%9C%8D%E5%8B%99-035234457.html"
  144. }
  145. },
  146. {
  147. "type": "box",
  148. "layout": "horizontal",
  149. "contents": [
  150. {
  151. "type": "image",
  152. "url": "https://cc.tvbs.com.tw/img/upload/2021/03/03/20210303100057-83c4f845.png",
  153. "margin": "xs"
  154. },
  155. {
  156. "type": "box",
  157. "layout": "vertical",
  158. "contents": [],
  159. "flex": 0
  160. },
  161. {
  162. "type": "text",
  163. "text": "疫情催生元宇宙策展創新服務 VR觀展全新體驗",
  164. "gravity": "center",
  165. "flex": 4,
  166. "size": "sm",
  167. "wrap": true
  168. }
  169. ],
  170. "spacing": "xs",
  171. "cornerRadius": "30px",
  172. "margin": "xl",
  173. "action": {
  174. "type": "uri",
  175. "label": "action",
  176. "uri": "https://news.tvbs.com.tw/life/1783151"
  177. }
  178. },
  179. {
  180. "type": "box",
  181. "layout": "horizontal",
  182. "contents": [
  183. {
  184. "type": "image",
  185. "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/LINE_logo.svg/2048px-LINE_logo.svg.png",
  186. "margin": "xs"
  187. },
  188. {
  189. "type": "box",
  190. "layout": "vertical",
  191. "contents": [],
  192. "flex": 0
  193. },
  194. {
  195. "type": "text",
  196. "text": "線上活動不受疫情影響 逆勢催生台灣元宇宙策展創新服務",
  197. "gravity": "center",
  198. "flex": 4,
  199. "size": "sm",
  200. "wrap": true
  201. }
  202. ],
  203. "spacing": "xs",
  204. "cornerRadius": "30px",
  205. "margin": "xl",
  206. "action": {
  207. "type": "uri",
  208. "label": "action",
  209. "uri": "https://today.line.me/tw/v2/article/gzBJpea"
  210. }
  211. }
  212. ],
  213. "offsetTop": "none"
  214. },"footer": {
  215. "type": "box",
  216. "layout": "vertical",
  217. "contents": [
  218. {
  219. "type": "text",
  220. "text": "幫您的產品服務在Yahoo, LINE today, TVBS, Pchome 等12個媒體曝光",
  221. "wrap": true,
  222. "color": "#AAAAAA",
  223. "size": "xs",
  224. "offsetStart": "md"
  225. },
  226. {
  227. "type": "button",
  228. "action": {
  229. "type": "uri",
  230. "label": "請來採訪我",
  231. "uri": "https://page.line.me/choozmo"
  232. },
  233. "style": "primary"
  234. }
  235. ]
  236. }
  237. };
  238. var flex = {
  239. "type": "flex",
  240. "altText": 'title',
  241. "contents": myFlexContent,
  242. };
  243. return flex;
  244. }
  245. function shareTargetPicker() {
  246. liff
  247. .shareTargetPicker([
  248. createFlexMessageData()
  249. ])
  250. .then(() => {
  251. // alert("Shared to the friend(s) you picked");
  252. })
  253. .catch(function(res) {
  254. alert(res);
  255. });
  256. }