|
|
@@ -13,6 +13,7 @@ const OfPayConstKey = {
|
|
|
marketItemsData: 'lkOfPayMarketItemsData',
|
|
|
marketBuyList: 'lkOfPayMarketBuyList',
|
|
|
awardDiscountPrice: 'lkOfPayDiscountPrice',
|
|
|
+ checkBuyRepeatEnable: 'lkOfPayBuyRepeatEnable',
|
|
|
}
|
|
|
|
|
|
let ofpayUserAgent = `Mozilla/5.0 (iPhone; CPU iPhone OS 16_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 F-OFST elife_moblie_ios fullversion:6.0.2 BSComponentVersion:5.4 WorkStationChannel:0 isBreak:0 ICBCiPhoneBSNew 6.0.2 iphone os wkwebview:true`;
|
|
|
@@ -21,6 +22,10 @@ let ofpayUUID = lk.getVal(OfPayConstKey.uuid,'');
|
|
|
// jwt登录身份验证 24小时过期
|
|
|
let ofpayAuthorization = lk.getVal(OfPayConstKey.token, '');
|
|
|
let ofpayCookie = lk.getVal(OfPayConstKey.cookie,'');
|
|
|
+let ofpayAccountPhone = lk.getVal(OfPayConstKey.phone);
|
|
|
+let ofpayCheckBuyRepeatEnable = lk.getVal(OfPayConstKey.checkBuyRepeatEnable, true);
|
|
|
+
|
|
|
+let appVersion = 602;
|
|
|
|
|
|
const CommonHost = 'market-web.ofpay.com';
|
|
|
const GCommonHeads = {
|
|
|
@@ -28,13 +33,12 @@ const GCommonHeads = {
|
|
|
'UUID': ofpayUUID,
|
|
|
'Accept': `*/*`,
|
|
|
'Sec-Fetch-Site': 'same-origin',
|
|
|
- 'Origin': `https://www.gandart.com`,
|
|
|
+ 'Origin': `https://market-web.ofpay.com`,
|
|
|
'Accept-Language': 'zh-CN,zh-Hans;q=0.9',
|
|
|
'Accept-Encoding': `gzip, deflate, br`,
|
|
|
'Sec-Fetch-Mode': 'cors',
|
|
|
'Content-Type': `application/json; charset=utf-8`,
|
|
|
'Connection': `keep-alive`,
|
|
|
- 'Host': `api2.gandart.com`,
|
|
|
'User-Agent': ofpayUserAgent,
|
|
|
'Referer': `https://www.gandart.com/`,
|
|
|
'Accept-Language': `zh-CN,zh-Hans;q=0.9`,
|
|
|
@@ -146,12 +150,25 @@ async function checkToBuyAll(buyList, activityData){
|
|
|
|
|
|
async function checkToBuyOne(subActivityId, itemName, awardList){
|
|
|
let oneRet = null;
|
|
|
+ let nowString = lk.formatDate(new Date(), 'yyyyMMdd');
|
|
|
+ if(ofpayCheckBuyRepeatEnable){
|
|
|
+ let checkBuyRepeatKey = `lkOfPayBuyItemKey#${itemName}`;
|
|
|
+ let lastBuySuccDate = lk.getVal(checkBuyRepeatKey, '');
|
|
|
+ if (nowString == lastBuySuccDate) {
|
|
|
+ lk.log(`商品[${itemName}]今日已抢购成功过,跳过~~`);
|
|
|
+ return oneRet;
|
|
|
+ }
|
|
|
+ }
|
|
|
for(let i=0; i < awardList.length; i++){
|
|
|
const awardData = awardList[i];
|
|
|
if(awardData.prizeName.indexOf(itemName) > -1){
|
|
|
lk.log(`开始尝试抢购-${awardData.prizeName}${awardData.prizeDesc},价格:${awardData.price},库存:${awardData.remainStock}`);
|
|
|
if(awardData.remainStock > 0){
|
|
|
oneRet = await itemBuy(subActivityId, awardData);
|
|
|
+ if(oneRet){
|
|
|
+ // 抢购成功
|
|
|
+ lk.setVal(checkBuyRepeatKey, nowString);
|
|
|
+ }
|
|
|
}else{
|
|
|
lk.log(`库存不足,跳过~`);
|
|
|
}
|
|
|
@@ -186,7 +203,7 @@ async function itemBuy(subActivityId, awardData){
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- const gameAccount = lk.getVal(OfPayConstKey.phone);
|
|
|
+ const gameAccount = ofpayAccountPhone;
|
|
|
const thirdInfo = JSON.parse(awardData.thirdInfo);
|
|
|
const awardId = awardData.awardId;
|
|
|
const awardPrice = parseFloat(awardData.price);
|
|
|
@@ -197,7 +214,7 @@ async function itemBuy(subActivityId, awardData){
|
|
|
lk.log(`商品${prizeName}(面值:${awardFaceValue})\n匹配的最终价格:${awardPrice}\n预设折扣价格:${discountPrice}#${awardId}`);
|
|
|
if(awardPrice <= discountPrice){
|
|
|
let payInfo = await getPayInfo(subActivityId, awardId, '', '', gameAccount, eventVisitorId);
|
|
|
- let payRet = await pay(subActivityId, eventVisitorId);
|
|
|
+ let payRet = await pay(subActivityId, eventVisitorId, payInfo.detailId);
|
|
|
if(payRet){
|
|
|
return awardData;
|
|
|
}
|
|
|
@@ -464,12 +481,19 @@ async function getPayInfo(subActivityId, awardId, goodsId, invitationCode, gameA
|
|
|
}
|
|
|
|
|
|
|
|
|
-async function pay(subActivityId, eventVisitorId){
|
|
|
+async function pay(subActivityId, eventVisitorId, detailId){
|
|
|
return new Promise((resolve, _reject) => {
|
|
|
try {
|
|
|
const headers = GCommonHeads;
|
|
|
headers.Host = 'market-web.ofpay.com';
|
|
|
- const body = ``;
|
|
|
+ headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
|
+ let postData = {
|
|
|
+ detailId: detailId,
|
|
|
+ rechargeAccount: ofpayAccountPhone,
|
|
|
+ account: ofpayAccountPhone,
|
|
|
+ appVersion: appVersion,
|
|
|
+ };
|
|
|
+ const body = JSON.stringify(postData);
|
|
|
const url = `https://${CommonHost}/h5/api/mobile/activity/pay/${subActivityId}?eventVisitorId=${eventVisitorId}`;
|
|
|
let options = {
|
|
|
url: url,
|
|
|
@@ -477,7 +501,7 @@ async function pay(subActivityId, eventVisitorId){
|
|
|
body: body
|
|
|
};
|
|
|
lk.log(`请求下单信息`);
|
|
|
- lk.get(options, async (error, _response, data) => {
|
|
|
+ lk.post(options, async (error, _response, data) => {
|
|
|
let ret;
|
|
|
try {
|
|
|
if (error) {
|