外置插件解决1034
This commit is contained in:
parent
0172e7a25e
commit
0232fcf48e
|
@ -11,7 +11,7 @@ export default class MysApi {
|
||||||
* @param option 其他参数
|
* @param option 其他参数
|
||||||
* @param option.log 是否显示日志
|
* @param option.log 是否显示日志
|
||||||
*/
|
*/
|
||||||
constructor (uid, cookie, option = {}, isSr = false, device = '') {
|
constructor(uid, cookie, option = {}, isSr = false, device = '') {
|
||||||
this.uid = uid
|
this.uid = uid
|
||||||
this.cookie = cookie
|
this.cookie = cookie
|
||||||
this.isSr = isSr
|
this.isSr = isSr
|
||||||
|
@ -21,6 +21,7 @@ export default class MysApi {
|
||||||
this.cacheCd = 300
|
this.cacheCd = 300
|
||||||
|
|
||||||
this._device = device
|
this._device = device
|
||||||
|
this.device_fp = ''
|
||||||
this.option = {
|
this.option = {
|
||||||
log: true,
|
log: true,
|
||||||
...option
|
...option
|
||||||
|
@ -28,12 +29,12 @@ export default class MysApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable quotes */
|
/* eslint-disable quotes */
|
||||||
get device () {
|
get device() {
|
||||||
if (!this._device) this._device = `Yz-${md5(this.uid).substring(0, 5)}`
|
if (!this._device) this._device = `Yz-${md5(this.uid).substring(0, 5)}`
|
||||||
return this._device
|
return this._device
|
||||||
}
|
}
|
||||||
|
|
||||||
getUrl (type, data = {}) {
|
getUrl(type, data = {}) {
|
||||||
let urlMap = this.apiTool.getUrlMap({ ...data, deviceId: this.device })
|
let urlMap = this.apiTool.getUrlMap({ ...data, deviceId: this.device })
|
||||||
if (!urlMap[type]) return false
|
if (!urlMap[type]) return false
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ export default class MysApi {
|
||||||
return { url, headers, body }
|
return { url, headers, body }
|
||||||
}
|
}
|
||||||
|
|
||||||
getServer () {
|
getServer() {
|
||||||
let uid = this.uid
|
let uid = this.uid
|
||||||
switch (String(uid)[0]) {
|
switch (String(uid)[0]) {
|
||||||
case '1':
|
case '1':
|
||||||
|
@ -64,23 +65,24 @@ export default class MysApi {
|
||||||
case '9':
|
case '9':
|
||||||
return this.isSr ? 'prod_official_cht' : 'os_cht' // 港澳台服
|
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) {
|
async getData(type, data = {}, cached = false, isGetFP = false) {
|
||||||
if (!isGetFP && !data.device_fp) {
|
if (!isGetFP && !this.device_fp && !data?.headers['x-rpc-device_fp']) {
|
||||||
let seed_id = this.generateSeed(16)
|
let seed_id = this.generateSeed(16)
|
||||||
let device_fp = await this.getData('getFp', {
|
let device_fp = await this.getData('getFp', {
|
||||||
seed_id
|
seed_id
|
||||||
}, false, true)
|
}, false, true)
|
||||||
if (!data) {
|
this.device_fp = device_fp?.data?.device_fp
|
||||||
data = {}
|
|
||||||
}
|
}
|
||||||
|
if (!isGetFP && this.device_fp && !data?.headers['x-rpc-device_fp']) {
|
||||||
if (data?.headers) {
|
if (data?.headers) {
|
||||||
data.headers['x-rpc-device_fp'] = device_fp?.data?.device_fp
|
data.headers['x-rpc-device_fp'] = this.device_fp
|
||||||
} else {
|
} else {
|
||||||
|
if (!data) data = {}
|
||||||
data.headers = {
|
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
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
getHeaders (query = '', body = '') {
|
getHeaders(query = '', body = '') {
|
||||||
const cn = {
|
const cn = {
|
||||||
app_version: '2.40.1',
|
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`,
|
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 = ''
|
let n = ''
|
||||||
if (['cn_gf01', 'cn_qd01', 'prod_gf_cn', 'prod_qd_cn'].includes(this.server)) {
|
if (['cn_gf01', 'cn_qd01', 'prod_gf_cn', 'prod_qd_cn'].includes(this.server)) {
|
||||||
n = 'xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs'
|
n = 'xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs'
|
||||||
|
@ -189,24 +191,24 @@ export default class MysApi {
|
||||||
return `${t},${r},${DS}`
|
return `${t},${r},${DS}`
|
||||||
}
|
}
|
||||||
|
|
||||||
getGuid () {
|
getGuid() {
|
||||||
function S4 () {
|
function S4() {
|
||||||
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
|
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4())
|
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))
|
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
|
if (!res || res.retcode !== 0) return
|
||||||
redis.setEx(cacheKey, this.cacheCd, JSON.stringify(res))
|
redis.setEx(cacheKey, this.cacheCd, JSON.stringify(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAgent () {
|
async getAgent() {
|
||||||
let proxyAddress = cfg.bot.proxyAddress
|
let proxyAddress = cfg.bot.proxyAddress
|
||||||
if (!proxyAddress) return null
|
if (!proxyAddress) return null
|
||||||
if (proxyAddress === 'http://0.0.0.0:0') return null
|
if (proxyAddress === 'http://0.0.0.0:0') return null
|
||||||
|
@ -228,7 +230,7 @@ export default class MysApi {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
generateSeed (length = 16) {
|
generateSeed(length = 16) {
|
||||||
const characters = '0123456789abcdef'
|
const characters = '0123456789abcdef'
|
||||||
let result = ''
|
let result = ''
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
|
|
|
@ -391,8 +391,17 @@ export default class MysInfo {
|
||||||
if (res.api === 'detail') res.retcode = 0
|
if (res.api === 'detail') res.retcode = 0
|
||||||
break
|
break
|
||||||
case 1034:
|
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}] 遇到验证码`)
|
logger.mark(`[米游社查询失败][uid:${this.uid}][qq:${this.userId}] 遇到验证码`)
|
||||||
if (!isTask) this.e.reply('米游社查询遇到验证码,请稍后再试')
|
if (!isTask) this.e.reply('米游社查询遇到验证码,请稍后再试')
|
||||||
|
}
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
if (!isTask) this.e.reply(`米游社接口报错,暂时无法查询:${res.message || 'error'}`)
|
if (!isTask) this.e.reply(`米游社接口报错,暂时无法查询:${res.message || 'error'}`)
|
||||||
|
|
Loading…
Reference in New Issue