liff-functions.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. console.log('login');
  31. liff.login();
  32. // liff.login({
  33. // // 使用者登入後導向頁面
  34. // redirectUri: 'https://liff.googo.org/misa/'
  35. // });
  36. }
  37. // function login() {
  38. // console.log('login');
  39. // // liff.login();
  40. // liff.login({
  41. // // 使用者登入後導向頁面
  42. // redirectUri: 'https://liff.googo.org/misa/'
  43. // });
  44. // // (async () => {
  45. // // await liff.init({ liffId: liffId })
  46. // // if (new URL(window.location).searchParams.get('liff.state')) return
  47. // // const liffLoginRedirect = sessionStorage.getItem('liffLoginRedirect')
  48. // // if (_.isString(liffLoginRedirect)) {
  49. // // sessionStorage.removeItem('liffLoginRedirect')
  50. // // location.href = liffLoginRedirect
  51. // // console.log(liffLoginRedirect)
  52. // // }
  53. // // })()
  54. // }
  55. function scanCode() {
  56. liff
  57. .scanCode()
  58. .then(result => {
  59. window.alert(JSON.stringify(result));
  60. })
  61. .catch(e => {
  62. window.alert(e);
  63. });
  64. }
  65. function openWindow() {
  66. liff.openWindow({
  67. url: "https://sirateek.me",
  68. external: true
  69. });
  70. }
  71. function closeWindow() {
  72. liff.closeWindow();
  73. }
  74. function logout() {
  75. console.log('logout');
  76. if (liff.isLoggedIn()) {
  77. liff.logout();
  78. window.alert("Successfully to Logout");
  79. location.reload();
  80. }
  81. }
  82. function createFlexMessageData() {
  83. var flex = {
  84. "type": "flex",
  85. "altText": redistitle,
  86. "contents": redisdata,
  87. };
  88. alert(`${flex}`)
  89. return flex;
  90. }
  91. var redisdata = '';
  92. function shareTargetPicker() {
  93. const url = 'https://liff.googo.org:9898/misa'
  94. axios
  95. .get(url)
  96. .then(({ data }) => {
  97. redisdata = data.data;
  98. redistitle = data.title;
  99. console.log(redistitle);
  100. console.log(redisdata);
  101. console.log('測試');
  102. /* Test */
  103. liff.shareTargetPicker([
  104. {
  105. type: "text",
  106. text: "Hello, World!"
  107. }
  108. ])
  109. .then(
  110. console.log("ShareTargetPicker was launched")
  111. ).catch(function (res) {
  112. alert(res);
  113. console.log("Failed to launch ShareTargetPicker", res)
  114. })
  115. // liff
  116. // .shareTargetPicker([
  117. // createFlexMessageData()
  118. // ])
  119. // .then(() => {
  120. // alert("Shared to the friend(s) you picked");
  121. // })
  122. // .catch(function(res) {
  123. // alert(res);
  124. // });
  125. });
  126. }