Mike преди 3 години
родител
ревизия
38cdea8f23
променени са 1 файла, в които са добавени 40 реда и са изтрити 31 реда
  1. 40 31
      ArkCard-web/collect.html

+ 40 - 31
ArkCard-web/collect.html

@@ -370,41 +370,50 @@
     <script charset="utf-8" src="https://static.line-scdn.net/liff/edge/2/sdk.js"></script>
 
 <script>
-liff.init({
-    liffId: "1656494344-JovNdOv0"
-})
-.then(() => {
-    var context = liff.getContext();
-    console.log(context);
+$(document).ready(function () {
+    liff.init({
+        liffId: "1656494344-JovNdOv0"
+    })
+    .then(() => {
+        // var context = liff.getContext();
+        // console.log(context);
 
-    var profile = liff.getProfile();
-    console.log(profile);
+        var profile = liff.getProfile();
+        console.log(profile);
 
-    // liff.login({ redirectUri: "https://ark.cards/collect.html?"+context.contextId });  // test   
+        // liff.login({ redirectUri: "https://ark.cards/collect.html?"+context.contextId });  // test   
 
-    // login
-    if (!liff.isLoggedIn()) {
-        console.log("您未登入");
-        liff.login({ redirectUri: "https://ark.cards/collect.html?"+profile.userId });  // test
-    } else {
-        console.log("您已登入");
-    }
-})
-.catch((err) => {
-    console.log('初始化失敗: ' + err.code + ", " + err.message);
-});
-
-$(".qrcode").click(function () {
-    alert('QRCode Scanner Starting...'); // test
+        // login
+        if (!liff.isLoggedIn()) {
+            console.log("您未登入");
+            liff.login({ redirectUri: "https://ark.cards/collect.html?"+profile.userId });  // test
+        } else {
+            console.log("您已登入");
+        }
+    })
+    .catch((err) => {
+        console.log('初始化失敗: ' + err.code + ", " + err.message);
+    });
 
-    // scanCodeV2 call
-    liff.scanCodeV2().then(result => {
-        // e.g. result = { value: "Hello LIFF app!" }
-        alert(result.value); // test
-        $('#address').val(result.value);
-    }).catch(err => {
-        alert(err); // test
-        console.log(err);
+    $(".qrcode").click(function () {
+        liff.scanCode().then(result => {
+            // e.g. result = { value: "Hello LIFF app!" }
+            alert(JSON.stringify(result); // test
+            $('#address').val(result.value);
+        }).catch(err => {
+            alert(JSON.stringify(err)); // test
+            console.log(JSON.stringify(err));
+        });
+        /*
+        // scanCodeV2 call
+        liff.scanCodeV2().then(result => {
+            // e.g. result = { value: "Hello LIFF app!" }
+            $('#address').val(result.value);
+        }).catch(err => {
+            alert(err); // test
+            console.log(err);
+        });
+        */
     });
 });
 </script>