👀👀👀👀

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

@ -33,8 +33,8 @@ export class Panel extends ZZZPlugin {
);
}
async toBindDevice() {
const uid = await this.getUID();
if (!uid) {
const ltuid = await this.getLtuid();
if (!ltuid) {
this.reply('未绑定UID');
this.finish('toBindDevice');
return false;
@ -66,14 +66,14 @@ export class Panel extends ZZZPlugin {
this.reply('设备信息格式错误', false, { at: true, recallMsg: 100 });
return false;
}
await redis.del(`ZZZ:DEVICE_FP:${uid}:FP`);
await redis.set(`ZZZ:DEVICE_FP:${uid}:BIND`, JSON.stringify(info));
await redis.del(`ZZZ:DEVICE_FP:${ltuid}:FP`);
await redis.set(`ZZZ:DEVICE_FP:${ltuid}:BIND`, JSON.stringify(info));
const { deviceFp } = await this.getAPI();
if (!deviceFp) {
await this.reply('绑定设备失败');
return false;
}
logger.debug(`[UID:${uid}]绑定设备成功deviceFp:${deviceFp}`);
logger.debug(`[LTUID:${ltuid}]绑定设备成功deviceFp:${deviceFp}`);
await this.reply('绑定设备成功', false, { at: true, recallMsg: 100 });
} catch (error) {
this.reply('设备信息格式错误', false, { at: true, recallMsg: 100 });

View file

@ -20,6 +20,7 @@ export default class ZZZApiTool {
this.host = 'https://api-takumi.mihoyo.com/';
this.hostRecord = 'https://api-takumi-record.mihoyo.com/';
this.hostPublicData = 'https://public-data-api.mihoyo.com/';
this.hostBbs = 'https://bbs-api.miyoushe.com/';
} else {
this.gameBiz = 'nap_global';
this.host = 'https://sg-public-api.hoyolab.com/';
@ -104,6 +105,28 @@ export default class ZZZApiTool {
},
noDs: true,
},
deviceLogin: {
url: `${this.hostBbs}apihub/api/deviceLogin`,
body: {
app_version: '2.73.1',
device_id: data.deviceId,
device_name: `${deviceBrand}${modelName}`,
os_version: '33',
platform: 'Android',
registration_id: generateSeed(19),
},
},
saveDevice: {
url: `${this.hostBbs}apihub/api/saveDevice`,
body: {
app_version: '2.73.1',
device_id: data.deviceId,
device_name: `${deviceBrand}${modelName}`,
os_version: '33',
platform: 'Android',
registration_id: generateSeed(19),
},
},
}
: {
getFp: {

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, {
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、设备指纹