shawenguan 1 год назад
Родитель
Сommit
5e9ac71ad3
2 измененных файлов с 93 добавлено и 5 удалено
  1. 3 2
      Scripts/hbcpre/hbcpreHelper.js
  2. 90 3
      Scripts/hbcpre/hbcpreOrder.js

+ 3 - 2
Scripts/hbcpre/hbcpreHelper.js

@@ -13,7 +13,9 @@
 hostname = lsjk.hbcpre.com
 
 ********************************/
-const magicJS = MagicJS(`华文数交`, "INFO");
+const scriptName = `华文数交助手`;
+const magicJS = MagicJS(scriptName, "INFO");
+
 const HbcpreConstKey = {
     token: 'HbcpreUserToken',
     userInfo: 'HbcpreUserInfo',
@@ -235,7 +237,6 @@ function handleNewpacklist(){
         const id = iData.id;
         tmpItemDict[id] = iData;
         // 退市标志
-        // iData.sell_status = 1;
         if(iData.pay_price == void 0){
             iData.pay_price = '99999.99';
             iData.is_delisted = 1;

+ 90 - 3
Scripts/hbcpre/hbcpreOrder.js

@@ -6,7 +6,8 @@
 * 
 ********************************/
 
-const magicJS = MagicJS(`华文数交下单`, "INFO");
+const scriptName = `华文数交下单`;
+const magicJS = MagicJS(scriptName, "INFO");
 const HbcpreConstKey = {
     token: 'HbcpreUserToken',
     userInfo: 'HbcpreUserInfo',
@@ -30,10 +31,62 @@ async function Main() {
 }
 
 async function tryFastOrder(){
-
+    let itemId = magicJS.data.read(HbcpreConstKey.castingId, null);
+    let itemName = magicJS.data.read(HbcpreConstKey.collectionName, null);
+    if(!itemId && !itemName){
+        return;
+    }
+    let itemList = magicJS.data.read(HbcpreConstKey.collectionClassList, []);
+    let willPrice = Number(magicJS.data.read(HbcpreConstKey.orderLimitPrice, 99999));
+    let priceFloatInterval = Number(magicJS.data.read(HbcpreConstKey.floatPriceIntaval, 0));
+    let willBuyList = [];
+    if(itemId){
+        for(let i=0; i < itemList.length; i++){
+            const iData = itemList[i];
+            const id = iData.id;
+            const price = parseFloat(iData.pay_price || 9999.99);
+            if(id == itemId){
+                if(price >= willPrice - priceFloatInterval &&  price <= willPrice + priceFloatInterval){
+                    willBuyList.push(iData);
+                }
+                break;
+            }
+        }
+    }
+    if(itemName){
+        for(let i=0; i < itemList.length; i++){
+            const iData = itemList[i];
+            const title = iData.title;
+            const price = parseFloat(iData.pay_price || 9999.99);
+            if(title.indexOf(itemName) > -1){
+                if(price >= willPrice - priceFloatInterval &&  price <= willPrice + priceFloatInterval){
+                    willBuyList.push(iData);
+                }
+                break;
+            }
+        }
+    }
+    for(let i=0; i < willBuyList.length; i++){
+        const iData = willBuyList[i];
+        const buyReqData ={
+            collection_id: iData.id,
+            returnurl: 'https://luanshu.hbcpre.com/#/pages/market/detail',
+        };
+        let buyRet = await hbRequest({API: '/api/userOrder/fastMarketOrderCreate', METHOD: 'post'}, buyReqData);
+        if(buyRet){
+            if(buyRet.code == 1000){
+                // magicJS.notification.appendNotifyInfo(`🎉产品【${iData.title}】快捷下单成功`);
+                if(buyRet.data.url){
+                    await openUrl(buyRet.data.url);
+                }
+                magicJS.notification.post(scriptName, "", `🎉产品【${iData.title}】快捷下单成功`, buyRet.data.url);
+            } else {
+                magicJS.logger.info(buyRet.message);
+            }
+        }
+    }
 }
 
-
 function transformKeys(keyStr) {
     let n = 3;
     if (arguments.length > 1 && void 0 !== arguments[1]) {
@@ -68,6 +121,7 @@ function getBaseConfig() {
     };
     return config;
 }
+
 //AES加密
 function encryptAES(wordStr, keyStr, ivStr) {
     if (typeof(wordStr) != 'string') {
@@ -88,6 +142,7 @@ function encryptAES(wordStr, keyStr, ivStr) {
     });
     return encrypted.toString();
 }
+
 //AES解密
 function decryptAES(wordStr, keyStr, ivStr) {
     if (typeof(wordStr) != 'string') {
@@ -109,6 +164,38 @@ function decryptAES(wordStr, keyStr, ivStr) {
     decrypt = decrypt.toString(CryptoJS.enc.Utf8);
     return decrypt.toString();
 }
+
+
+
+async function openUrl(url){
+    const tokenInfo = magicJS.data.read(HbcpreConstKey.token, '');
+    const headers = {
+        "If-Modified-Since": "0",
+        "Cache-Control": "no-cache",
+        "Content-Type": "application/json",
+        "Authorization": `Bearer ${tokenInfo}`,
+        "User-Agent": userAgent,
+    };
+    let options = {
+        url: `${url}`,
+        headers: headers,
+        body: body
+    };
+    let result = await magicJS.http.get(options).then(response => {
+        try {
+            const body = response.body;
+            return body;
+        } catch (e) {
+            magicJS.logger.error(e);
+        }
+    }).catch(err => {
+        const msg = `签到异常\n${JSON.stringify(err)}`;
+        magicJS.logger.error(msg);
+    });
+    return result;
+}
+
+
 async function hbRequest(config, data) {
     const api = config.API;
     const method = config.METHOD;