This commit is contained in:
bietiaop 2024-07-08 16:27:34 +08:00
parent 5d109ef51c
commit 4828a31163
11 changed files with 100 additions and 126 deletions

View file

@ -1,4 +1,3 @@
// import User from "../../xiaoyao-cvs-plugin/model/user.js";
import fetch from 'node-fetch';
import MysZZZApi from './mysapi.js';
let User;
@ -12,7 +11,7 @@ try {
* 此方法依赖逍遥插件
* @returns {Promise<void>}
*/
export async function getAuthKey(e, srUid, authAppid = 'csc') {
export async function getAuthKey(e, zzzUid, authAppid = 'csc') {
if (!User) {
throw new Error('未安装逍遥插件,无法自动刷新抽卡链接');
}
@ -21,7 +20,7 @@ export async function getAuthKey(e, srUid, authAppid = 'csc') {
await user.getCookie(e);
let ck = await user.getStoken(e.user_id);
ck = `stuid=${ck.stuid};stoken=${ck.stoken};mid=${ck.mid};`;
let api = new MysZZZApi(srUid, ck);
let api = new MysZZZApi(zzzUid, ck);
let type = 'zzzPayAuthKey';
switch (authAppid) {
case 'csc': {

View file

@ -5,13 +5,19 @@ import crypto from 'crypto';
import ZZZApiTool from './mysapi/tool.js';
// const DEVICE_ID = randomString(32).toUpperCase()
const DEVICE_NAME = randomString(_.random(1, 10));
const game_region = [
'prod_gf_cn',
'prod_gf_cn',
'prod_gf_us',
'prod_gf_eu',
'prod_gf_jp',
'prod_gf_sg',
];
export default class MysZZZApi extends MysApi {
constructor(uid, cookie, option = {}) {
super(uid, cookie, option, true);
this.uid = uid;
this.server = this.getServer();
// this.isSr = true
// this.server = 'hkrpg_cn'
this.apiTool = new ZZZApiTool(uid, this.server);
if (typeof this.cookie != 'string' && this.cookie) {
let ck =
@ -25,23 +31,20 @@ export default class MysZZZApi extends MysApi {
}
getServer() {
switch (String(this.uid).slice(0, -8)) {
case '1':
case '2':
return 'prod_gf_cn'; // 官服
case '5':
return 'prod_qd_cn'; // B服
case '6':
return 'prod_official_usa'; // 美服
case '7':
return 'prod_official_euro'; // 欧服
case '8':
case '18':
return 'prod_official_asia'; // 亚服
case '9':
return 'prod_official_cht'; // 港澳台服
const _uid = this.uid.toString();
if (_uid.length < 10) {
return game_region[this.game][0]; // 官服
}
switch (_uid.slice(0, -8)) {
case '10':
return game_region[this.game][2]; // 美服
case '15':
return game_region[this.game][3]; // 欧服
case '13':
return game_region[this.game][4]; // 亚服
case '17':
return game_region[this.game][5]; // 港澳台服
}
return 'prod_gf_cn';
}
getUrl(type, data = {}) {

View file

@ -74,6 +74,10 @@ export default class ZZZApiTool {
url: `${hostRecord}event/game_record_zzz/api/zzz/note`,
query: `role_id=${this.uid}&server=${this.server}`,
},
zzzIndex: {
url: `${hostRecord}event/game_record_zzz/api/zzz/index`,
query: `role_id=${this.uid}&server=${this.server}`,
},
},
};
return urlMap[this.game];

View file

@ -1,45 +1,24 @@
import MysZZZApi from './mysapi.js';
import { getCk } from './common.js';
import _ from 'lodash';
import NoteUser from '../../genshin/model/mys/NoteUser.js';
export class ZZZPlugin extends plugin {
async miYoSummerGetUid() {
const key = `ZZZ:UID:${this.e.user_id}`;
const ck = await getCk(this.e);
if (!ck) return false;
let api = new MysZZZApi('', ck);
let userData = await api.getData('zzzUser');
if (!userData?.data || _.isEmpty(userData.data.list)) return false;
userData = userData.data.list[0];
let { game_uid: gameUid } = userData;
await redis.set(key, gameUid);
await redis.setEx(
`ZZZ:userData:${gameUid}`,
60 * 60,
JSON.stringify(userData)
);
return userData;
}
async getAPI() {
let user = this.e.user_id;
let ats = this.e.message.filter(m => m.type === 'at');
if (ats.length > 0 && !e.atBot) {
user = ats[0].qq;
this.e.user_id = user;
this.User = new User(this.e);
let user = this.e;
if (this.e.at) {
user = this.e.at;
}
this.User = new NoteUser(user);
let uid = this.e.msg.match(/\d+/)?.[0];
await this.miYoSummerGetUid();
uid =
uid || (await redis.get(`ZZZ:UID:${user}`)) || this.e.user?.getUid('zzz');
uid = uid || this.User?.getUid('zzz');
if (!uid) {
await this.reply('尚未绑定uid,请发送#zzz绑定uid进行绑定');
await this.reply('uid为空米游社查询请先绑定cookie其他查询请携带uid');
return false;
}
const ck = await getCk(this.e);
if (!ck || Object.keys(ck).filter(k => ck[k].ck).length === 0) {
await this.reply('尚未绑定cookie请先使用逍遥插件绑定cookie');
await this.reply('尚未绑定cookie请先绑定cookie');
return false;
}