liff-functions.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. console.log('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. alert(`${flex}`)
  66. return flex;
  67. }
  68. var redisdata = '';
  69. function shareTargetPicker() {
  70. const url = 'https://liff.googo.org:9898/misa'
  71. axios
  72. .get(url)
  73. .then(({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. }