add: Automatic sk acquisition

This commit is contained in:
会飞的蛋蛋面
2023-08-08 00:16:47 +08:00
parent 2330631531
commit e5ff17bf66
3 changed files with 41 additions and 1 deletions

1
.gitignore vendored
View File

@@ -55,6 +55,7 @@ typings/
.yarn-integrity .yarn-integrity
# dotenv environment variables file # dotenv environment variables file
.idea
.env .env
dist dist

View File

@@ -18,5 +18,8 @@
"homepage": "https://github.com/hex-ci/smzdm_script", "homepage": "https://github.com/hex-ci/smzdm_script",
"devDependencies": { "devDependencies": {
"eslint": "^8.36.0" "eslint": "^8.36.0"
},
"dependencies": {
"crypto-js": "^4.1.1"
} }
} }

View File

@@ -8,6 +8,7 @@ cron: 10 8 * * *
const Env = require('./env'); const Env = require('./env');
const { SmzdmBot, requestApi, removeTags, getEnvCookies, wait } = require('./bot'); const { SmzdmBot, requestApi, removeTags, getEnvCookies, wait } = require('./bot');
const notify = require('./sendNotify'); const notify = require('./sendNotify');
const CryptoJS = require("crypto-js");
// ------------------------------------ // ------------------------------------
@@ -193,6 +194,38 @@ class SmzdmCheckinBot extends SmzdmBot {
} }
} }
function random32() {
const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
let result = "";
for (let i = 0; i < 32; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
}
function getSk(cookie) {
const matchUserId = cookie.match(/smzdm_id=([^;]*)/);
if (!matchUserId) {
return ''
}
const userId = matchUserId[1];
const deviceId = getDeviceId(cookie);
const key = CryptoJS.enc.Utf8.parse('geZm53XAspb02exN');
const cipherText = CryptoJS.DES.encrypt(userId + deviceId, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return cipherText.toString();
}
function getDeviceId(cookie) {
const matchDeviceId = cookie.match(/device_id=([^;]*)/);
if (matchDeviceId) {
return matchDeviceId[1]
}
return random32()
}
!(async () => { !(async () => {
const cookies = getEnvCookies(); const cookies = getEnvCookies();
@@ -225,7 +258,10 @@ class SmzdmCheckinBot extends SmzdmBot {
continue; continue;
} }
const sk = sks[i]; let sk = sks[i];
if (!sk) {
sk = getSk(cookie)
}
if (i > 0) { if (i > 0) {
await wait(10, 30); await wait(10, 30);