Skip to content

Commit e5ff17b

Browse files
committed
add: Automatic sk acquisition
1 parent 2330631 commit e5ff17b

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ typings/
5555
.yarn-integrity
5656

5757
# dotenv environment variables file
58+
.idea
5859
.env
5960

6061
dist

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
"homepage": "https://github.com/hex-ci/smzdm_script",
1919
"devDependencies": {
2020
"eslint": "^8.36.0"
21+
},
22+
"dependencies": {
23+
"crypto-js": "^4.1.1"
2124
}
2225
}

smzdm_checkin.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cron: 10 8 * * *
88
const Env = require('./env');
99
const { SmzdmBot, requestApi, removeTags, getEnvCookies, wait } = require('./bot');
1010
const notify = require('./sendNotify');
11+
const CryptoJS = require("crypto-js");
1112

1213
// ------------------------------------
1314

@@ -193,6 +194,38 @@ class SmzdmCheckinBot extends SmzdmBot {
193194
}
194195
}
195196

197+
function random32() {
198+
const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
199+
let result = "";
200+
for (let i = 0; i < 32; i++) {
201+
result += chars.charAt(Math.floor(Math.random() * chars.length));
202+
}
203+
return result;
204+
}
205+
206+
function getSk(cookie) {
207+
const matchUserId = cookie.match(/smzdm_id=([^;]*)/);
208+
if (!matchUserId) {
209+
return ''
210+
}
211+
const userId = matchUserId[1];
212+
const deviceId = getDeviceId(cookie);
213+
const key = CryptoJS.enc.Utf8.parse('geZm53XAspb02exN');
214+
const cipherText = CryptoJS.DES.encrypt(userId + deviceId, key, {
215+
mode: CryptoJS.mode.ECB,
216+
padding: CryptoJS.pad.Pkcs7
217+
});
218+
return cipherText.toString();
219+
}
220+
221+
function getDeviceId(cookie) {
222+
const matchDeviceId = cookie.match(/device_id=([^;]*)/);
223+
if (matchDeviceId) {
224+
return matchDeviceId[1]
225+
}
226+
return random32()
227+
}
228+
196229
!(async () => {
197230
const cookies = getEnvCookies();
198231

@@ -225,7 +258,10 @@ class SmzdmCheckinBot extends SmzdmBot {
225258
continue;
226259
}
227260

228-
const sk = sks[i];
261+
let sk = sks[i];
262+
if (!sk) {
263+
sk = getSk(cookie)
264+
}
229265

230266
if (i > 0) {
231267
await wait(10, 30);

0 commit comments

Comments
 (0)