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..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) @@ -26,17 +26,14 @@ 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 } /** 获取角色数据 */ 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 @@ -66,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() @@ -104,7 +101,7 @@ export default class Calculator extends base { this.setSkill = setSkill } - async getBody() { + async getBody () { // 技能 let skillList = [] if (this.dataCharacter) { @@ -156,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: [] } @@ -168,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) @@ -197,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) { @@ -219,7 +215,6 @@ export default class Calculator extends base { level_current: Number(this.dataCharacter.weapon.level), level_target: Number(this.setSkill[1]) } - } } @@ -228,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 @@ -242,8 +237,11 @@ export default class Calculator extends base { return avatarSkill.list } - async computes(body) { - let computes = await MysInfo.get(this.e, 'compute', body) + async computes (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 9adb221..d143d8c 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/mysApi.js b/plugins/genshin/model/mys/mysApi.js index b54e181..db89e24 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 } } @@ -64,26 +66,11 @@ 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) { - let seed_id = this.generateSeed(16) - let device_fp = await this.getData('getFp', { - seed_id - }, false, true) - if (!data) { - data = {} - } - if (data?.headers) { - data.headers['x-rpc-device_fp'] = device_fp?.data?.device_fp - } else { - data.headers = { - 'x-rpc-device_fp': device_fp?.data?.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 @@ -96,7 +83,6 @@ export default class MysApi { if (data.headers) { headers = { ...headers, ...data.headers } - delete data.headers } let param = { @@ -237,4 +223,3 @@ export default class MysApi { return result } } - diff --git a/plugins/genshin/model/mys/mysInfo.js b/plugins/genshin/model/mys/mysInfo.js index 2a64f9c..e3f35ca 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) @@ -26,9 +26,11 @@ 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) { + static async init (e, api) { await MysInfo.initCache() let mysInfo = new MysInfo(e) @@ -75,7 +77,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 +121,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 +154,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 @@ -161,10 +163,35 @@ export default class MysInfo { let user = e.user?.getMysUser() let mysApi = new MysApi(mysInfo.uid, mysInfo.ckInfo.ck, option, e.isSr, user.device) + let devicefp = '' + if (!data?.headers?.['x-rpc-device_fp'] && api !== 'getFp') { + devicefp = (await mysApi.getData('getFp')).data?.device_fp + if (data?.headers) { + data.headers['x-rpc-device_fp'] = devicefp + } else { + if (!data) data = {} + data.headers = { + 'x-rpc-device_fp': devicefp + } + } + } + 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'] = devicefp + } else { + if (!api[i]) api[i] = {} + api[i].headers = { + 'x-rpc-device_fp': devicefp + } + } + } + } if (e.apiSync) { res = [] for (let i in api) { @@ -179,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 @@ -196,7 +224,7 @@ export default class MysInfo { * 初始化公共CK * @returns {Promise} */ - static async initPubCk() { + static async initPubCk () { // 初始化公共CK let pubCount = 0 let pubCks = GsCfg.getConfig('mys', 'pubCk') || [] @@ -220,7 +248,7 @@ export default class MysInfo { * 默认会将用户CK加入查询池 * @returns {Promise} */ - static async initUserCk() { + static async initUserCk () { // 初始化用户缓存 let userCount = 0 await MysUser.forEach(async (mys) => { @@ -238,7 +266,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')) { @@ -261,13 +289,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 @@ -275,12 +303,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 } @@ -296,7 +324,7 @@ export default class MysInfo { return false } - async checkReply() { + async checkReply () { if (this.e.noTips === true) return if (!this.uid) { @@ -317,7 +345,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) @@ -336,7 +364,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 @@ -391,8 +419,14 @@ export default class MysInfo { if (res.api === 'detail') res.retcode = 0 break case 1034: - logger.mark(`[米游社查询失败][uid:${this.uid}][qq:${this.userId}] 遇到验证码`) - if (!isTask) this.e.reply('米游社查询遇到验证码,请稍后再试') + try { + res = await Gtest.getvali(mysApi, type, data, this.gtest) + } catch (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'}`) @@ -407,7 +441,7 @@ export default class MysInfo { } /** 删除失效ck */ - async delCk() { + async delCk () { if (!this.ckUser) { return false } @@ -417,7 +451,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 3f2caa6..65ca05b 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 } @@ -41,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] } } @@ -58,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) { @@ -69,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 } } @@ -110,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 } }