mirror of
https://github.com/lan-tianxiang/clone_scripts.git
synced 2025-07-13 15:42:35 +08:00
更新于 09-03 12:01
This commit is contained in:
140
getJDCookie.js
140
getJDCookie.js
@ -6,14 +6,19 @@
|
||||
const jd_env = require("./utils/JDEnv.js");
|
||||
const $ = jd_env.env("扫码获取京东cookie");
|
||||
const qrcode = require("qrcode-terminal");
|
||||
const JD_UA = `jdapp;iPhone;10.1.2;14.7.1;${randomString(40)};network/wifi;model/iPhone10,2;addressid/4091160336;appBuild/167802;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1`;
|
||||
let s_token, cookies, guid, lsid, lstoken, okl_token, token;
|
||||
!(async () => {
|
||||
await loginEntrance();
|
||||
await generateQrcode();
|
||||
await getCookie();
|
||||
try {
|
||||
await loginEntrance();
|
||||
await generateQrcode();
|
||||
await getCookie();
|
||||
} catch (e) {
|
||||
$.logErr(e);
|
||||
}
|
||||
})()
|
||||
.catch((e) => {
|
||||
$.log("", `❌ ${$.name}, 失败! 原因: ${e}!`, "");
|
||||
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '');
|
||||
})
|
||||
.finally(() => {
|
||||
// $.done();
|
||||
@ -50,15 +55,15 @@
|
||||
} else {
|
||||
$.stepsHeaders = resp.headers;
|
||||
data = JSON.parse(data);
|
||||
token = data["token"];
|
||||
token = data['token'];
|
||||
// $.log('token', token)
|
||||
|
||||
const setCookie = resp.headers["set-cookie"][0];
|
||||
okl_token = setCookie.substring(setCookie.indexOf("=") + 1, setCookie.indexOf(";"));
|
||||
const url = "https://plogin.m.jd.com/cgi-bin/m/tmauth?appid=300&client_type=m&token=" + token;
|
||||
const setCookie = resp.headers['set-cookie'][0];
|
||||
okl_token = setCookie.substring(setCookie.indexOf('=') + 1, setCookie.indexOf(';'));
|
||||
const url = 'https://plogin.m.jd.com/cgi-bin/m/tmauth?appid=300&client_type=m&token=' + token;
|
||||
qrcode.generate(url, { small: true }); // 输出二维码
|
||||
console.log("请打开 京东APP 扫码登录(二维码有效期为3分钟)");
|
||||
console.log(`\n\n注:如扫描不到,请使用工具(例如在线二维码工具:https://cli.im)手动生成如下url二维码\n\n${url}\n\n`);
|
||||
console.log('请打开 京东APP 扫码登录(二维码有效期为3分钟)');
|
||||
console.error(`注:如上图二维码扫描不到,请使用工具(例如在线二维码工具:https://cli.im)手动生成下面链接的二维码\n\n${url}\n\n`);
|
||||
}
|
||||
} catch (e) {
|
||||
$.logErr(e, resp);
|
||||
@ -74,14 +79,14 @@
|
||||
const options = {
|
||||
url: `https://plogin.m.jd.com/cgi-bin/m/tmauthchecktoken?&token=${token}&ou_state=0&okl_token=${okl_token}`,
|
||||
body: `lang=chs&appid=300&source=wq_passport&returnurl=https://wqlogin2.jd.com/passport/LoginRedirect?state=${Date.now()}&returnurl=//home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action`,
|
||||
timeout: 10 * 1000,
|
||||
headers: {
|
||||
Referer: `https://plogin.m.jd.com/login/login?appid=300&returnurl=https://wqlogin2.jd.com/passport/LoginRedirect?state=${Date.now()}&returnurl=//home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action&source=wq_passport`,
|
||||
Cookie: cookies,
|
||||
Connection: "Keep-Alive",
|
||||
"Content-Type": "application/x-www-form-urlencoded; Charset=UTF-8",
|
||||
Accept: "application/json, text/plain, */*",
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 SP-engine/2.14.0 main%2F1.0 baiduboxapp/11.18.0.16 (Baidu; P2 13.3.1) NABar/0.0",
|
||||
Connection: 'Keep-Alive',
|
||||
'Content-Type': 'application/x-www-form-urlencoded; Charset=UTF-8',
|
||||
Accept: 'application/json, text/plain, */*',
|
||||
'User-Agent': JD_UA,
|
||||
},
|
||||
};
|
||||
$.post(options, (err, resp, data) => {
|
||||
@ -105,34 +110,38 @@
|
||||
|
||||
function getCookie() {
|
||||
$.timer = setInterval(async () => {
|
||||
const checkRes = await checkLogin();
|
||||
if (checkRes["errcode"] === 0) {
|
||||
//扫描登录成功
|
||||
$.log(`扫描登录成功\n`);
|
||||
clearInterval($.timer);
|
||||
await formatCookie($.checkLoginHeaders);
|
||||
$.done();
|
||||
} else if (checkRes["errcode"] === 21) {
|
||||
$.log(`二维码已失效,请重新获取二维码重新扫描\n`);
|
||||
clearInterval($.timer);
|
||||
$.done();
|
||||
} else if (checkRes["errcode"] === 176) {
|
||||
//未扫描登录
|
||||
} else {
|
||||
$.log(`其他异常:${JSON.stringify(checkRes)}\n`);
|
||||
clearInterval($.timer);
|
||||
$.done();
|
||||
try {
|
||||
const checkRes = await checkLogin();
|
||||
if (checkRes['errcode'] === 0) {
|
||||
//扫描登录成功
|
||||
$.log(`扫描登录成功\n`);
|
||||
clearInterval($.timer);
|
||||
await formatCookie($.checkLoginHeaders);
|
||||
$.done();
|
||||
} else if (checkRes['errcode'] === 21) {
|
||||
$.log(`二维码已失效,请重新获取二维码重新扫描\n`);
|
||||
clearInterval($.timer);
|
||||
$.done();
|
||||
} else if (checkRes['errcode'] === 176) {
|
||||
//未扫描登录
|
||||
} else {
|
||||
$.log(`扫描登录失败:其他未知状态异常:${JSON.stringify(checkRes)}\n`);
|
||||
clearInterval($.timer);
|
||||
$.done();
|
||||
}
|
||||
} catch (e) {
|
||||
$.logErr(e);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function formatCookie(headers) {
|
||||
new Promise((resolve) => {
|
||||
let pt_key = headers["set-cookie"][1];
|
||||
pt_key = pt_key.substring(pt_key.indexOf("=") + 1, pt_key.indexOf(";"));
|
||||
let pt_pin = headers["set-cookie"][2];
|
||||
pt_pin = pt_pin.substring(pt_pin.indexOf("=") + 1, pt_pin.indexOf(";"));
|
||||
const cookie1 = "pt_key=" + pt_key + ";pt_pin=" + pt_pin + ";";
|
||||
let pt_key = headers['set-cookie'][1];
|
||||
pt_key = pt_key.substring(pt_key.indexOf('=') + 1, pt_key.indexOf(';'));
|
||||
let pt_pin = headers['set-cookie'][2];
|
||||
pt_pin = pt_pin.substring(pt_pin.indexOf('=') + 1, pt_pin.indexOf(';'));
|
||||
const cookie1 = 'pt_key=' + pt_key + ';pt_pin=' + pt_pin + ';';
|
||||
|
||||
$.UserName = decodeURIComponent(cookie1.match(/pt_pin=([^; ]+)(?=;?)/) && cookie1.match(/pt_pin=([^; ]+)(?=;?)/)[1]);
|
||||
$.log(`京东用户:${$.UserName} Cookie获取成功,cookie如下:`);
|
||||
@ -143,14 +152,14 @@
|
||||
|
||||
function formatSetCookies(headers, body) {
|
||||
new Promise((resolve) => {
|
||||
s_token = body["s_token"];
|
||||
guid = headers["set-cookie"][0];
|
||||
guid = guid.substring(guid.indexOf("=") + 1, guid.indexOf(";"));
|
||||
lsid = headers["set-cookie"][2];
|
||||
lsid = lsid.substring(lsid.indexOf("=") + 1, lsid.indexOf(";"));
|
||||
lstoken = headers["set-cookie"][3];
|
||||
lstoken = lstoken.substring(lstoken.indexOf("=") + 1, lstoken.indexOf(";"));
|
||||
cookies = "guid=" + guid + "; lang=chs; lsid=" + lsid + "; lstoken=" + lstoken + "; ";
|
||||
s_token = body['s_token'];
|
||||
guid = headers['set-cookie'][0];
|
||||
guid = guid.substring(guid.indexOf('=') + 1, guid.indexOf(';'));
|
||||
lsid = headers['set-cookie'][2];
|
||||
lsid = lsid.substring(lsid.indexOf('=') + 1, lsid.indexOf(';'));
|
||||
lstoken = headers['set-cookie'][3];
|
||||
lstoken = lstoken.substring(lstoken.indexOf('=') + 1, lstoken.indexOf(';'));
|
||||
cookies = 'guid=' + guid + '; lang=chs; lsid=' + lsid + '; lstoken=' + lstoken + '; ';
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
@ -158,15 +167,15 @@
|
||||
function taskUrl() {
|
||||
return {
|
||||
url: `https://plogin.m.jd.com/cgi-bin/mm/new_login_entrance?lang=chs&appid=300&returnurl=https://wq.jd.com/passport/LoginRedirect?state=${Date.now()}&returnurl=https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action&source=wq_passport`,
|
||||
timeout: 10 * 1000,
|
||||
headers: {
|
||||
Connection: "Keep-Alive",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
Accept: "application/json, text/plain, */*",
|
||||
"Accept-Language": "zh-cn",
|
||||
Connection: 'Keep-Alive',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
Accept: 'application/json, text/plain, */*',
|
||||
'Accept-Language': 'zh-cn',
|
||||
Referer: `https://plogin.m.jd.com/login/login?appid=300&returnurl=https://wq.jd.com/passport/LoginRedirect?state=${Date.now()}&returnurl=https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action&source=wq_passport`,
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 SP-engine/2.14.0 main%2F1.0 baiduboxapp/11.18.0.16 (Baidu; P2 13.3.1) NABar/0.0",
|
||||
Host: "plogin.m.jd.com",
|
||||
'User-Agent': JD_UA,
|
||||
Host: 'plogin.m.jd.com',
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -175,16 +184,27 @@
|
||||
return {
|
||||
url: `https://plogin.m.jd.com/cgi-bin/m/tmauthreflogurl?s_token=${s_token}&v=${Date.now()}&remember=true`,
|
||||
body: `lang=chs&appid=300&source=wq_passport&returnurl=https://wqlogin2.jd.com/passport/LoginRedirect?state=${Date.now()}&returnurl=//home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action`,
|
||||
timeout: 10 * 1000,
|
||||
headers: {
|
||||
Connection: "Keep-Alive",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
Accept: "application/json, text/plain, */*",
|
||||
"Accept-Language": "zh-cn",
|
||||
Connection: 'Keep-Alive',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
Accept: 'application/json, text/plain, */*',
|
||||
'Accept-Language': 'zh-cn',
|
||||
Referer: `https://plogin.m.jd.com/login/login?appid=300&returnurl=https://wq.jd.com/passport/LoginRedirect?state=${Date.now()}&returnurl=https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action&source=wq_passport`,
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 SP-engine/2.14.0 main%2F1.0 baiduboxapp/11.18.0.16 (Baidu; P2 13.3.1) NABar/0.0",
|
||||
Host: "plogin.m.jd.com",
|
||||
'User-Agent': JD_UA,
|
||||
Host: 'plogin.m.jd.com',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成随机 iPhoneID
|
||||
* @returns {string}
|
||||
*/
|
||||
function randomString(e) {
|
||||
e = e || 32;
|
||||
let t = "abcdef0123456789", a = t.length, n = "";
|
||||
for (i = 0; i < e; i++)
|
||||
n += t.charAt(Math.floor(Math.random() * a));
|
||||
return n
|
||||
}
|
Reference in New Issue
Block a user