145 lines
4.8 KiB
JavaScript
145 lines
4.8 KiB
JavaScript
/*
|
|
关注有礼beta v1.0.0
|
|
|
|
https://shop.m.jd.com/?shopId=1000304221
|
|
650767_655224
|
|
https://shop.m.jd.com/?shopId=650767&venderId=650767
|
|
|
|
export B_FOLLOW_SHOP_ARGV=""
|
|
|
|
cron: 1 1 1 1 *
|
|
const $ = new Env("关注有礼beta");
|
|
*/
|
|
|
|
let l1IlIiIi = __dirname.includes("bear"),
|
|
ilIIlIl1 = decodeURIComponent(process.argv.splice(2)?.[0] || process.env.M_FOLLOW_SHOP_ARGV);
|
|
if (l1IlIiIi) {
|
|
ilIIlIl1 = "650767_655224";
|
|
ilIIlIl1 = "https://shop.m.jd.com/?shopId=650767";
|
|
ilIIlIl1 = "https://shop.m.jd.com/?venderId=650767";
|
|
ilIIlIl1 = "https://shop.m.jd.com/?shopId=650767&venderId=650767";
|
|
ilIIlIl1 = "1000083882_1000083882";
|
|
ilIIlIl1 = "https://shop.m.jd.com/shop/home?shopId=158274";
|
|
}
|
|
const {
|
|
RunMode: Ii1I1iil,
|
|
UserMode: lli1111I,
|
|
tools: tool
|
|
} = require("./bear");
|
|
const qs = require("qs");
|
|
Ii1I1iil.envInfo = {
|
|
"name": "M关注有礼",
|
|
"runName": "jd_follow_shop",
|
|
"env": "M_FOLLOW_SHOP_ARGV",
|
|
"version": "1.0.0"
|
|
};
|
|
class i11IiIIl extends lli1111I {
|
|
constructor(iiiIIliI, l1I1iI) {
|
|
super(iiiIIliI, l1I1iI);
|
|
}
|
|
["removeLastCharacterIfAmpersand"](Ii1iIlII) {
|
|
const l111i11l = Ii1iIlII.charAt(Ii1iIlII.length - 1);
|
|
if (l111i11l === "&") {
|
|
return Ii1iIlII.slice(0, -1);
|
|
} else return Ii1iIlII;
|
|
}
|
|
async ["drawShopGift"](IiiilI) {
|
|
let I1I11iii = {
|
|
"activityId": IiiilI
|
|
};
|
|
this.shopId && (I1I11iii.shopId = this.shopId);
|
|
this.venderId && (I1I11iii.venderId = this.venderId);
|
|
let l1iiii1i = await this.jd_api({
|
|
"url": "https://api.m.jd.com/client.action?functionId=whx_drawShopGift&appid=shop_m_jd_com&body=" + encodeURIComponent(JSON.stringify(I1I11iii)),
|
|
"headers": {
|
|
"Referer": "https://shop.m.jd.com/"
|
|
}
|
|
});
|
|
this.debug(l1iiii1i);
|
|
if (l1iiii1i && l1iiii1i.code === "0") {
|
|
let iliI1iII = l1iiii1i.result,
|
|
iiIl1II = iliI1iII?.["alreadyReceivedGifts"]?.["map"](I11IlII => "" + I11IlII?.["rearWord"] + I11IlII?.["redWord"])["join"](",");
|
|
this.putMsg(iiIl1II);
|
|
return;
|
|
}
|
|
this.putMsg(l1iiii1i ? JSON.stringify(l1iiii1i) : "领取失败");
|
|
}
|
|
async ["userTask"]() {
|
|
if (this.followShopArgv?.["startsWith"]("http")) {
|
|
this.shopId = this.getQueryString(this.followShopArgv, "shopId");
|
|
this.venderId = this.getQueryString(this.followShopArgv, "venderId");
|
|
} else {
|
|
if (this.followShopArgv.includes("_")) {
|
|
let I1i111il = this.followShopArgv.split("_");
|
|
this.shopId = I1i111il[0];
|
|
this.venderId = I1i111il[1];
|
|
} else {
|
|
if (/^\d+$/.test(this.followShopArgv)) this.venderId = this.followShopArgv;else {
|
|
this.putMsg("参数错误");
|
|
this.stop();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
!this.shopId && !this.venderId && (this.putMsg("参数错误"), this.stop());
|
|
let lIIl11Il = "https://shop.m.jd.com/?" + (this.shopId ? "shopId=" + this.shopId + "&" : "") + (this.venderId ? "venderId=" + this.venderId : "");
|
|
Ii1I1iil.activity.activityUrl = this.removeLastCharacterIfAmpersand(lIIl11Il);
|
|
let body = {
|
|
"shopId": this.shopId,
|
|
"source":"app-shop",
|
|
"sourceRpc": "shop_app_home_home",
|
|
"venderId": this.venderId
|
|
};
|
|
let sign = tool.getSignData("getShopHomeActivityInfo", body, this.phoneInfo);
|
|
let sifnStr = qs.stringify(sign);
|
|
|
|
let i11li1i = await this.jd_api({
|
|
"url": 'https://api.m.jd.com/client.action?functionId=getShopHomeActivityInfo&' + sifnStr,
|
|
"headers": this.headers
|
|
});
|
|
if (!i11li1i || i11li1i.code !== "0") {
|
|
this.putMsg(i11li1i ? JSON.stringify(i11li1i) : "获取活动信息失败");
|
|
return;
|
|
}
|
|
let iilliil1 = i11li1i.result;
|
|
if (iilliil1?.["followed"]) {
|
|
this.putMsg("已经关注过");
|
|
await this.unfollow();
|
|
}
|
|
if (iilliil1?.["shopGifts"]) {
|
|
let body = {
|
|
"shopId": this.shopId,
|
|
"source":"app-shop",
|
|
"sourceRpc": "shop_app_home_home",
|
|
"venderId": this.venderId,
|
|
"activityId": iilliil1?.["activityId"]
|
|
};
|
|
let sign = tool.getSignData("drawShopGift", body, this.phoneInfo);
|
|
let sifnStr = qs.stringify(sign);
|
|
let lIiillIl = await this.jd_api({
|
|
"url": "https://api.m.jd.com/client.action?functionId=drawShopGift&" + sifnStr,
|
|
"headers": this.headers
|
|
});
|
|
this.debug(lIiillIl);
|
|
if (lIiillIl && lIiillIl.code === "0") {
|
|
let I1lIl1Ii = lIiillIl.result,
|
|
llIlli1I = I1lIl1Ii?.["alreadyReceivedGifts"]?.["map"](liIili1i => "" + liIili1i?.["rearWord"] + liIili1i?.["redWord"])["join"](",");
|
|
this.putMsg(llIlli1I);
|
|
return;
|
|
}
|
|
this.putMsg(lIiillIl ? JSON.stringify(lIiillIl) : "领取失败");
|
|
} else {
|
|
this.putMsg("未发现关注有礼活动");
|
|
}
|
|
}
|
|
}
|
|
Ii1I1iil.activity = {
|
|
"followShopArgv": ilIIlIl1
|
|
};
|
|
Ii1I1iil.TaskClass = i11IiIIl;
|
|
Ii1I1iil.run({
|
|
"whitelist": ["1-2000"],
|
|
"main_thread": 3,
|
|
"wxProxySmart": 1
|
|
});
|