From 069250f0ee7b9ea4e41312591e3b65b8b3a9ea30 Mon Sep 17 00:00:00 2001 From: bietiaop <1527109126@qq.com> Date: Fri, 23 Aug 2024 13:12:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=9D=E8=AF=95=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E8=BF=87=F0=9F=90=8E=E6=8F=92=E4=BB=B6=E7=9A=84event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mysapi.js | 20 ++++++++++++++++++-- lib/plugin.js | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/mysapi.js b/lib/mysapi.js index 932ccea..3b916f6 100644 --- a/lib/mysapi.js +++ b/lib/mysapi.js @@ -17,9 +17,15 @@ export default class MysZZZApi extends MysApi { super(uid, cookie, option, true); // 初始化 uid、server、apiTool this.uid = uid; + // 获取玩家的服务器 this.server = this.getServer(uid); + // 初始化 apiTool this.apiTool = new ZZZApiTool(uid, this.server); + // 绑定过🐎插件 (如果存在) this.handler = option?.handler || {}; + // 绑定yunzai event (如果存在) + this.e = option?.e || {}; + // 获取 cookie 和设备 ID if (typeof this.cookie !== 'string' && this.cookie) { const ck = Object.values(this.cookie).find(item => { return item.ck && item.uid === uid; @@ -30,6 +36,7 @@ export default class MysZZZApi extends MysApi { this._device = ck?.device_id || ck?.device; this.cookie = ck?.ck; } + // 如果没有设备ID,生成设备ID if (!this._device) { this._device = crypto.randomUUID(); } @@ -40,7 +47,9 @@ export default class MysZZZApi extends MysApi { * @returns {string} */ getServer() { + // 获取 UID const _uid = this.uid?.toString(); + // 如果 UID 长度小于 10,说明是官服 if (_uid.length < 10) { return 'prod_gf_cn'; // 官服 } @@ -80,6 +89,7 @@ export default class MysZZZApi extends MysApi { if (query) url += `?${query}`; // 如果传入了 query 参数,将 query 参数拼接到 url 上 if (data.query) { + // 拼接 query let str = ''; for (let key in data.query) { if (data.query[key] === undefined) continue; @@ -90,7 +100,9 @@ export default class MysZZZApi extends MysApi { }); } else str += `${key}=${data.query[key]}&`; } + // 去除最后一个 & str = str.slice(0, -1); + // 拼接到 url 上 if (url.includes('?')) { url += `&${str}`; } else { @@ -101,6 +113,7 @@ export default class MysZZZApi extends MysApi { if (body) body = JSON.stringify(body); // 获取请求头 let headers = this.getHeaders(query, body); + // 如果有设备指纹,写入设备指纹 if (data.deviceFp) { headers['x-rpc-device_fp'] = data.deviceFp; // 兼容喵崽 @@ -108,13 +121,15 @@ export default class MysZZZApi extends MysApi { } // 写入 cookie headers.cookie = this.cookie; - // 写入设备ID + // 写入设备ID(默认继承的) if (this._device) { headers['x-rpc-device_id'] = this._device; } + // 如果有设备ID,写入设备ID(传入的,这里是绑定设备方法1中的设备ID) if (data.deviceId) { headers['x-rpc-device_id'] = data.deviceId; } + // 如果有设备信息,写入设备信息 if (data?.deviceInfo && data?.modelName) { const deviceBrand = data.deviceInfo?.split('/')[0]; try { @@ -133,6 +148,7 @@ export default class MysZZZApi extends MysApi { } default: } + // 如果是获取 AuthKey,写入额外参数 if (type === 'zzzAuthKey') { let extra = { DS: this.getDS2(), @@ -251,7 +267,7 @@ export default class MysZZZApi extends MysApi { // 如果有注册的mys.req.err,调用 if (!!this?.handler && this?.handler?.has('mys.req.err')) { logger.mark( - `[米游社绝区零查询失败][UID:${this.uid}][qq:${this.userId}] 遇到验证码,尝试调用 Handler mys.req.err` + `[米游社绝区零查询失败][UID:${this.uid}][qq:${this?.e?.userId}] 遇到验证码,尝试调用 Handler mys.req.err` ); res = (await this.handler.call('mys.req.err', this.e, { diff --git a/lib/plugin.js b/lib/plugin.js index 8d10061..a73db25 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -64,6 +64,7 @@ export class ZZZPlugin extends plugin { * @returns {Promise<{api: MysZZZApi, uid: string, deviceFp: string}>} */ async getAPI() { + this.e.game = 'zzz'; // 直接调用获取 UID const uid = await this.getUID(); // 获取用户的 cookie @@ -77,6 +78,7 @@ export class ZZZPlugin extends plugin { // 创建米游社 API 对象 const api = new MysZZZApi(uid, ck, { handler: this.e?.runtime?.handler || {}, + e: this.e, }); const currentCK = Object.values(ck).find(item => { return item.ck && item.uid === uid;