Explorar o código

connect to send api

huai-sian %!s(int64=3) %!d(string=hai) anos
pai
achega
97fdf92337
Modificáronse 2 ficheiros con 31 adicións e 28 borrados
  1. 6 4
      ArkCard-web/collect.html
  2. 25 24
      ArkCard-web/goto.js

+ 6 - 4
ArkCard-web/collect.html

@@ -17,6 +17,7 @@
     <link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css" />
     <link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick-theme.css" />
     <link rel="stylesheet" href="./style.css">
+    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
 </head>
 
 <div id="qr-reader" style="width:100%;display:none"></div>
@@ -336,6 +337,7 @@
         </section>
         <div style="background: #484848;position: fixed; bottom:0px; z-index: 20;" class="sendbox w-100 pt-2">
             <div class="p-2">
+                <input type="number" name="amount" id="number" placeholder="請輸入數量" class="p-2 w-100 mb-3" style="border-radius: 10px; border:none;" required>
                 <input id="address" style="border-radius: 10px; border:none;" class="p-2 w-100 mb-3" type="text" name="address" placeholder="請輸入您要發送的地址" required>
                 <div class="text-end px-2">
                     <p class="text-start text-white mb-2">※ 一次只能發送一則NFT收藏品</p>
@@ -377,7 +379,7 @@ $(document).ready(function () {
         liffId: "1656404434-gJ0Nzy1Y"
     })
     .then(() => {
-        var context = liff.getContext();
+        /* var context = liff.getContext();
         console.log(context);
 
         var profile = liff.getProfile();
@@ -391,10 +393,10 @@ $(document).ready(function () {
             //liff.login({ redirectUri: "https://liff.line.me/1656404434-gJ0Nzy1Y?"+context.userId });  // test
         } else {
             console.log("您已登入");
-        } 
-
+        }  */
+        var userid = 'Ue8e21f8c88f366bff7d1d294c14061ae';
         // 收藏頁面
-        collection(context.userId);
+        collection(userid);
     })
     .catch((err) => {
         console.log('初始化失敗: ' + err.code + ", " + err.message);

+ 25 - 24
ArkCard-web/goto.js

@@ -19,10 +19,11 @@ $(document).on("click", ".close", function (event) {
   $(".collectcontent").removeClass("select");
 });
 
+let userId;
 // 收藏頁面
 function collection(collectuserid='') {
   console.log('Call collection(' + collectuserid + ')'); // test
-
+  userId = collectuserid;
   var collectcontent = '';
 
   $.ajax({
@@ -40,12 +41,15 @@ function collection(collectuserid='') {
       for(let i = 0; i < len; i++) {
         arr.push(msg[i]);
       }
+      arr = arr.filter((item, i) => {
+        return item !== undefined;
+      })
       console.log(arr);
         for(let i = 0; i < arr.length; i++) {
           collectcontent += '\
             <div class="collectcontent col">\
-              <input style="display: none;" type="radio" value="'+ arr[i].id + '" name="nftid" id="' + arr[i].id + '">\
-              <label for="'+ arr[i].id + '">\
+              <input style="display: none;" type="radio" value="'+ arr[i].uid + '" name="nftid" id="' + arr[i].uid + '">\
+              <label for="'+ arr[i].uid + '">\
                 <div class="collectcard card h-100">\
                   <a target="_blank">\
                     <img src="'+ arr[i].imgurl + '"class="card-img-top" alt="...">\
@@ -179,32 +183,29 @@ $.fn.serializeObject = function () {
 
 // 確定發送按鈕處理
 $(".collect-send").submit(function (e) {
-  var nftid = $("input[name='nftid']:checked").val();
+  var nftuid = $("input[name='nftid']:checked").val();
+  var amount = $("input[name='amount']").val();
   var address = $('#address').val();
-
-  var data = `{"nftid":"` + nftid +`","address":"` + address +`"}`;
+  console.log(amount);
+  var data = `{"nftuid": ${nftuid}, "to": "${address}", "userid": "${userId}", "amount": ${amount}}`;
   
+  var headers = {'accept': 'application/json'}
   console.log(data); // test
-  
-  var url = "https://api.ptt.cx:8750/api/v1/line/send";
-
-  var xhr = new XMLHttpRequest();
-  xhr.open("POST", url, false);
-  
-  xhr.setRequestHeader("accept", "application/json");
-  xhr.setRequestHeader("Content-Type", "application/json");
-  
-  xhr.onreadystatechange = function () {
-    if (xhr.readyState === 4) {
-      console.log(xhr.status);
-      console.log(xhr.responseText);
 
-      alert("發送成功");
-      location.replace("collect.html");
-    }
-  };
+  var url = `https://api.ptt.cx:8750/api/v1/line/send?userid=${userId}&to=${address}&nftuid=${nftuid}&amount=${amount}`;
+  axios({
+    method: 'post',
+    url: url,
+    headers,
+    data: ''
+  }).then(res => {
+    console.log(res);
+    window.location.href = './collect.html';
     
-  xhr.send(data);
+  }).catch(err => {
+    console.log(err);
+  })
+  
 });
 
 $(".nft-buy").submit(function (e) {