liff-functions.js 2.4 KB

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