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
4913e524c9
commit
c71cb5a7f4
1 changed files with 57 additions and 39 deletions
|
|
@ -87,12 +87,13 @@ export class ZZZPlugin extends plugin {
|
||||||
return { api: null, uid: null, deviceFp: null };
|
return { api: null, uid: null, deviceFp: null };
|
||||||
}
|
}
|
||||||
// 获取设备指纹
|
// 获取设备指纹
|
||||||
let deviceFp = await redis.get(`ZZZ:DEVICE_FP:${ltuid}:FP`);
|
let deviceFp
|
||||||
let bindInfo = await redis.get(`ZZZ:DEVICE_FP:${ltuid}:BIND`);
|
let bindInfo = await redis.get(`ZZZ:DEVICE_FP:${ltuid}:BIND`);
|
||||||
let data = {
|
|
||||||
deviceFp,
|
|
||||||
};
|
|
||||||
if (bindInfo) {
|
if (bindInfo) {
|
||||||
|
deviceFp = await redis.get(`ZZZ:DEVICE_FP:${ltuid}:FP`);
|
||||||
|
let data = {
|
||||||
|
deviceFp,
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
bindInfo = JSON.parse(bindInfo);
|
bindInfo = JSON.parse(bindInfo);
|
||||||
data = {
|
data = {
|
||||||
|
|
@ -106,44 +107,61 @@ export class ZZZPlugin extends plugin {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
bindInfo = null;
|
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) {
|
if (!deviceFp) {
|
||||||
return { api: null, uid: null, deviceFp: null };
|
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 };
|
||||||
|
}
|
||||||
|
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 {
|
||||||
EX: 86400 * 7,
|
deviceFp = await redis.get(`ZZZ:DEVICE_FP:${uid}`);
|
||||||
});
|
if (!deviceFp) {
|
||||||
data['deviceFp'] = deviceFp;
|
const sdk = api.getUrl('getFp');
|
||||||
const deviceLogin = api.getUrl('deviceLogin', data);
|
const res = await fetch(sdk.url, {
|
||||||
const saveDevice = api.getUrl('saveDevice', data);
|
headers: sdk.headers,
|
||||||
if (!!deviceLogin && !!saveDevice) {
|
method: 'POST',
|
||||||
logger.debug(`[米游社][设备登录]保存设备信息`);
|
body: sdk.body,
|
||||||
try {
|
});
|
||||||
logger.debug(`[米游社][设备登录]${JSON.stringify(deviceLogin)}`);
|
const fpRes = await res.json();
|
||||||
const login = await request(deviceLogin.url, {
|
deviceFp = fpRes?.data?.device_fp;
|
||||||
headers: deviceLogin.headers,
|
if (deviceFp) {
|
||||||
method: 'POST',
|
await redis.set(`ZZZ:DEVICE_FP:${uid}`, deviceFp, {
|
||||||
body: deviceLogin.body,
|
EX: 86400 * 7,
|
||||||
});
|
});
|
||||||
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}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue