👀👀👀👀

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() { async toBindDevice() {
const uid = await this.getUID(); const ltuid = await this.getLtuid();
if (!uid) { if (!ltuid) {
this.reply('未绑定UID'); this.reply('未绑定UID');
this.finish('toBindDevice'); this.finish('toBindDevice');
return false; return false;
@ -66,14 +66,14 @@ export class Panel extends ZZZPlugin {
this.reply('设备信息格式错误', false, { at: true, recallMsg: 100 }); this.reply('设备信息格式错误', false, { at: true, recallMsg: 100 });
return false; return false;
} }
await redis.del(`ZZZ:DEVICE_FP:${uid}:FP`); await redis.del(`ZZZ:DEVICE_FP:${ltuid}:FP`);
await redis.set(`ZZZ:DEVICE_FP:${uid}:BIND`, JSON.stringify(info)); await redis.set(`ZZZ:DEVICE_FP:${ltuid}:BIND`, JSON.stringify(info));
const { deviceFp } = await this.getAPI(); const { deviceFp } = await this.getAPI();
if (!deviceFp) { if (!deviceFp) {
await this.reply('绑定设备失败'); await this.reply('绑定设备失败');
return false; return false;
} }
logger.debug(`[UID:${uid}]绑定设备成功deviceFp:${deviceFp}`); logger.debug(`[LTUID:${ltuid}]绑定设备成功deviceFp:${deviceFp}`);
await this.reply('绑定设备成功', false, { at: true, recallMsg: 100 }); await this.reply('绑定设备成功', false, { at: true, recallMsg: 100 });
} catch (error) { } catch (error) {
this.reply('设备信息格式错误', false, { at: true, recallMsg: 100 }); 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.host = 'https://api-takumi.mihoyo.com/';
this.hostRecord = 'https://api-takumi-record.mihoyo.com/'; this.hostRecord = 'https://api-takumi-record.mihoyo.com/';
this.hostPublicData = 'https://public-data-api.mihoyo.com/'; this.hostPublicData = 'https://public-data-api.mihoyo.com/';
this.hostBbs = 'https://bbs-api.miyoushe.com/';
} else { } else {
this.gameBiz = 'nap_global'; this.gameBiz = 'nap_global';
this.host = 'https://sg-public-api.hoyolab.com/'; this.host = 'https://sg-public-api.hoyolab.com/';
@ -104,6 +105,28 @@ export default class ZZZApiTool {
}, },
noDs: true, 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: { getFp: {

View file

@ -3,7 +3,7 @@ import { getCk } from './common.js';
import _ from 'lodash'; import _ from 'lodash';
import NoteUser from '../../genshin/model/mys/NoteUser.js'; import NoteUser from '../../genshin/model/mys/NoteUser.js';
import settings from '../lib/settings.js'; import settings from '../lib/settings.js';
import fetch from 'node-fetch'; import request from '../utils/request.js';
export class ZZZPlugin extends plugin { export class ZZZPlugin extends plugin {
/** /**
@ -37,6 +37,30 @@ export class ZZZPlugin extends plugin {
// 返回 UID // 返回 UID
return 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 * 获取米游社 API
* @returns {Promise<{api: MysZZZApi, uid: string, deviceFp: string}>} * @returns {Promise<{api: MysZZZApi, uid: string, deviceFp: string}>}
@ -55,11 +79,18 @@ export class ZZZPlugin extends plugin {
try { try {
// 创建米游社 API 对象 // 创建米游社 API 对象
const api = new MysZZZApi(uid, ck); 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) { if (!deviceFp) {
const sdk = api.getUrl('getFp'); const sdk = api.getUrl('getFp');
const res = await fetch(sdk.url, { const res = await request(sdk.url, {
headers: sdk.headers, headers: sdk.headers,
method: 'POST', method: 'POST',
body: sdk.body, body: sdk.body,
@ -67,10 +98,32 @@ export class ZZZPlugin extends plugin {
const fpRes = await res.json(); const fpRes = await res.json();
logger.debug(`[米游社][设备指纹]${JSON.stringify(fpRes)}`); logger.debug(`[米游社][设备指纹]${JSON.stringify(fpRes)}`);
deviceFp = fpRes?.data?.device_fp; deviceFp = fpRes?.data?.device_fp;
if (deviceFp) { if (!deviceFp) {
await redis.set(`ZZZ:DEVICE_FP:${uid}:FP`, deviceFp, { return { api: null, uid: null, deviceFp: null };
EX: 86400 * 7, }
}); 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、设备指纹 // 返回数据API、UID、设备指纹