liff-functions.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. if (liff.isLoggedIn()) {
  53. liff.logout();
  54. window.alert("Successfully to Logout");
  55. location.reload();
  56. }
  57. }
  58. function createFlexMessageData() {
  59. var flex = {
  60. "type": "flex",
  61. "altText": redistitle,
  62. "contents": redisdata,
  63. };
  64. return flex;
  65. }
  66. var redisdata='';
  67. function shareTargetPicker() {
  68. const url = 'https://liff.googo.org:9898/getliff3'
  69. axios
  70. .get(url)
  71. .then(({data}) => {
  72. redisdata=data.data;
  73. redistitle=data.title;
  74. console.log(redistitle);
  75. console.log(redisdata);
  76. liff
  77. .shareTargetPicker([
  78. createFlexMessageData()
  79. ])
  80. .then(() => {
  81. alert("Shared to the friend(s) you picked");
  82. })
  83. .catch(function(res) {
  84. alert(res);
  85. });
  86. });
  87. }