mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 13:17:32 +00:00
fix: 尝试兼容过🐎插件的event
This commit is contained in:
parent
c6b5f7ab44
commit
069250f0ee
2 changed files with 20 additions and 2 deletions
|
|
@ -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, {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue