mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 21:27:47 +00:00
fix: 部分逻辑
This commit is contained in:
parent
34cd8b15dc
commit
70836ab785
9 changed files with 204 additions and 173 deletions
187
lib/plugin.js
187
lib/plugin.js
|
|
@ -32,7 +32,7 @@ export class ZZZPlugin extends plugin {
|
|||
await this.reply(
|
||||
'uid为空,需要CK的功能请先绑定CK或者#扫码登录,需要SK的功能请#扫码登录,若不清楚需要CK或SK,请查看%帮助'
|
||||
);
|
||||
return false;
|
||||
throw new Error('UID为空');
|
||||
}
|
||||
// 返回 UID
|
||||
return uid;
|
||||
|
|
@ -43,18 +43,14 @@ export class ZZZPlugin extends plugin {
|
|||
* @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;
|
||||
throw new Error('CK为空');
|
||||
}
|
||||
const currentCK = Object.values(ck).find(item => {
|
||||
return item.ck && item.uid === uid;
|
||||
|
|
@ -68,109 +64,105 @@ export class ZZZPlugin extends plugin {
|
|||
async getAPI() {
|
||||
// 直接调用获取 UID
|
||||
const uid = await this.getUID();
|
||||
if (!uid) return { api: null, uid: null, deviceFp: null };
|
||||
// 获取用户的 cookie
|
||||
const ck = await getCk(this.e);
|
||||
// 如果 cookie 不存在或者 cookie 为空,说明没有绑定 cookie
|
||||
if (!ck || Object.keys(ck).filter(k => ck[k].ck).length === 0) {
|
||||
await this.reply('尚未绑定cookie,请先绑定cookie,或者#扫码登录');
|
||||
return { api: null, uid: null, deviceFp: null };
|
||||
throw new Error('CK为空');
|
||||
}
|
||||
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
|
||||
let bindInfo = await redis.get(`ZZZ:DEVICE_FP:${ltuid}:BIND`);
|
||||
if (bindInfo) {
|
||||
deviceFp = await redis.get(`ZZZ:DEVICE_FP:${ltuid}:FP`);
|
||||
let data = {
|
||||
deviceFp,
|
||||
|
||||
// 创建米游社 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) {
|
||||
this.reply('ltuid为空,请重新绑定CK');
|
||||
throw new Error('ltuid为空');
|
||||
}
|
||||
// 获取设备指纹
|
||||
let deviceFp;
|
||||
let bindInfo = await redis.get(`ZZZ:DEVICE_FP:${ltuid}:BIND`);
|
||||
if (bindInfo) {
|
||||
deviceFp = await redis.get(`ZZZ:DEVICE_FP:${ltuid}:FP`);
|
||||
let data = {
|
||||
deviceFp,
|
||||
};
|
||||
try {
|
||||
bindInfo = JSON.parse(bindInfo);
|
||||
data = {
|
||||
productName: bindInfo?.deviceProduct,
|
||||
deviceType: bindInfo?.deviceName,
|
||||
modelName: bindInfo?.deviceModel,
|
||||
oaid: bindInfo?.oaid,
|
||||
deviceInfo: bindInfo?.deviceFingerprint,
|
||||
board: bindInfo?.deviceBoard,
|
||||
};
|
||||
try {
|
||||
bindInfo = JSON.parse(bindInfo);
|
||||
data = {
|
||||
productName: bindInfo?.deviceProduct,
|
||||
deviceType: bindInfo?.deviceName,
|
||||
modelName: bindInfo?.deviceModel,
|
||||
oaid: bindInfo?.oaid,
|
||||
deviceInfo: bindInfo?.deviceFingerprint,
|
||||
board: bindInfo?.deviceBoard,
|
||||
};
|
||||
} catch (error) {
|
||||
bindInfo = null;
|
||||
}
|
||||
} catch (error) {
|
||||
bindInfo = null;
|
||||
}
|
||||
if (!deviceFp) {
|
||||
const sdk = api.getUrl('getFp', data);
|
||||
const res = await request(sdk.url, {
|
||||
headers: sdk.headers,
|
||||
method: 'POST',
|
||||
body: sdk.body,
|
||||
});
|
||||
const fpRes = await res.json();
|
||||
logger.debug(`[米游社][设备指纹]${JSON.stringify(fpRes)}`);
|
||||
deviceFp = fpRes?.data?.device_fp;
|
||||
if (!deviceFp) {
|
||||
const sdk = api.getUrl('getFp', data);
|
||||
const res = await request(sdk.url, {
|
||||
headers: sdk.headers,
|
||||
method: 'POST',
|
||||
body: sdk.body,
|
||||
});
|
||||
const fpRes = await res.json();
|
||||
logger.debug(`[米游社][设备指纹]${JSON.stringify(fpRes)}`);
|
||||
deviceFp = fpRes?.data?.device_fp;
|
||||
if (!deviceFp) {
|
||||
return { api: null, uid: null, deviceFp: null };
|
||||
return { api: null, uid: null, deviceFp: null };
|
||||
}
|
||||
await redis.set(`ZZZ:DEVICE_FP:${ltuid}:FP`, deviceFp, {
|
||||
EX: 86400 * 7,
|
||||
});
|
||||
data['deviceFp'] = deviceFp;
|
||||
const deviceLogin = api.getUrl('deviceLogin', data);
|
||||
const saveDevice = api.getUrl('saveDevice', data);
|
||||
if (!!deviceLogin && !!saveDevice) {
|
||||
logger.debug(`[米游社][设备登录]保存设备信息`);
|
||||
try {
|
||||
logger.debug(`[米游社][设备登录]${JSON.stringify(deviceLogin)}`);
|
||||
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}`);
|
||||
}
|
||||
await redis.set(`ZZZ:DEVICE_FP:${ltuid}:FP`, deviceFp, {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
deviceFp = await redis.get(`ZZZ:DEVICE_FP:${uid}`);
|
||||
if (!deviceFp) {
|
||||
const sdk = api.getUrl('getFp');
|
||||
const res = await fetch(sdk.url, {
|
||||
headers: sdk.headers,
|
||||
method: 'POST',
|
||||
body: sdk.body,
|
||||
});
|
||||
const fpRes = await res.json();
|
||||
deviceFp = fpRes?.data?.device_fp;
|
||||
if (deviceFp) {
|
||||
await redis.set(`ZZZ:DEVICE_FP:${uid}`, deviceFp, {
|
||||
EX: 86400 * 7,
|
||||
});
|
||||
data['deviceFp'] = deviceFp;
|
||||
const deviceLogin = api.getUrl('deviceLogin', data);
|
||||
const saveDevice = api.getUrl('saveDevice', data);
|
||||
if (!!deviceLogin && !!saveDevice) {
|
||||
logger.debug(`[米游社][设备登录]保存设备信息`);
|
||||
try {
|
||||
logger.debug(`[米游社][设备登录]${JSON.stringify(deviceLogin)}`);
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
deviceFp = await redis.get(`ZZZ:DEVICE_FP:${uid}`);
|
||||
if (!deviceFp) {
|
||||
const sdk = api.getUrl('getFp');
|
||||
const res = await fetch(sdk.url, {
|
||||
headers: sdk.headers,
|
||||
method: 'POST',
|
||||
body: sdk.body,
|
||||
});
|
||||
const fpRes = await res.json();
|
||||
deviceFp = fpRes?.data?.device_fp;
|
||||
if (deviceFp) {
|
||||
await redis.set(`ZZZ:DEVICE_FP:${uid}`, deviceFp, {
|
||||
EX: 86400 * 7,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// 返回数据(API、UID、设备指纹)
|
||||
return { api, uid, deviceFp };
|
||||
} catch (error) {
|
||||
this.reply(error.message);
|
||||
return { api: null, uid: null, deviceFp: null };
|
||||
}
|
||||
// 返回数据(API、UID、设备指纹)
|
||||
return { api, uid, deviceFp };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -180,10 +172,9 @@ export class ZZZPlugin extends plugin {
|
|||
async getPlayerInfo() {
|
||||
// 获取 米游社 API
|
||||
const { api, uid } = await this.getAPI();
|
||||
if (!api) return false;
|
||||
// 获取用户信息
|
||||
let userData = await api.getFinalData(this.e, 'zzzUser');
|
||||
if (!userData) return false;
|
||||
if (!userData) throw new Error('获取用户数据失败');
|
||||
// 取第一个用户信息
|
||||
userData =
|
||||
userData?.list?.find(item => item.game_uid == uid) || userData?.list?.[0];
|
||||
|
|
@ -195,7 +186,7 @@ export class ZZZPlugin extends plugin {
|
|||
} else if (this.e.friend?.getAvatarUrl) {
|
||||
avatar = await this.e.friend.getAvatarUrl();
|
||||
} else {
|
||||
avatar = this.e?.bot?.avatar
|
||||
avatar = this.e?.bot?.avatar;
|
||||
}
|
||||
// 写入数据
|
||||
this.e.playerCard = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue