shawenguan 2 лет назад
Родитель
Сommit
7364d3775c
2 измененных файлов с 147 добавлено и 34 удалено
  1. 0 7
      BoxJsSub/JoJo_BoxJs.json
  2. 147 27
      Scripts/gandartHelper.js

+ 0 - 7
BoxJsSub/JoJo_BoxJs.json

@@ -101,13 +101,6 @@
                   "val": "",
                   "type": "text",
                   "desc": "产品名称"
-                },
-                {
-                  "id": "lkGandartCollectionCateLst",
-                  "name": "产品列表",
-                  "val": "[]",
-                  "type": "textarea",
-                  "desc": "产品列表"
                 }
             ]
         }

+ 147 - 27
Scripts/gandartHelper.js

@@ -71,26 +71,19 @@ function getInfo() {
             }
             let data = lk.getResponseBody();
             try {
-                // lk.log(data);
                 data = JSON.parse(data);
-                lk.log(`pageItemlst001`);
                 if (data["success"]) {
                     let obj = data["obj"];
-                    lk.log(`pageItemlst002`);
                     let oldItemlst = JSON.parse(lk.getVal(gandartCollectionCateLstKey, '[]'));
                     let pageItemlst = obj["list"];
-                    lk.log(`pageItemlst111`);
                     let newLst = checkAppendCollectionItemsDiff(oldItemlst, pageItemlst);
-                    lk.log(`pageItemlst222`);
                     let jsonStr = JSON.stringify(newLst);
                     lk.setVal(gandartCollectionCateLstKey, jsonStr);
-                    lk.log(`pageItemlst222`);
                     lk.log(jsonStr);
-                    lk.log(`pageItemlst333`);
                 }
-                lk.appendNotifyInfo('更新了产品列表');
+                lk.appendNotifyInfo('🎉更新了产品列表');
             } catch (e) {
-                lk.log(JSON.stringify(e));
+                lk.logErr(e);
                 lk.execFail();
             }
             lk.msg('');
@@ -106,6 +99,7 @@ function getInfo() {
                     let obj = data["obj"];
                     let castingId = String(obj["castingId"]);
                     if(castingId == ""){
+                        // 无法获取请求体
                     }
                     if(castingId != ""){
                         lk.setVal(gardartCastingIdKey, castingId);
@@ -121,6 +115,7 @@ function getInfo() {
                     lk.appendNotifyInfo('❌获取产品信息失败,请稍后再试');
                 }
             } catch (e) {
+                lk.logErr(e);
                 lk.execFail();
                 lk.appendNotifyInfo('❌获取产品信息失败');
             }
@@ -144,6 +139,7 @@ function checkAppendCollectionItemsDiff(cLst, pageLst){
             castingId: dic[k].castingId,
             collectionName: dic[k].collectionName,
             resalePrice: dic[k].resalePrice,
+            viewSort: dic[k].viewSort || 0,
         };
         newLst.push(ele);
     }
@@ -168,13 +164,19 @@ async function all() {
         lk.execFail();
         lk.appendNotifyInfo(`⚠️请先打开光予登录获取token`);
     } else {
-        // await checkBuy();
-        let price = Number(lk.getVal(gardartLimitPriceKey, 0));
-        lk.log(`test111111`);
-        lk.log(String(price));
-        lk.log(gardartLimitPriceKey + "="+typeof(price)+":"+price);
-        lk.log(`test222222`);
-        hasNeedSendNotify = false;
+        let price = lk.getVal(gardartLimitPriceKey, 0);
+        price = Number(price);
+        if(price > 0){
+            let item = await refreshBuyLst(price);
+            if(item){
+                hasNeedSendNotify = await checkToBuy(item);
+            } else {
+                hasNeedSendNotify = false;
+            }
+        } else {
+            lk.prependNotifyInfo('⚠️请设置监控价格');
+            hasNeedSendNotify = true;
+        }
     }
     if (hasNeedSendNotify) {
         lk.msg(``);
@@ -182,26 +184,144 @@ async function all() {
     lk.done();
 }
 
-function checkBuy() {
+function refreshBuyLst(price) {
     return new Promise((resolve, _reject) => {
         try {
-            let price = lk.getVal(gardartLimitPriceKey, 0);
-            price = Number(price);
-            if(price < 0){
-                lk.prependNotifyInfo('请设置监控价格');
-                resolve(1);
-                return;
-            }
-
+            const headers = {
+                'Accept' : `application/json, text/plain, */*`,
+                'Origin' : `https://www.gandart.com`,
+                'Accept-Encoding' : `gzip, deflate, br`,
+                'Content-Type' : `application/x-www-form-urlencoded;charset=UTF-8`,
+                'Connection' : `keep-alive`,
+                'Host' : `api2.gandart.com`,
+                'User-Agent' : `Mozilla/5.0 (iPhone; CPU iPhone OS 16_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Mobile/15E148 Safari/604.1`,
+                'Referer' : `https://www.gandart.com/`,
+                'Accept-Language' : `zh-CN,zh-Hans;q=0.9`,
+                'token' : gandartToken
+            };
+            let signData = getSign();
+            signData.castingId = 0;
+            signData.page = 1;
+            signData.pageSize = 15;
+            signData.sort = 2;
+            signData.transactionStatus = 2;
+            let body = urlEncode(signData);
+            let url = {
+                url: `https://api2.gandart.com/market/api/v2/resaleManage/resale/onSale`,
+                headers: headers,
+                body: body
+            };
+            lk.log(`请求寄售列表=${body}`);
+            lk.post(url, async (error, _response, data) => {
+                let retItem;
+                try {
+                    if (error) {
+                        lk.execFail();
+                        lk.appendNotifyInfo(`❌获取寄售列表失败,请稍后再试`);
+                    } else {
+                        let ret = JSON.parse(data)
+                        if (ret.success) {
+                            let obj = ret.obj;
+                            let lst = obj.list;
+                            for(let d of lst){
+                                if(d.transactionStatus == 2){//2=可购买,4=支付中
+                                    const resalePrice = Number(d.resalePrice);
+                                    if(price <= resalePrice){
+                                        retItem = d;
+                                        lk.appendNotifyInfo(`🎉成功匹配产品[${d.collectionName}#${d.viewSort}],价格:${d.resalePrice}`);
+                                        break;
+                                    }
+                                }
+                            }
+                        } else {
+                            lk.execFail();
+                        }
+                    }
+                } catch (e) {
+                    lk.logErr(e);
+                    lk.execFail();
+                } finally {
+                    resolve(retItem);
+                }
+            });
+        } catch (e) {
+            lk.logErr(e);
+            resolve();
+        }
+    });
+}
 
-        }  catch (e) {
+function checkToBuy(data){
+    return new Promise((resolve, _reject) => {
+        try {
+            const id = data.id;
+            const headers = {
+                'Accept' : `application/json, text/plain, */*`,
+                'Origin' : `https://www.gandart.com`,
+                'Accept-Encoding' : `gzip, deflate, br`,
+                'Content-Type' : `application/x-www-form-urlencoded;charset=UTF-8`,
+                'Connection' : `keep-alive`,
+                'Host' : `api.gandart.com`,
+                'User-Agent' : `Mozilla/5.0 (iPhone; CPU iPhone OS 16_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Mobile/15E148 Safari/604.1`,
+                'Referer' : `https://www.gandart.com/`,
+                'Accept-Language' : `zh-CN,zh-Hans;q=0.9`,
+                'token' : gandartToken
+            };
+            const body = `transactionRecordId=${id}`;
+            let url = {
+                url: `https://api.gandart.com/base/v2/resaleManage/resale/buy/v2`,
+                headers: headers,
+                body: body
+            };
+            lk.log(`请求购买产品=${body}`);
+            resolve(1);
+            // lk.post(url, async (error, _response, data) => {
+            //     let retItem;
+            //     try {
+            //         if (error) {
+            //             lk.execFail()
+            //             lk.appendNotifyInfo(`❌购买失败,请稍后再试`)
+            //         } else {
+            //             let ret = JSON.parse(data)
+            //             if (ret.success) {
+            //                 let obj = ret.obj;
+            //                 let orderNum = obj.orderNum;
+            //                 if(orderNum && orderNum.length > 0){
+            //                     retItem = ret;
+            //                     lk.appendNotifyInfo(`🎉成功下单产品[${obj.collectionName}],订单号:${obj.orderNum}`);
+            //                 }
+            //             } else {
+            //                 lk.execFail();
+            //             }
+            //         }
+            //     } catch (e) {
+            //         lk.logErr(e);
+            //         lk.execFail();
+            //     } finally {
+            //         resolve(retItem);
+            //     }
+            // });
+        } catch (e) {
             lk.logErr(e);
-        } finally {
             resolve();
         }
     });
 }
 
+function urlEncode(param, key, encode) {
+    if(param==null) return '';
+    let paramStr = '';
+    let t = typeof (param);
+    if (t == 'string' || t == 'number' || t == 'boolean') {
+        paramStr += '&' + key + '=' + ((encode==null||encode) ? encodeURIComponent(param) : param);
+    } else {
+        for (let i in param) {
+             let k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i);
+             paramStr += urlEncode(param[i], k, encode);
+        }
+    }
+    return paramStr;
+}
 
 function getSign() {
     const now = new Date().getTime();