mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 13:17:32 +00:00
👀👀👀👀
This commit is contained in:
parent
8e3ee9188e
commit
6eaf8c0e90
3 changed files with 88 additions and 12 deletions
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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、设备指纹)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue