liff-functions.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 scanCode() {
  34. liff
  35. .scanCode()
  36. .then(result => {
  37. window.alert(JSON.stringify(result));
  38. })
  39. .catch(e => {
  40. window.alert(e);
  41. });
  42. }
  43. function openWindow() {
  44. liff.openWindow({
  45. url: "https://sirateek.me",
  46. external: true
  47. });
  48. }
  49. function closeWindow() {
  50. liff.closeWindow();
  51. }
  52. function logout() {
  53. if (liff.isLoggedIn()) {
  54. liff.logout();
  55. window.alert("Successfully to Logout");
  56. location.reload();
  57. }
  58. }
  59. function createFlexMessageData() {
  60. var flex = {
  61. "type": "flex",
  62. "altText": redistitle,
  63. "contents": redisdata,
  64. };
  65. return flex;
  66. }
  67. var redisdata = '';
  68. function shareTargetPicker() {
  69. const url = 'https://liff.googo.org:9898/getbtn'
  70. axios
  71. .get(url)
  72. .then(({ data }) => {
  73. console.log('data', data);
  74. redisdata = data.data;
  75. redistitle = data.title;
  76. console.log(redistitle);
  77. console.log(redisdata);
  78. liff
  79. .shareTargetPicker([
  80. createFlexMessageData()
  81. ])
  82. .then(() => {
  83. alert("Shared to the friend(s) you picked");
  84. })
  85. .catch(function (res) {
  86. alert(res);
  87. });
  88. });
  89. }
  90. (function test() {
  91. setTimeout(() => {
  92. liff.isLoggedIn();
  93. console.log('123');
  94. }, 3000);
  95. })();