diff --git a/plugins/genshin/model/mys/mysApi.js b/plugins/genshin/model/mys/mysApi.js index 2507ffb..b582fe7 100644 --- a/plugins/genshin/model/mys/mysApi.js +++ b/plugins/genshin/model/mys/mysApi.js @@ -11,7 +11,7 @@ export default class MysApi { * @param option 其他参数 * @param option.log 是否显示日志 */ - constructor (uid, cookie, option = {}, isSr = false, device = '') { + constructor(uid, cookie, option = {}, isSr = false, device = '') { this.uid = uid this.cookie = cookie this.isSr = isSr @@ -21,6 +21,7 @@ export default class MysApi { this.cacheCd = 300 this._device = device + this.device_fp = '' this.option = { log: true, ...option @@ -28,12 +29,12 @@ export default class MysApi { } /* eslint-disable quotes */ - get device () { + get device() { if (!this._device) this._device = `Yz-${md5(this.uid).substring(0, 5)}` return this._device } - getUrl (type, data = {}) { + getUrl(type, data = {}) { let urlMap = this.apiTool.getUrlMap({ ...data, deviceId: this.device }) if (!urlMap[type]) return false @@ -47,7 +48,7 @@ export default class MysApi { return { url, headers, body } } - getServer () { + getServer() { let uid = this.uid switch (String(uid)[0]) { case '1': @@ -64,23 +65,24 @@ export default class MysApi { case '9': return this.isSr ? 'prod_official_cht' : 'os_cht' // 港澳台服 } - return 'cn_gf01' + return this.isSr ? 'prod_gf_cn' : 'cn_gf01' } - async getData (type, data = {}, cached = false, isGetFP = false) { - if (!isGetFP && !data.device_fp) { + 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) - if (!data) { - data = {} - } + 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'] = device_fp?.data?.device_fp + data.headers['x-rpc-device_fp'] = this.device_fp } else { + if (!data) data = {} data.headers = { - 'x-rpc-device_fp': device_fp?.data?.device_fp + 'x-rpc-device_fp': this.device_fp } } } @@ -144,7 +146,7 @@ export default class MysApi { return res } - getHeaders (query = '', body = '') { + getHeaders(query = '', body = '') { const cn = { app_version: '2.40.1', User_Agent: `Mozilla/5.0 (Linux; Android 12; ${this.device}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.73 Mobile Safari/537.36 miHoYoBBS/2.40.1`, @@ -176,7 +178,7 @@ export default class MysApi { } } - getDs (q = '', b = '') { + getDs(q = '', b = '') { let n = '' if (['cn_gf01', 'cn_qd01', 'prod_gf_cn', 'prod_qd_cn'].includes(this.server)) { n = 'xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs' @@ -189,24 +191,24 @@ export default class MysApi { return `${t},${r},${DS}` } - getGuid () { - function S4 () { + getGuid() { + function S4() { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1) } return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4()) } - cacheKey (type, data) { + cacheKey(type, data) { return 'Yz:genshin:mys:cache:' + md5(this.uid + type + JSON.stringify(data)) } - async cache (res, cacheKey) { + async cache(res, cacheKey) { if (!res || res.retcode !== 0) return redis.setEx(cacheKey, this.cacheCd, JSON.stringify(res)) } - async getAgent () { + async getAgent() { let proxyAddress = cfg.bot.proxyAddress if (!proxyAddress) return null if (proxyAddress === 'http://0.0.0.0:0') return null @@ -228,7 +230,7 @@ export default class MysApi { return null } - generateSeed (length = 16) { + generateSeed(length = 16) { const characters = '0123456789abcdef' let result = '' for (let i = 0; i < length; i++) { diff --git a/plugins/genshin/model/mys/mysInfo.js b/plugins/genshin/model/mys/mysInfo.js index 2a64f9c..81337f2 100644 --- a/plugins/genshin/model/mys/mysInfo.js +++ b/plugins/genshin/model/mys/mysInfo.js @@ -391,8 +391,17 @@ export default class MysInfo { if (res.api === 'detail') res.retcode = 0 break case 1034: + try { + let Validate = (await import(`file://${process.cwd()}/plugins/loveMys-plugin/model/mys/mysApi.js`)).default + let vali = new Validate(mysApi.uid, mysApi.cookie, mysApi.option, mysApi.isSr ? 'sr' : 'gs', mysApi._device) + res = await vali.getvali(type, data) + } catch (error) { + logger.error(error) + } + if (!res || res?.retcode == 1034) { logger.mark(`[米游社查询失败][uid:${this.uid}][qq:${this.userId}] 遇到验证码`) if (!isTask) this.e.reply('米游社查询遇到验证码,请稍后再试') + } break default: if (!isTask) this.e.reply(`米游社接口报错,暂时无法查询:${res.message || 'error'}`)