diff --git a/apps/user.js b/apps/user.js index bb32b7d..c7da3da 100644 --- a/apps/user.js +++ b/apps/user.js @@ -107,6 +107,7 @@ export class User extends ZZZPlugin { await redis.del(`ZZZ:DEVICE_FP:${ltuid}:FP`); await redis.del(`ZZZ:DEVICE_FP:${ltuid}:BIND`); await redis.del(`ZZZ:DEVICE_FP:${ltuid}:ID`); + await redis.del(`ZZZ:DEVICE_FP:${uid}:FP`); await this.reply('解绑设备成功', false, { at: true, recallMsg: 100 }); } async bindDeviceHelp() { diff --git a/lib/plugin.js b/lib/plugin.js index f7442d1..f85bd13 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -157,11 +157,38 @@ export class ZZZPlugin extends plugin { body: sdk.body, }); 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:${uid}:FP`, deviceFp, { + EX: 86400 * 7, + }); + if (!/^(1[0-9])[0-9]{8}/i.test(uid)) { + 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}`); + } + } } } }