forked from shufflewzc/faker2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jd_follow_shop.js
125 lines (120 loc) · 3.85 KB
/
jd_follow_shop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
7 7 7 7 7 m_jd_follow_shop.js
*/
let mode = __dirname.includes('magic')
const {Env} = mode ? require('./magic') : require('./magic')
const $ = new Env('M关注有礼');
$.followShopArgv = process.env.M_FOLLOW_SHOP_ARGV
? process.env.M_FOLLOW_SHOP_ARGV
: '';
if (mode) {
$.followShopArgv = '1000104168_1000104168'
}
$.logic = async function () {
let argv = $?.followShopArgv?.split('_');
$.shopId = argv?.[0];
$.venderId = argv?.[1];
if (!$.shopId || !$.venderId) {
$.log(`无效的参数${$.followShopArgv}`)
$.expire = true;
return
}
let actInfo = await getShopHomeActivityInfo();
if (actInfo?.code !== '0') {
$.log(JSON.stringify(actInfo))
if (actInfo?.message.includes('不匹配')) {
$.expire = true;
}
return
}
let actInfoData = actInfo?.result;
if (actInfoData?.shopGifts?.filter(o => o.rearWord.includes('京豆')).length
> 0) {
$.activityId = actInfoData?.activityId?.toString();
let gift = await drawShopGift();
if (gift?.code !== '0') {
$.log(JSON.stringify(gift))
return
}
let giftData = gift?.result;
$.log(giftData)
for (let ele of
giftData?.alreadyReceivedGifts?.filter(o => o.prizeType === 4) || []) {
$.putMsg(`${ele.redWord}${ele.rearWord}`);
}
} else {
$.putMsg(`没有豆子`);
}
};
let kv = {'jd': '京豆', 'jf': '积分', 'dq': 'q券'}
$.after = async function () {
$.msg.push(`\n${(await $.getShopInfo()).shopName}`);
if ($?.content) {
let message = `\n`;
for (let ele of $.content || []) {
message += ` ${ele.takeNum || ele.discount} ${kv[ele?.type]}\n`
}
$.msg.push(message)
$.msg.push($.activityUrl);
}
}
$.run({whitelist: ['1-5'], wait: [1000, 3000]}).catch(reason => $.log(reason))
async function drawShopGift() {
$.log('店铺信息', $.shopId, $.venderId, $.activityId)
let sb = {
"follow": 0,
"shopId": $.shopId,
"activityId": $.activityId,
"sourceRpc": "shop_app_home_window",
"venderId": $.venderId
};
let newVar = await $.sign('drawShopGift', sb);
let headers = {
'J-E-H': '',
'Connection': 'keep-alive',
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'api.m.jd.com',
'Referer': '',
'J-E-C': '',
'Accept-Language': 'zh-Hans-CN;q=1, en-CN;q=0.9',
'Accept': '*/*',
'User-Agent': 'JD4iPhone/167841 (iPhone; iOS; Scale/3.00)'
}
// noinspection DuplicatedCode
headers['Cookie'] = $.cookie
let url = `https://api.m.jd.com/client.action?functionId=` + newVar.fn
let {status, data} = await $.request(url, headers, newVar.sign);
return data;
}
async function getShopHomeActivityInfo() {
let sb = {
"shopId": $.shopId,
"source": "app-shop",
"latWs": "0",
"lngWs": "0",
"displayWidth": "1098.000000",
"sourceRpc": "shop_app_home_home",
"lng": "0",
"lat": "0",
"venderId": $.venderId
}
let newVar = await $.sign('getShopHomeActivityInfo', sb);
let headers = {
'J-E-H': '',
'Connection': 'keep-alive',
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'api.m.jd.com',
'Referer': '',
'J-E-C': '',
'Accept-Language': 'zh-Hans-CN;q=1, en-CN;q=0.9',
'Accept': '*/*',
'User-Agent': 'JD4iPhone/167841 (iPhone; iOS; Scale/3.00)'
}
// noinspection DuplicatedCode
headers['Cookie'] = $.cookie
let url = `https://api.m.jd.com/client.action?functionId=` + newVar.fn
let {status, data} = await $.request(url, headers, newVar.sign);
return data;
}