liff-functions.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // const liffId = "1657279859-Nz2nKkQA";
  2. function getProfile() {
  3. liff
  4. .getProfile()
  5. .then(profile => {
  6. console.log(JSON.stringify(profile));
  7. window.alert(JSON.stringify(profile));
  8. })
  9. .catch(e => {
  10. console.log(e);
  11. window.alert(e);
  12. });
  13. }
  14. function getAccessToken() {
  15. window.alert(liff.getAccessToken());
  16. }
  17. function getContext() {
  18. window.alert(JSON.stringify(liff.getContext()));
  19. }
  20. function sendMessage() {
  21. liff
  22. .sendMessages([{ type: "text", text: "中文測試 Hello from LIFF2.0" }])
  23. .then(() => {
  24. window.alert("Message has been sent");
  25. })
  26. .catch(e => {
  27. window.alert(e);
  28. });
  29. }
  30. function login() {
  31. console.log('login');
  32. // liff.login();
  33. liff.login({
  34. // 使用者登入後要去到哪個頁面
  35. redirectUri: 'https://liff.googo.org/liff2-taroboba-yuan/'
  36. });
  37. // (async () => {
  38. // await liff.init({ liffId: liffId })
  39. // if (new URL(window.location).searchParams.get('liff.state')) return
  40. // const liffLoginRedirect = sessionStorage.getItem('liffLoginRedirect')
  41. // if (_.isString(liffLoginRedirect)) {
  42. // sessionStorage.removeItem('liffLoginRedirect')
  43. // location.href = liffLoginRedirect
  44. // console.log(liffLoginRedirect)
  45. // }
  46. // })()
  47. }
  48. function scanCode() {
  49. liff
  50. .scanCode()
  51. .then(result => {
  52. window.alert(JSON.stringify(result));
  53. })
  54. .catch(e => {
  55. window.alert(e);
  56. });
  57. }
  58. function openWindow() {
  59. liff.openWindow({
  60. url: "https://sirateek.me",
  61. external: true
  62. });
  63. }
  64. function closeWindow() {
  65. liff.closeWindow();
  66. }
  67. function logout() {
  68. if (liff.isLoggedIn()) {
  69. liff.logout();
  70. window.alert("Successfully to Logout");
  71. location.reload();
  72. }
  73. }
  74. function createFlexMessageData() {
  75. var flex = {
  76. "type": "flex",
  77. "altText": redistitle,
  78. "contents": redisdata,
  79. };
  80. return flex;
  81. }
  82. var redisdata = '';
  83. function shareTargetPicker() {
  84. const url = 'https://liff.googo.org:9898/liff2-taroboba-yuan'
  85. axios
  86. .get(url)
  87. .then(({ data }) => {
  88. console.log('data', data);
  89. redisdata = data.data;
  90. redistitle = data.title;
  91. console.log(redistitle);
  92. console.log(redisdata);
  93. liff
  94. .shareTargetPicker([
  95. createFlexMessageData()
  96. ])
  97. .then(() => {
  98. alert("Shared to the friend(s) you picked");
  99. })
  100. .catch(function (res) {
  101. alert(res);
  102. });
  103. });
  104. }
  105. (function test() {
  106. setTimeout(() => {
  107. liff.isLoggedIn();
  108. console.log('123');
  109. }, 3000);
  110. })();