不重复生成fp

This commit is contained in:
bbaban 2023-10-10 12:53:42 +08:00
parent 72fc40ea49
commit af19c2959c
2 changed files with 27 additions and 19 deletions

View File

@ -68,24 +68,8 @@ export default class MysApi {
return this.isSr ? 'prod_gf_cn' : 'cn_gf01'
}
async getData(type, data = {}, cached = false, isGetFP = false) {
if (!isGetFP && !this.device_fp && !data?.headers?.['x-rpc-device_fp']) {
let seed_id = this.generateSeed(16)
let device_fp = await this.getData('getFp', {
seed_id
}, false, true)
this.device_fp = device_fp?.data?.device_fp
}
if (!isGetFP && this.device_fp && !data?.headers?.['x-rpc-device_fp']) {
if (data?.headers) {
data.headers['x-rpc-device_fp'] = this.device_fp
} else {
if (!data) data = {}
data.headers = {
'x-rpc-device_fp': this.device_fp
}
}
}
async getData(type, data = {}, cached = false) {
if (type == 'getFp') data = { seed_id: this.generateSeed(16) }
let { url, headers, body } = this.getUrl(type, data)
if (!url) return false

View File

@ -161,10 +161,34 @@ export default class MysInfo {
let user = e.user?.getMysUser()
let mysApi = new MysApi(mysInfo.uid, mysInfo.ckInfo.ck, option, e.isSr, user.device)
if (!data?.headers?.['x-rpc-device_fp']){
let device_fp = (await mysApi.getData('getFp')).data?.device_fp
if (data?.headers) {
data.headers['x-rpc-device_fp'] = device_fp
} else {
if (!data) data = {}
data.headers = {
'x-rpc-device_fp': device_fp
}
}
}
let res
if (lodash.isObject(api)) {
let all = []
/** 同步请求 */
for (let i in api) {
if (!api[i]?.headers?.['x-rpc-device_fp']){
if (api[i]?.headers) {
api[i].headers['x-rpc-device_fp'] = device_fp
} else {
if (!api[i]) api[i] = {}
api[i].headers = {
'x-rpc-device_fp': device_fp
}
}
}
}
if (e.apiSync) {
res = []
for (let i in api) {
@ -396,7 +420,7 @@ export default class MysInfo {
let vali = new Validate(mysApi.uid, mysApi.cookie, mysApi.option, mysApi.isSr ? 'sr' : 'gs', mysApi._device)
res = await vali.getvali(type, data)
} catch (error) { }
if (!res || res?.retcode == 1034) {
logger.mark(`[米游社查询失败][uid:${this.uid}][qq:${this.userId}] 遇到验证码`)
if (!isTask) this.e.reply('米游社查询遇到验证码,请稍后再试')