|
|
@@ -36,34 +36,7 @@ async function Main() {
|
|
|
magicJS.logger.info(!!$response);
|
|
|
magicJS.logger.info(`isRequest=${magicJS.isRequest}`);
|
|
|
if (magicJS.isRequest) {
|
|
|
- if(getCookieRegex.test(magicJS.request.url)){
|
|
|
- const cookie = magicJS.request.headers.Cookie;
|
|
|
- const body = magicJS.request.url.split('?')[1];
|
|
|
- // 获取UserId
|
|
|
- const userId = await magicJS.utils.retry(getUserId, 3, 500)(cookie).catch(err => {
|
|
|
- magicJS.notification.post(err);
|
|
|
- magicJS.done();
|
|
|
- })
|
|
|
- let hisCookie = magicJS.data.read(dingDongCookieKey, "", userId);
|
|
|
- if (cookie !== hisCookie) {
|
|
|
- magicJS.data.write(dingDongCookieKey, cookie, userId);
|
|
|
- magicJS.data.write(dingDongBodyKey, body, userId);
|
|
|
- magicJS.logger.info(`旧的Cookie:${hisCookie}\n新的Cookie:${cookie}\nCookie不同,写入新的Cookie成功!`);
|
|
|
- magicJS.notification.post("🎈Cookie写入成功!!");
|
|
|
- } else {
|
|
|
- magicJS.logger.info("Cookie没有变化,无需更新");
|
|
|
- }
|
|
|
- // 同步Cookies至青龙面板
|
|
|
- if (magicJS.data.read(dingDongSyncQinglongKey, false) === true) {
|
|
|
- hisCookie = await magicJS.qinglong.read(dingDongCookieKey, "", userId);
|
|
|
- if (cookie !== hisCookie) {
|
|
|
- await magicJS.qinglong.write(dingDongCookieKey, cookie, userId);
|
|
|
- await magicJS.qinglong.write(dingDongBodyKey, body, userId);
|
|
|
- magicJS.logger.info(`旧的Cookie:${hisCookie}\n新的Cookie:${cookie}\nCookie不同,写入新的Cookie成功!`);
|
|
|
- magicJS.notification.post("🎈Cookie同步到青龙面板成功!!");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ handleRequest();
|
|
|
} else {
|
|
|
const allSessions = magicJS.data.allSessionNames(dingDongCookieKey);
|
|
|
if (!allSessions || allSessions.length <= 0) {
|
|
|
@@ -88,6 +61,40 @@ async function Main() {
|
|
|
magicJS.done();
|
|
|
}
|
|
|
|
|
|
+function handleRequest(){
|
|
|
+ const request = magicJS.request;
|
|
|
+ const url = request.url;
|
|
|
+ const path = request.path;
|
|
|
+ // if(getCookieRegex.test(request.url)){
|
|
|
+ // const cookie = request.headers.Cookie;
|
|
|
+ // const body = request.url.split('?')[1];
|
|
|
+ // // 获取UserId
|
|
|
+ // const userId = await magicJS.utils.retry(getUserId, 3, 500)(cookie).catch(err => {
|
|
|
+ // magicJS.notification.post(err);
|
|
|
+ // magicJS.done();
|
|
|
+ // });
|
|
|
+ // let hisCookie = magicJS.data.read(dingDongCookieKey, "", userId);
|
|
|
+ // if (cookie !== hisCookie) {
|
|
|
+ // magicJS.data.write(dingDongCookieKey, cookie, userId);
|
|
|
+ // magicJS.data.write(dingDongBodyKey, body, userId);
|
|
|
+ // magicJS.logger.info(`旧的Cookie:${hisCookie}\n新的Cookie:${cookie}\nCookie不同,写入新的Cookie成功!`);
|
|
|
+ // magicJS.notification.post("🎈Cookie写入成功!!");
|
|
|
+ // } else {
|
|
|
+ // magicJS.logger.info("Cookie没有变化,无需更新");
|
|
|
+ // }
|
|
|
+ // // 同步Cookies至青龙面板
|
|
|
+ // if (magicJS.data.read(dingDongSyncQinglongKey, false) === true) {
|
|
|
+ // hisCookie = await magicJS.qinglong.read(dingDongCookieKey, "", userId);
|
|
|
+ // if (cookie !== hisCookie) {
|
|
|
+ // await magicJS.qinglong.write(dingDongCookieKey, cookie, userId);
|
|
|
+ // await magicJS.qinglong.write(dingDongBodyKey, body, userId);
|
|
|
+ // magicJS.logger.info(`旧的Cookie:${hisCookie}\n新的Cookie:${cookie}\nCookie不同,写入新的Cookie成功!`);
|
|
|
+ // magicJS.notification.post("🎈Cookie同步到青龙面板成功!!");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+}
|
|
|
+
|
|
|
function getUserId(cookie) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
magicJS.http.get({
|
|
|
@@ -96,12 +103,13 @@ function getUserId(cookie) {
|
|
|
"Referer": "https://activity.m.ddxq.mobi/",
|
|
|
"Host": "maicai.api.ddxq.mobi",
|
|
|
"Origin": "https://activity.m.ddxq.mobi",
|
|
|
- "Cookie": cookie
|
|
|
+ "Cookie": cookie,
|
|
|
+ "User-Agent": userAgent,
|
|
|
}
|
|
|
}).then(resp => {
|
|
|
const obj = resp.body;
|
|
|
if (obj.code === 0) {
|
|
|
- magicJS.logger.info(`当前登录用户的UserId:${obj.data.id}`);
|
|
|
+ magicJS.logger.info(`当前登录用户Id:${obj.data.id},手机号:${obj.mobile}`);
|
|
|
resolve(obj.data.id);
|
|
|
} else {
|
|
|
const msg = `获取UserId失败\n${JSON.stringify(resp)}`;
|