👀👀👀👀

This commit is contained in:
bietiaop 2024-08-16 21:09:42 +08:00
parent 8e3ee9188e
commit 6eaf8c0e90
3 changed files with 88 additions and 12 deletions

View file

@ -3,7 +3,7 @@ import { getCk } from './common.js';
import _ from 'lodash';
import NoteUser from '../../genshin/model/mys/NoteUser.js';
import settings from '../lib/settings.js';
import fetch from 'node-fetch';
import request from '../utils/request.js';
export class ZZZPlugin extends plugin {
/**
@ -37,6 +37,30 @@ export class ZZZPlugin extends plugin {
// 返回 UID
return uid;
}
/**
* 获取用户 ltuid
* @returns {Promise<string | boolean>}
* @memberof ZZZPlugin
* @description 获取用户 ltuid
* @example
* const ltuid = await this.getLtuid();
* if (!ltuid) return false;
* @returns {Promise<string | boolean>}
*/
async getLtuid() {
const uid = await this.getUID();
if (!uid) return false;
const ck = await getCk(this.e);
if (!ck || Object.keys(ck).filter(k => ck[k].ck).length === 0) {
await this.reply('尚未绑定cookie请先绑定cookie或者#扫码登录');
return false;
}
const currentCK = Object.values(ck).find(item => {
return item.ck && item.uid === uid;
});
return currentCK?.ltuid || '';
}
/**
* 获取米游社 API
* @returns {Promise<{api: MysZZZApi, uid: string, deviceFp: string}>}
@ -55,11 +79,18 @@ export class ZZZPlugin extends plugin {
try {
// 创建米游社 API 对象
const api = new MysZZZApi(uid, ck);
const currentCK = Object.values(ck).find(item => {
return item.ck && item.uid === uid;
});
const ltuid = currentCK?.ltuid || '';
if (!ltuid) {
return { api: null, uid: null, deviceFp: null };
}
// 获取设备指纹
let deviceFp = await redis.get(`ZZZ:DEVICE_FP:${uid}:FP`);
let deviceFp = await redis.get(`ZZZ:DEVICE_FP:${ltuid}:FP`);
if (!deviceFp) {
const sdk = api.getUrl('getFp');
const res = await fetch(sdk.url, {
const res = await request(sdk.url, {
headers: sdk.headers,
method: 'POST',
body: sdk.body,
@ -67,10 +98,32 @@ export class ZZZPlugin extends plugin {
const fpRes = await res.json();
logger.debug(`[米游社][设备指纹]${JSON.stringify(fpRes)}`);
deviceFp = fpRes?.data?.device_fp;
if (deviceFp) {
await redis.set(`ZZZ:DEVICE_FP:${uid}:FP`, deviceFp, {
EX: 86400 * 7,
});
if (!deviceFp) {
return { api: null, uid: null, deviceFp: null };
}
await redis.set(`ZZZ:DEVICE_FP:${ltuid}:FP`, deviceFp, {
EX: 86400 * 7,
});
const deviceLogin = api.getUrl('deviceLogin');
const saveDevice = api.getUrl('saveDevice');
if (!!deviceLogin && !!saveDevice) {
logger.debug(`[米游社][设备登录]保存设备信息`);
try {
const login = await request(deviceLogin.url, {
headers: deviceLogin.headers,
method: 'POST',
body: deviceLogin.body,
});
const save = await request(saveDevice.url, {
headers: saveDevice.headers,
method: 'POST',
body: saveDevice.body,
});
const result = await Promise.all([login.json(), save.json()]);
logger.debug(`[米游社][设备登录]${JSON.stringify(result)}`);
} catch (error) {
logger.error(`[米游社][设备登录]${error.message}`);
}
}
}
// 返回数据API、UID、设备指纹