From 0232fcf48ef597d0e63c4e8e23c3c5d86999a2ee Mon Sep 17 00:00:00 2001 From: bbaban <3102509561@qq.com> Date: Mon, 9 Oct 2023 23:11:24 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=A4=96=E7=BD=AE=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E8=A7=A3=E5=86=B31034?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/model/mys/mysApi.js | 42 +++++++++++++++------------- plugins/genshin/model/mys/mysInfo.js | 9 ++++++ 2 files changed, 31 insertions(+), 20 deletions(-) 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'}`) From fe8640274bdd9f6d3585e4e38e6c1316462008ac Mon Sep 17 00:00:00 2001 From: bbaban <3102509561@qq.com> Date: Tue, 10 Oct 2023 12:14:16 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E5=88=A0log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/model/mys/mysInfo.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/genshin/model/mys/mysInfo.js b/plugins/genshin/model/mys/mysInfo.js index 81337f2..70ba98a 100644 --- a/plugins/genshin/model/mys/mysInfo.js +++ b/plugins/genshin/model/mys/mysInfo.js @@ -395,12 +395,11 @@ export default class MysInfo { 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) - } + } catch (error) { } + if (!res || res?.retcode == 1034) { - logger.mark(`[米游社查询失败][uid:${this.uid}][qq:${this.userId}] 遇到验证码`) - if (!isTask) this.e.reply('米游社查询遇到验证码,请稍后再试') + logger.mark(`[米游社查询失败][uid:${this.uid}][qq:${this.userId}] 遇到验证码`) + if (!isTask) this.e.reply('米游社查询遇到验证码,请稍后再试') } break default: From 72fc40ea490171fd13ed50b9d110a879f3699e70 Mon Sep 17 00:00:00 2001 From: bbaban <3102509561@qq.com> Date: Tue, 10 Oct 2023 12:24:37 +0800 Subject: [PATCH 3/9] fix --- plugins/genshin/model/mys/mysApi.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/genshin/model/mys/mysApi.js b/plugins/genshin/model/mys/mysApi.js index b582fe7..1d1878c 100644 --- a/plugins/genshin/model/mys/mysApi.js +++ b/plugins/genshin/model/mys/mysApi.js @@ -69,14 +69,14 @@ export default class MysApi { } async getData(type, data = {}, cached = false, isGetFP = false) { - if (!isGetFP && !this.device_fp && !data?.headers['x-rpc-device_fp']) { + 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 (!isGetFP && this.device_fp && !data?.headers?.['x-rpc-device_fp']) { if (data?.headers) { data.headers['x-rpc-device_fp'] = this.device_fp } else { From af19c2959c5987ef75533b8bb062decfb1ca5c8a Mon Sep 17 00:00:00 2001 From: bbaban <3102509561@qq.com> Date: Tue, 10 Oct 2023 12:53:42 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E4=B8=8D=E9=87=8D=E5=A4=8D=E7=94=9F?= =?UTF-8?q?=E6=88=90fp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/model/mys/mysApi.js | 20 ++------------------ plugins/genshin/model/mys/mysInfo.js | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/plugins/genshin/model/mys/mysApi.js b/plugins/genshin/model/mys/mysApi.js index 1d1878c..32c991d 100644 --- a/plugins/genshin/model/mys/mysApi.js +++ b/plugins/genshin/model/mys/mysApi.js @@ -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 diff --git a/plugins/genshin/model/mys/mysInfo.js b/plugins/genshin/model/mys/mysInfo.js index 70ba98a..010f68c 100644 --- a/plugins/genshin/model/mys/mysInfo.js +++ b/plugins/genshin/model/mys/mysInfo.js @@ -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('米游社查询遇到验证码,请稍后再试') From fc299a96281885cad31ab37392e6b3be70de6c7a Mon Sep 17 00:00:00 2001 From: bbaban <3102509561@qq.com> Date: Tue, 10 Oct 2023 12:59:47 +0800 Subject: [PATCH 5/9] fix --- plugins/genshin/model/mys/mysInfo.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/genshin/model/mys/mysInfo.js b/plugins/genshin/model/mys/mysInfo.js index 010f68c..75c4052 100644 --- a/plugins/genshin/model/mys/mysInfo.js +++ b/plugins/genshin/model/mys/mysInfo.js @@ -161,8 +161,9 @@ 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 + let device_fp = '' + if (!data?.headers?.['x-rpc-device_fp']) { + device_fp = (await mysApi.getData('getFp')).data?.device_fp if (data?.headers) { data.headers['x-rpc-device_fp'] = device_fp } else { @@ -178,7 +179,7 @@ export default class MysInfo { let all = [] /** 同步请求 */ for (let i in api) { - if (!api[i]?.headers?.['x-rpc-device_fp']){ + if (!api[i]?.headers?.['x-rpc-device_fp']) { if (api[i]?.headers) { api[i].headers['x-rpc-device_fp'] = device_fp } else { From 3e8e30f329b6d02c5a975b3a729cff7e73e3c082 Mon Sep 17 00:00:00 2001 From: bbaban <3102509561@qq.com> Date: Tue, 10 Oct 2023 13:29:59 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84fp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/model/blueprint.js | 2 +- plugins/genshin/model/calculator.js | 10 +++++----- plugins/genshin/model/mys/apiTool.js | 8 ++++---- plugins/genshin/model/mys/mysInfo.js | 2 +- plugins/genshin/model/note.js | 15 +++++---------- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/plugins/genshin/model/blueprint.js b/plugins/genshin/model/blueprint.js index a8d1a27..6e1e318 100644 --- a/plugins/genshin/model/blueprint.js +++ b/plugins/genshin/model/blueprint.js @@ -53,7 +53,7 @@ export default class blueprint extends base { } async computes (body) { - let computes = await this.mysApi.getData('blueprintCompute', body) + let computes = await this.mysApi.getData('blueprintCompute', { body }) if (!computes || computes.retcode !== 0) return false computes = computes.data?.list return computes diff --git a/plugins/genshin/model/calculator.js b/plugins/genshin/model/calculator.js index fdf4c87..2f3c230 100644 --- a/plugins/genshin/model/calculator.js +++ b/plugins/genshin/model/calculator.js @@ -26,10 +26,7 @@ export default class Calculator extends base { this.mysApi = new MysApi(uid, ck.ck, { log: true }) - let seed_id = lodash.sample('abcdefghijklmnopqrstuvwxyz0123456789', 16).replace(/,/g, '') - let device_fp = await MysInfo.get(this.e, 'getFp', { - seed_id - }) + let device_fp = await MysInfo.get(this.e, 'getFp') this.headers = { 'x-rpc-device_fp': device_fp?.data?.device_fp } @@ -243,7 +240,10 @@ export default class Calculator extends base { } async computes(body) { - let computes = await MysInfo.get(this.e, 'compute', body) + let computes = await MysInfo.get(this.e, 'compute', { + body, + headers: this.headers + }) if (!computes || computes.retcode !== 0) return false computes = computes.data diff --git a/plugins/genshin/model/mys/apiTool.js b/plugins/genshin/model/mys/apiTool.js index 8e1daf0..5942c8e 100644 --- a/plugins/genshin/model/mys/apiTool.js +++ b/plugins/genshin/model/mys/apiTool.js @@ -66,11 +66,11 @@ export default class apiTool { /** 养成计算器 */ compute: { url: `${host}event/e20200928calculate/v2/compute`, - body: data + body: data.body }, blueprintCompute: { url: `${host}event/e20200928calculate/v1/furniture/compute`, - body: data + body: data.body }, /** 养成计算器 */ blueprint: { @@ -178,7 +178,7 @@ export default class apiTool { compute: { url: `${host}event/rpgcalc/compute?`, query:`game=hkrpg`, - body: data + body: data.body }, /** 详情 */ detail: { @@ -197,7 +197,7 @@ export default class apiTool { urlMap.genshin.blueprint.url = 'https://sg-public-api.hoyolab.com/event/calculateos/furniture/blueprint' urlMap.genshin.blueprint.query = `share_code=${data.share_code}®ion=${this.server}&lang=zh-cn` urlMap.genshin.blueprintCompute.url = 'https://sg-public-api.hoyolab.com/event/calculateos/furniture/compute' - urlMap.genshin.blueprintCompute.body = { lang: 'zh-cn', ...data } + urlMap.genshin.blueprintCompute.body = { lang: 'zh-cn', ...data.body } urlMap.genshin.ys_ledger.url = 'https://hk4e-api-os.mihoyo.com/event/ysledgeros/month_info'// 支持了国际服札记 urlMap.genshin.ys_ledger.query = `lang=zh-cn&month=${data.month}&uid=${this.uid}®ion=${this.server}` urlMap.genshin.useCdk.url = 'https://sg-hk4e-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey' diff --git a/plugins/genshin/model/mys/mysInfo.js b/plugins/genshin/model/mys/mysInfo.js index 75c4052..dfe81fd 100644 --- a/plugins/genshin/model/mys/mysInfo.js +++ b/plugins/genshin/model/mys/mysInfo.js @@ -162,7 +162,7 @@ export default class MysInfo { let mysApi = new MysApi(mysInfo.uid, mysInfo.ckInfo.ck, option, e.isSr, user.device) let device_fp = '' - if (!data?.headers?.['x-rpc-device_fp']) { + if (!data?.headers?.['x-rpc-device_fp'] && api !== 'getFp') { device_fp = (await mysApi.getData('getFp')).data?.device_fp if (data?.headers) { data.headers['x-rpc-device_fp'] = device_fp diff --git a/plugins/genshin/model/note.js b/plugins/genshin/model/note.js index 3f2caa6..b59e0b0 100644 --- a/plugins/genshin/model/note.js +++ b/plugins/genshin/model/note.js @@ -16,15 +16,10 @@ export default class Note extends base { } async getData () { - let seed_id = lodash.sample('abcdefghijklmnopqrstuvwxyz0123456789', 16).replace(/,/g, '') - let device_fp = await MysInfo.get(this.e, 'getFp', { - seed_id - }) - let res = await MysInfo.get(this.e, 'dailyNote', { - headers: { - 'x-rpc-device_fp': device_fp?.data?.device_fp - } - }) + let device_fp = await MysInfo.get(this.e, 'getFp') + let headers= {'x-rpc-device_fp': device_fp?.data?.device_fp} + + let res = await MysInfo.get(this.e, 'dailyNote', { headers }) let resUser if (!res || res.retcode !== 0) return false @@ -33,7 +28,7 @@ export default class Note extends base { let screenData = this.screenData if (this.e.isSr) { - resUser = await MysInfo.get(this.e, 'UserGame') + resUser = await MysInfo.get(this.e, 'UserGame', { headers }) resUser.data?.list?.forEach(v => this.e.uid.includes(v.game_biz)) if (!resUser || resUser.retcode !== 0) return false } From a70b384580ef474c38ddc035e357609407ae8fd9 Mon Sep 17 00:00:00 2001 From: bbaban <3102509561@qq.com> Date: Tue, 10 Oct 2023 15:39:49 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E6=94=B9=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/model/mys/mysApi.js | 1 - plugins/genshin/model/mys/mysInfo.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/genshin/model/mys/mysApi.js b/plugins/genshin/model/mys/mysApi.js index 32c991d..b0a1622 100644 --- a/plugins/genshin/model/mys/mysApi.js +++ b/plugins/genshin/model/mys/mysApi.js @@ -21,7 +21,6 @@ export default class MysApi { this.cacheCd = 300 this._device = device - this.device_fp = '' this.option = { log: true, ...option diff --git a/plugins/genshin/model/mys/mysInfo.js b/plugins/genshin/model/mys/mysInfo.js index dfe81fd..5cb6042 100644 --- a/plugins/genshin/model/mys/mysInfo.js +++ b/plugins/genshin/model/mys/mysInfo.js @@ -418,8 +418,7 @@ export default class MysInfo { 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) + res = await Validate.getvali(mysApi, type, data) } catch (error) { } if (!res || res?.retcode == 1034) { From 3b18140992209b72d61e7be57cce675b66e9fbd9 Mon Sep 17 00:00:00 2001 From: bbaban <3102509561@qq.com> Date: Thu, 12 Oct 2023 12:24:30 +0800 Subject: [PATCH 8/9] fix --- plugins/genshin/model/calculator.js | 20 ++++++++-------- plugins/genshin/model/mys/mysApi.js | 28 +++++++++++------------ plugins/genshin/model/mys/mysInfo.js | 34 ++++++++++++++-------------- plugins/genshin/model/note.js | 30 +++++++++++++----------- 4 files changed, 56 insertions(+), 56 deletions(-) diff --git a/plugins/genshin/model/calculator.js b/plugins/genshin/model/calculator.js index 2f3c230..aaaa9c9 100644 --- a/plugins/genshin/model/calculator.js +++ b/plugins/genshin/model/calculator.js @@ -5,13 +5,13 @@ import lodash from 'lodash' import gsCfg from './gsCfg.js' export default class Calculator extends base { - constructor(e) { + constructor (e) { super(e) this.model = 'calculator' this.checkMsg = `设置角色、武器、技能等级有误\n指令:${e.isSr ? '*克拉拉养成\n示例:*克拉拉养成75 80 6 9 9 9\n参数为角色、武器、普攻、战技、终结技、天赋' : '#刻晴养成\n示例:#刻晴养成81 90 9 9 9\n参数为角色、武器、技能等级'}` } - async get(role) { + async get (role) { this.role = role /** 获取绑定uid */ let uid = await MysInfo.getUid(this.e) @@ -33,7 +33,7 @@ export default class Calculator extends base { /** 获取角色数据 */ let character = await MysInfo.get(this.e, this.e.isSr ? 'avatarInfo' : 'character', { - headers: this.headers, + headers: this.headers }) if (!character || character.retcode !== 0) return false character = character.data @@ -63,7 +63,7 @@ export default class Calculator extends base { } } - async getSet() { + async getSet () { let defSetSkill = this.e.isSr ? '80,80,6,10,10,10'.split(',') : '90,90,10,10,10'.split(',') let set = this.e.msg.replace(/#|#|星铁|养成|计算/g, '').trim() @@ -101,7 +101,7 @@ export default class Calculator extends base { this.setSkill = setSkill } - async getBody() { + async getBody () { // 技能 let skillList = [] if (this.dataCharacter) { @@ -153,7 +153,7 @@ export default class Calculator extends base { avatar: { item_id: Number(this.role.roleId), cur_level: Number(this.dataCharacter.level), - target_level: Number(this.setSkill[0]), + target_level: Number(this.setSkill[0]) }, skill_list: [] } @@ -165,7 +165,6 @@ export default class Calculator extends base { } if (Number(this.setSkill[0]) >= data.min_level_limit) body.skill_list.push(skill) } - } else { skillList = skillList.filter((item) => item.max_level != 1) @@ -194,7 +193,7 @@ export default class Calculator extends base { } if (this.mysApi.getServer().startsWith('os')) { - body.lang = "zh-cn" + body.lang = 'zh-cn' } if (this.e.isSr) { @@ -216,7 +215,6 @@ export default class Calculator extends base { level_current: Number(this.dataCharacter.weapon.level), level_target: Number(this.setSkill[1]) } - } } @@ -225,7 +223,7 @@ export default class Calculator extends base { return body } - async getSkillId(roleId) { + async getSkillId (roleId) { let avatarSkill = await MysInfo.get(this.e, 'avatarSkill', { headers: this.headers, avatar_id: roleId @@ -239,7 +237,7 @@ export default class Calculator extends base { return avatarSkill.list } - async computes(body) { + async computes (body) { let computes = await MysInfo.get(this.e, 'compute', { body, headers: this.headers diff --git a/plugins/genshin/model/mys/mysApi.js b/plugins/genshin/model/mys/mysApi.js index b0a1622..4946f50 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 @@ -28,12 +28,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 +47,7 @@ export default class MysApi { return { url, headers, body } } - getServer() { + getServer () { let uid = this.uid switch (String(uid)[0]) { case '1': @@ -67,7 +67,7 @@ export default class MysApi { return this.isSr ? 'prod_gf_cn' : 'cn_gf01' } - async getData(type, data = {}, cached = false) { + async getData (type, data = {}, cached = false) { if (type == 'getFp') data = { seed_id: this.generateSeed(16) } let { url, headers, body } = this.getUrl(type, data) @@ -81,7 +81,6 @@ export default class MysApi { if (data.headers) { headers = { ...headers, ...data.headers } - delete data.headers } let param = { @@ -129,7 +128,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`, @@ -161,7 +160,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' @@ -174,24 +173,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 @@ -213,7 +212,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++) { @@ -222,4 +221,3 @@ export default class MysApi { return result } } - diff --git a/plugins/genshin/model/mys/mysInfo.js b/plugins/genshin/model/mys/mysInfo.js index 5cb6042..c2323dd 100644 --- a/plugins/genshin/model/mys/mysInfo.js +++ b/plugins/genshin/model/mys/mysInfo.js @@ -8,7 +8,7 @@ import DailyCache from './DailyCache.js' export default class MysInfo { static tips = '请先#绑定cookie\n发送【体力帮助】查看配置教程' - constructor(e) { + constructor (e) { if (e) { this.e = e this.userId = String(e.user_id) @@ -28,7 +28,7 @@ export default class MysInfo { this.auth = ['dailyNote', 'bbs_sign_info', 'bbs_sign_home', 'bbs_sign', 'ys_ledger', 'compute', 'avatarSkill', 'detail', 'blueprint', 'UserGame', 'deckList', 'avatar_cardList', 'action_cardList', 'avatarInfo'] } - static async init(e, api) { + static async init (e, api) { await MysInfo.initCache() let mysInfo = new MysInfo(e) @@ -75,7 +75,7 @@ export default class MysInfo { * @param matchMsgUid 用于判断消息是否为uid数据 * @returns {Promise} */ - static async getUid(e, matchMsgUid = true) { + static async getUid (e, matchMsgUid = true) { let user = await NoteUser.create(e) if (e.uid && matchMsgUid) { /** 没有绑定的自动绑定 */ @@ -119,7 +119,7 @@ export default class MysInfo { * @param e * @returns {Promise} */ - static async getSelfUid(e) { + static async getSelfUid (e) { let { msg = '', at = '' } = e if (!msg) return false @@ -152,7 +152,7 @@ export default class MysInfo { * @param option 配置 * @param option.log 是否显示请求日志 */ - static async get(e, api, data = {}, option = {}) { + static async get (e, api, data = {}, option = {}) { let mysInfo = await MysInfo.init(e, api) if (!mysInfo.uid || !mysInfo.ckInfo.ck) return false @@ -221,7 +221,7 @@ export default class MysInfo { * 初始化公共CK * @returns {Promise} */ - static async initPubCk() { + static async initPubCk () { // 初始化公共CK let pubCount = 0 let pubCks = GsCfg.getConfig('mys', 'pubCk') || [] @@ -245,7 +245,7 @@ export default class MysInfo { * 默认会将用户CK加入查询池 * @returns {Promise} */ - static async initUserCk() { + static async initUserCk () { // 初始化用户缓存 let userCount = 0 await MysUser.forEach(async (mys) => { @@ -263,7 +263,7 @@ export default class MysInfo { * @param clearData 强制初始化时是否清除已有数据 (刷新/重置) * @returns {Promise} */ - static async initCache(force = false, clearData = false) { + static async initCache (force = false, clearData = false) { // 检查缓存标记 let cache = DailyCache.create() if (!force && await cache.get('cache-ready')) { @@ -286,13 +286,13 @@ export default class MysInfo { return true } - static async getBingCkUid() { + static async getBingCkUid () { let res = await GsCfg.getBingCk() return { ...res.ck } } // 获取uid绑定的ck信息 - static async checkUidBing(uid, game = 'gs') { + static async checkUidBing (uid, game = 'gs') { let ckUser = await MysUser.getByQueryUid(uid, game, true) if (ckUser && ckUser.ck) { return ckUser @@ -300,12 +300,12 @@ export default class MysInfo { return false } - static async delDisable() { + static async delDisable () { return await MysUser.delDisable() } /** 判断绑定ck才能查询 */ - checkAuth(api) { + checkAuth (api) { if (api === 'cookie') { return true } @@ -321,7 +321,7 @@ export default class MysInfo { return false } - async checkReply() { + async checkReply () { if (this.e.noTips === true) return if (!this.uid) { @@ -342,7 +342,7 @@ export default class MysInfo { * @param onlySelfCk 是否只获取uid自己对应的ck。为true则只获取uid对应ck,若无则返回为空 * @returns {Promise} 查询ck,获取失败则返回空 */ - async getCookie(game = 'gs', onlySelfCk = false) { + async getCookie (game = 'gs', onlySelfCk = false) { if (this.ckUser?.ck) return this.ckUser?.ck let mysUser = await MysUser.getByQueryUid(this.uid, game, onlySelfCk) @@ -361,7 +361,7 @@ export default class MysInfo { return this.ckUser?.ck } - async checkCode(res, type, mysApi = {}, data = {}, isTask = false) { + async checkCode (res, type, mysApi = {}, data = {}, isTask = false) { if (!res) { if (!isTask) this.e.reply('米游社接口请求失败,暂时无法查询') return false @@ -439,7 +439,7 @@ export default class MysInfo { } /** 删除失效ck */ - async delCk() { + async delCk () { if (!this.ckUser) { return false } @@ -449,7 +449,7 @@ export default class MysInfo { } /** 查询次数满,今日内标记失效 */ - async disableToday(game = 'gs') { + async disableToday (game = 'gs') { /** 统计次数设为超限 */ await this.ckUser.disable(game) } diff --git a/plugins/genshin/model/note.js b/plugins/genshin/model/note.js index b59e0b0..65ca05b 100644 --- a/plugins/genshin/model/note.js +++ b/plugins/genshin/model/note.js @@ -17,7 +17,7 @@ export default class Note extends base { async getData () { let device_fp = await MysInfo.get(this.e, 'getFp') - let headers= {'x-rpc-device_fp': device_fp?.data?.device_fp} + let headers = { 'x-rpc-device_fp': device_fp?.data?.device_fp } let res = await MysInfo.get(this.e, 'dailyNote', { headers }) let resUser @@ -36,7 +36,8 @@ export default class Note extends base { name: this.e.sender.card, quality: 80, ...screenData, - ...data, ...resUser?.data?.list[0] + ...data, + ...resUser?.data?.list[0] } } @@ -53,7 +54,7 @@ export default class Note extends base { let minutes = d.minutes() let seconds = d.seconds() resinMaxTime = hours + '小时' + minutes + '分钟' + seconds + '秒' - //精确到秒。。。。 + // 精确到秒。。。。 if (day > 0) { resinMaxTime = day + '天' + hours + '小时' + minutes + '分钟' + seconds + '秒' } else if (hours > 0) { @@ -64,17 +65,17 @@ export default class Note extends base { resinMaxTime = seconds + '秒' } if ((day > 0) || (hours > 0) || (seconds > 0)) { - let total_seconds = 3600*hours + 60*minutes + seconds - const now = new Date() - const dateTimes = now.getTime() + total_seconds * 1000 - const date = new Date(dateTimes) - const dayDiff = date.getDate() - now.getDate() - const str = dayDiff === 0 ? '今日' : '明日' - const timeStr = `${date.getHours().toString().padStart(2, '0')}:${date + let total_seconds = 3600 * hours + 60 * minutes + seconds + const now = new Date() + const dateTimes = now.getTime() + total_seconds * 1000 + const date = new Date(dateTimes) + const dayDiff = date.getDate() - now.getDate() + const str = dayDiff === 0 ? '今日' : '明日' + const timeStr = `${date.getHours().toString().padStart(2, '0')}:${date .getMinutes() .toString() .padStart(2, '0')}` - let recoverTimeStr = ` | [${str}]${timeStr}` + let recoverTimeStr = ` | [${str}]${timeStr}` resinMaxTime += recoverTimeStr } } @@ -105,8 +106,11 @@ export default class Note extends base { let day = `${week[moment().day()]}` return { uid: this.e.uid, - saveId: this.e.uid, icon, day, - resinMaxTime, nowDay: moment(new Date()).format('YYYY年MM月DD日'), + saveId: this.e.uid, + icon, + day, + resinMaxTime, + nowDay: moment(new Date()).format('YYYY年MM月DD日'), ...data } } From be9cb8cf38fc827d1332e737aa7eb4f587fc4883 Mon Sep 17 00:00:00 2001 From: bbaban <3102509561@qq.com> Date: Thu, 12 Oct 2023 18:13:44 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/model/mys/mysApi.js | 6 ++++-- plugins/genshin/model/mys/mysInfo.js | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/plugins/genshin/model/mys/mysApi.js b/plugins/genshin/model/mys/mysApi.js index 4946f50..fa03be0 100644 --- a/plugins/genshin/model/mys/mysApi.js +++ b/plugins/genshin/model/mys/mysApi.js @@ -10,6 +10,8 @@ export default class MysApi { * @param cookie 米游社cookie * @param option 其他参数 * @param option.log 是否显示日志 + * @param isSr 是否星铁 + * @param device 设备device_id */ constructor (uid, cookie, option = {}, isSr = false, device = '') { this.uid = uid @@ -37,12 +39,12 @@ export default class MysApi { let urlMap = this.apiTool.getUrlMap({ ...data, deviceId: this.device }) if (!urlMap[type]) return false - let { url, query = '', body = '', sign = '' } = urlMap[type] + let { url, query = '', body = '' } = urlMap[type] if (query) url += `?${query}` if (body) body = JSON.stringify(body) - let headers = this.getHeaders(query, body, sign) + let headers = this.getHeaders(query, body) return { url, headers, body } } diff --git a/plugins/genshin/model/mys/mysInfo.js b/plugins/genshin/model/mys/mysInfo.js index c2323dd..e3f35ca 100644 --- a/plugins/genshin/model/mys/mysInfo.js +++ b/plugins/genshin/model/mys/mysInfo.js @@ -26,6 +26,8 @@ export default class MysInfo { // ck对应MysUser对象 this.ckUser = null this.auth = ['dailyNote', 'bbs_sign_info', 'bbs_sign_home', 'bbs_sign', 'ys_ledger', 'compute', 'avatarSkill', 'detail', 'blueprint', 'UserGame', 'deckList', 'avatar_cardList', 'action_cardList', 'avatarInfo'] + + this.gtest = false } static async init (e, api) { @@ -161,15 +163,15 @@ export default class MysInfo { let user = e.user?.getMysUser() let mysApi = new MysApi(mysInfo.uid, mysInfo.ckInfo.ck, option, e.isSr, user.device) - let device_fp = '' + let devicefp = '' if (!data?.headers?.['x-rpc-device_fp'] && api !== 'getFp') { - device_fp = (await mysApi.getData('getFp')).data?.device_fp + devicefp = (await mysApi.getData('getFp')).data?.device_fp if (data?.headers) { - data.headers['x-rpc-device_fp'] = device_fp + data.headers['x-rpc-device_fp'] = devicefp } else { if (!data) data = {} data.headers = { - 'x-rpc-device_fp': device_fp + 'x-rpc-device_fp': devicefp } } } @@ -181,11 +183,11 @@ export default class MysInfo { 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 + api[i].headers['x-rpc-device_fp'] = devicefp } else { if (!api[i]) api[i] = {} api[i].headers = { - 'x-rpc-device_fp': device_fp + 'x-rpc-device_fp': devicefp } } } @@ -204,6 +206,7 @@ export default class MysInfo { for (let i in res) { res[i] = await mysInfo.checkCode(res[i], res[i].api, mysApi, api[res[i].api]) + mysInfo.gtest = true if (res[i]?.retcode === 0) continue @@ -417,8 +420,7 @@ export default class MysInfo { break case 1034: try { - let Validate = (await import(`file://${process.cwd()}/plugins/loveMys-plugin/model/mys/mysApi.js`)).default - res = await Validate.getvali(mysApi, type, data) + res = await Gtest.getvali(mysApi, type, data, this.gtest) } catch (error) { } if (!res || res?.retcode == 1034) {