mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 21:27:47 +00:00
typo: 代码注释
This commit is contained in:
parent
51b3908afd
commit
4c90ca5354
12 changed files with 457 additions and 139 deletions
|
|
@ -2,10 +2,12 @@ import md5 from 'md5';
|
|||
import _ from 'lodash';
|
||||
import crypto from 'crypto';
|
||||
import ZZZApiTool from './mysapi/tool.js';
|
||||
import { randomString } from '../utils/data.js';
|
||||
import MysApi from '../../genshin/model/mys/mysApi.js';
|
||||
|
||||
// const DEVICE_ID = randomString(32).toUpperCase()
|
||||
const DEVICE_NAME = randomString(_.random(1, 10));
|
||||
// const DEVICE_NAME = randomString(_.random(1, 10));
|
||||
|
||||
const game_region = [
|
||||
'prod_gf_cn',
|
||||
'prod_gf_us',
|
||||
|
|
@ -13,9 +15,14 @@ const game_region = [
|
|||
'prod_gf_jp',
|
||||
'prod_gf_sg',
|
||||
];
|
||||
|
||||
/**
|
||||
* 米游社ZZZAPI(继承自MysApi)
|
||||
*/
|
||||
export default class MysZZZApi extends MysApi {
|
||||
constructor(uid, cookie, option = {}) {
|
||||
super(uid, cookie, option, true);
|
||||
// 初始化 uid、server、apiTool
|
||||
this.uid = uid;
|
||||
this.server = this.getServer(uid);
|
||||
this.apiTool = new ZZZApiTool(uid, this.server);
|
||||
|
|
@ -30,6 +37,10 @@ export default class MysZZZApi extends MysApi {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务器
|
||||
* @returns {string}
|
||||
*/
|
||||
getServer() {
|
||||
const _uid = this.uid?.toString();
|
||||
if (_uid.length < 10) {
|
||||
|
|
@ -47,10 +58,19 @@ export default class MysZZZApi extends MysApi {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求网址
|
||||
* @param {string} type
|
||||
* @param {object} data
|
||||
* @returns {object|boolean}
|
||||
*/
|
||||
getUrl(type, data = {}) {
|
||||
// 设置设备ID
|
||||
data.deviceId = this._device;
|
||||
let urlMap = this.apiTool.getUrlMap(data);
|
||||
// 获取请求地址
|
||||
const urlMap = this.apiTool.getUrlMap(data);
|
||||
if (!urlMap[type]) return false;
|
||||
// 获取请求参数(即APITool中默认的请求参数,此参数理应是不可获取的,详细请参照 lib/mysapi/tool.js`)
|
||||
let {
|
||||
url,
|
||||
query = '',
|
||||
|
|
@ -58,7 +78,9 @@ export default class MysZZZApi extends MysApi {
|
|||
noDs = false,
|
||||
dsSalt = '',
|
||||
} = urlMap[type];
|
||||
// 如果有query,拼接到url上
|
||||
if (query) url += `?${query}`;
|
||||
// 如果传入了 query 参数,将 query 参数拼接到 url 上
|
||||
if (data.query) {
|
||||
let str = '';
|
||||
for (let key in data.query) {
|
||||
|
|
@ -77,19 +99,22 @@ export default class MysZZZApi extends MysApi {
|
|||
url += `?${str}`;
|
||||
}
|
||||
}
|
||||
// 写入 body
|
||||
if (body) body = JSON.stringify(body);
|
||||
|
||||
// 获取请求头
|
||||
let headers = this.getHeaders(query, body);
|
||||
if (data.deviceFp) {
|
||||
headers['x-rpc-device_fp'] = data.deviceFp;
|
||||
// 兼容喵崽
|
||||
this._device_fp = { data: { device_fp: data.deviceFp } };
|
||||
}
|
||||
// 写入 cookie
|
||||
headers.cookie = this.cookie;
|
||||
|
||||
// 写入设备ID
|
||||
if (this._device) {
|
||||
headers['x-rpc-device_id'] = this._device;
|
||||
}
|
||||
// 写入DS
|
||||
switch (dsSalt) {
|
||||
case 'web': {
|
||||
headers.DS = this.getDS2();
|
||||
|
|
@ -106,6 +131,7 @@ export default class MysZZZApi extends MysApi {
|
|||
} else {
|
||||
headers.DS = this.getDs(query, body);
|
||||
}
|
||||
// 如果不需要 DS,删除 DS
|
||||
if (noDs) {
|
||||
delete headers.DS;
|
||||
if (this._device) {
|
||||
|
|
@ -115,9 +141,16 @@ export default class MysZZZApi extends MysApi {
|
|||
}
|
||||
}
|
||||
logger.debug(`[mysapi]请求url:${url}`);
|
||||
// 返回请求参数
|
||||
return { url, headers, body };
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取DS
|
||||
* @param {string} q
|
||||
* @param {string} b
|
||||
* @returns {string}
|
||||
*/
|
||||
getDs(q = '', b = '') {
|
||||
let n = '';
|
||||
if (['prod_gf_cn'].includes(this.server)) {
|
||||
|
|
@ -125,19 +158,29 @@ export default class MysZZZApi extends MysApi {
|
|||
} else {
|
||||
n = 'okr4obncj8bw5a65hbnn5oo6ixjc3l9w';
|
||||
}
|
||||
let t = Math.round(new Date().getTime() / 1000);
|
||||
let r = Math.floor(Math.random() * 900000 + 100000);
|
||||
let DS = md5(`salt=${n}&t=${t}&r=${r}&b=${b}&q=${q}`);
|
||||
const t = Math.round(new Date().getTime() / 1000);
|
||||
const r = Math.floor(Math.random() * 900000 + 100000);
|
||||
const DS = md5(`salt=${n}&t=${t}&r=${r}&b=${b}&q=${q}`);
|
||||
return `${t},${r},${DS}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取DS2
|
||||
* @returns {string}
|
||||
*/
|
||||
getDS2() {
|
||||
let t = Math.round(new Date().getTime() / 1000);
|
||||
let r = randomString(6);
|
||||
let sign = md5(`salt=BIPaooxbWZW02fGHZL1If26mYCljPgst&t=${t}&r=${r}`);
|
||||
const t = Math.round(new Date().getTime() / 1000);
|
||||
const r = randomString(6);
|
||||
const sign = md5(`salt=BIPaooxbWZW02fGHZL1If26mYCljPgst&t=${t}&r=${r}`);
|
||||
return `${t},${r},${sign}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求头
|
||||
* @param {string} query
|
||||
* @param {string} body
|
||||
* @returns {object}
|
||||
*/
|
||||
getHeaders(query = '', body = '') {
|
||||
const cn = {
|
||||
app_version: '2.63.1',
|
||||
|
|
@ -191,7 +234,7 @@ export default class MysZZZApi extends MysApi {
|
|||
return false;
|
||||
}
|
||||
this.e = e;
|
||||
this.e.isSr = true;
|
||||
this.e.isZZZ = true;
|
||||
res.retcode = Number(res.retcode);
|
||||
switch (res.retcode) {
|
||||
case 0:
|
||||
|
|
@ -255,20 +298,3 @@ export default class MysZZZApi extends MysApi {
|
|||
return _data.data;
|
||||
}
|
||||
}
|
||||
|
||||
export function randomString(length) {
|
||||
let randomStr = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
randomStr += _.sample('abcdefghijklmnopqrstuvwxyz0123456789');
|
||||
}
|
||||
return randomStr;
|
||||
}
|
||||
|
||||
export function generateSeed(length = 16) {
|
||||
const characters = '0123456789abcdef';
|
||||
let result = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += characters[Math.floor(Math.random() * characters.length)];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue