liff-functions.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 shareTargetPicker() {
  59. liff
  60. .shareTargetPicker([
  61. {
  62. "type": "bubble",
  63. "styles": {
  64. "footer": {
  65. "backgroundColor": "#42b3f4"
  66. }
  67. },
  68. "header": {
  69. "type": "box",
  70. "layout": "horizontal",
  71. "contents": [
  72. {
  73. "type": "box",
  74. "layout": "baseline",
  75. "contents": [
  76. {
  77. "type": "icon",
  78. "size": "xxl",
  79. "url": "https://scontent.fbkk7-2.fna.fbcdn.net/v/t1.0-1/p200x200/22814542_1962234637127047_1607260544847069468_n.png?_nc_cat=0&oh=2a303227c24dfab9e71a405b6d594d50&oe=5BC3965D"
  80. }
  81. ]
  82. },
  83. {
  84. "type": "box",
  85. "layout": "vertical",
  86. "flex": 5,
  87. "contents": [
  88. {
  89. "type": "text",
  90. "text": "โรงพยาบาลอ่างทอง",
  91. "weight": "bold",
  92. "color": "#aaaaaa",
  93. "size": "md",
  94. "gravity": "top"
  95. },
  96. {
  97. "type": "text",
  98. "text": "ขอขอบพระคุณ",
  99. "weight": "bold",
  100. "color": "#aaaaaa",
  101. "size": "lg",
  102. "gravity": "top"
  103. }
  104. ]
  105. }
  106. ]
  107. },
  108. "hero": {
  109. "type": "image",
  110. "url": "https://scontent.fbkk7-2.fna.fbcdn.net/v/t1.0-9/35076722_2227987830551725_330757188106584064_n.jpg?_nc_cat=0&oh=0f5fa137c5bd65f109a40439afcd59eb&oe=5BB566B6",
  111. "size": "full",
  112. "aspectRatio": "16:9",
  113. "aspectMode": "cover",
  114. "action": {
  115. "type": "uri",
  116. "uri": "http://bit.ly/2JGBRKv"
  117. }
  118. },
  119. "body": {
  120. "type": "box",
  121. "layout": "vertical",
  122. "contents": [
  123. {
  124. "type": "text",
  125. "margin": "sm",
  126. "text": "คุณกานต์สินี ไหลสงวนงาม",
  127. "weight": "bold",
  128. "size": "md",
  129. "wrap": true
  130. },
  131. {
  132. "type": "box",
  133. "layout": "vertical",
  134. "margin": "xs",
  135. "contents": [
  136. {
  137. "type": "box",
  138. "layout": "baseline",
  139. "spacing": "sm",
  140. "contents": [
  141. {
  142. "type": "text",
  143. "text": "บริจาคเงินจำนวน ๑๘๐,๐๐๐ บาท เพื่อซื้อครุภัณฑ์ทางการแพทย์ ใช้ในโรงพยาบาลอ่างทอง โดยมีนายแพทย์พงษ์นรินทร์ ชาติรังสรรค์ผู้อำนวยการโรงพยาบาลอ่างทอง เป็นผู้รับมอบ",
  144. "wrap": true,
  145. "color": "#666666",
  146. "size": "sm",
  147. "flex": 6
  148. }
  149. ]
  150. }
  151. ]
  152. },
  153. {
  154. "type": "text",
  155. "margin": "md",
  156. "text": "วันที่ 12 มิ.ย. 2561",
  157. "size": "sm",
  158. "color": "#adadad"
  159. }
  160. ]
  161. },
  162. "footer": {
  163. "type": "box",
  164. "layout": "vertical",
  165. "spacing": "sm",
  166. "contents": [
  167. {
  168. "type": "button",
  169. "style": "link",
  170. "color": "#FFFFFF",
  171. "height": "sm",
  172. "action": {
  173. "type": "uri",
  174. "label": "อ่านต่อ...",
  175. "uri": "http://bit.ly/2JGBRKv"
  176. }
  177. }
  178. ]
  179. }
  180. }
  181. ])
  182. .then(() => {
  183. alert("Shared to the friend(s) you picked");
  184. })
  185. .catch(function(res) {
  186. alert(res);
  187. });
  188. }