-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathjd_gold_sign.js
170 lines (163 loc) · 5.99 KB
/
jd_gold_sign.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
京东金榜
活动入口:https://h5.m.jd.com/babelDiy/Zeus/2H5Ng86mUJLXToEo57qWkJkjFPxw/index.html
脚本更新时间:2022-1-5
脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js
新手写脚本,难免有bug,能用且用。
===================quantumultx================
[task_local]
#京东金榜
13 7 * * * jd_gold_sign.js, tag=京东金榜, img-url=https://raw.githubusercontent.com/Orz-3/mini/master/Color/jd.png, enabled=true
*/
const jd_helpers = require('./utils/JDHelpers.js');
const jd_env = require('./utils/JDEnv.js');
const $ = jd_env.env('京东抽奖机&京东金榜');
const notify = $.isNode() ? require('./sendNotify') : '';
//Node.js用户请在jdCookie.js处填写京东ck;
const jdCookieNode = $.isNode() ? require('./jdCookie.js') : '';
//IOS等用户直接用NobyDa的jd cookie
let cookiesArr = [],
cookie = '',
message;
if ($.isNode()) {
Object.keys(jdCookieNode).forEach((item) => {
cookiesArr.push(jdCookieNode[item]);
});
if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => {};
if (JSON.stringify(process.env).indexOf('GITHUB') > -1) process.exit(0);
} else {
cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...$.toObj($.getdata('CookiesJD') || '[]').map((item) => item.cookie)].filter((item) => !!item);
}
const JD_API_HOST = 'https://api.m.jd.com/client.action';
!(async () => {
if (!cookiesArr[0]) {
$.msg($.name, '【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取', 'https://bean.m.jd.com/', { 'open-url': 'https://bean.m.jd.com/' });
return;
}
for (let i = 0; i < cookiesArr.length; i++) {
if (cookiesArr[i]) {
$.cookie = cookie = cookiesArr[i];
$.UserName = decodeURIComponent(cookie.match(/pt_pin=(.+?);/) && cookie.match(/pt_pin=(.+?);/)[1]);
$.index = i + 1;
$.isLogin = true;
$.beans = 0;
$.nickName = '';
message = '';
$.UUID = getUUID('xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx');
await $.totalBean();
console.log(`\n******开始【京东账号${$.index}】${$.nickName || $.UserName}*********\n`);
if (!$.isLogin) {
$.msg($.name, `【提示】cookie已失效`, `京东账号${$.index} ${$.nickName || $.UserName}\n请重新登录获取\nhttps://bean.m.jd.com/`, { 'open-url': 'https://bean.m.jd.com/' });
if ($.isNode()) {
await notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账号${$.index} ${$.UserName}\n请重新登录获取cookie`);
} else {
$.setdata('', `CookieJD${i ? i + 1 : ''}`); //cookie失效,故清空cookie。$.setdata('', `CookieJD${i ? i + 1 : "" }`);//cookie失效,故清空cookie。
}
continue;
}
await goldCreatorDoTask({ type: 1 });
await goldCenterHead();
}
}
})()
.catch((e) => {
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '');
})
.finally(() => {
$.done();
});
function goldCenterHead() {
return new Promise((resolve) => {
const options = taskUrl('goldCenterHead', '{}');
// console.log(options);
$.get(options, async (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`);
console.log(`goldCenterDoTask API请求失败,请检查网路重试`);
} else {
if (jd_helpers.safeGet(data)) {
data = JSON.parse(data);
if (data.code === '0') {
if (data.result.medalNum === 5) {
await $.wait(1500);
await goldCreatorDoTask({ type: 2 });
}
} else {
console.log(`失败:${JSON.stringify(data)}\n`);
}
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
});
});
}
function goldCreatorDoTask(body) {
return new Promise((resolve) => {
const options = taskUrl('goldCenterDoTask', body);
$.get(options, async (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`);
console.log(`goldCenterDoTask API请求失败,请检查网路重试`);
} else {
if (jd_helpers.safeGet(data)) {
data = JSON.parse(data);
if (data.code === '0') {
if (data.result.taskCode === '0') {
console.log(`成功,获得 ${data.result.lotteryScore}京豆\n`);
if (data.result.lotteryScore) $.beans += parseInt(data.result.lotteryScore);
} else {
console.log(`失败:${data.result['taskMsg']}\n`);
}
} else {
console.log(`失败:${JSON.stringify(data)}\n`);
}
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve();
}
});
});
}
function taskUrl(function_id, body = {}) {
return {
url: `${JD_API_HOST}?functionId=${function_id}&body=${escape(JSON.stringify(body))}&appid=content_ecology&clientVersion=10.2.4&client=wh5&eufv=false&uuid=${$.UUID}`,
headers: {
Accept: '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-cn',
Connection: 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded',
Host: 'api.m.jd.com',
Referer: 'https://h5.m.jd.com/',
Cookie: cookie,
'User-Agent': $.isNode()
? process.env.JD_USER_AGENT
? process.env.JD_USER_AGENT
: require('./USER_AGENTS').USER_AGENT
: $.getdata('JDUA')
? $.getdata('JDUA')
: 'jdapp;iPhone;9.4.4;14.3;network/4g;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1',
},
};
}
function getUUID(format = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', UpperCase = 0) {
return format.replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8;
if (UpperCase) {
uuid = v.toString(36).toUpperCase();
} else {
uuid = v.toString(36);
}
return uuid;
});
}