From 230cfe0d4c284612e729d5cfeefce3d140323de1 Mon Sep 17 00:00:00 2001 From: ctrlcvs <1509167646@qq.com> Date: Sat, 14 Jan 2023 22:26:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0redis=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=9C=BA=E5=88=B6=EF=BC=8C=E9=81=BF=E5=85=8D=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E5=88=B7=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/mhyTopUpLogin.js | 18 +++++++++++------- model/mys/utils.js | 12 +++++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/model/mhyTopUpLogin.js b/model/mhyTopUpLogin.js index e6c87f8..fb249c6 100644 --- a/model/mhyTopUpLogin.js +++ b/model/mhyTopUpLogin.js @@ -1,10 +1,5 @@ import User from "./user.js"; -import fs from "fs"; -import { - isV3 -} from '../components/Changelog.js' import utils from './mys/utils.js'; -import gsCfg from './gsCfg.js'; import { segment } from 'oicq' export default class mysTopLogin { constructor(e) { @@ -19,6 +14,11 @@ export default class mysTopLogin { } // async qrCodeLogin() { + let RedisData=await utils.redisGet(this.e.user_id,"GetQrCode") + if(RedisData){ + this.e.reply([segment.at(this.e.user_id),`前置二维码未扫描,请勿重复触发指令`]) + return false; + } this.device = await utils.randomString(64) this.e.reply(this.sendMsgUser) let res = await this.user.getData("qrCodeLogin", { @@ -31,21 +31,25 @@ export default class mysTopLogin { return res } async GetQrCode(ticket) { + await utils.redisSet(this.e.user_id,"GetQrCode",{GetQrCode:1},60*5) //设置5分钟缓存避免重复触发 let res; + let RedisData=await utils.redisGet(this.e.user_id,"GetQrCode") for (let n = 1; n < 60; n++) { await utils.sleepAsync(5000) res = await this.user.getData("qrCodeQuery", { device: this.device, ticket }) - if (res?.data?.stat == "Scanned") { + if (res?.data?.stat == "Scanned"&&RedisData.GetQrCode==1) { Bot.logger.mark(`[米哈游登录] ${Bot.logger.blue(JSON.stringify(res))}`) await this.e.reply("二维码已扫描,请确认登录", true) + RedisData.GetQrCode++; } if (res?.data?.stat == "Confirmed") { Bot.logger.mark(`[米哈游登录] ${Bot.logger.blue(JSON.stringify(res))}`) break } } + await redisDel(this.e.user_id,'GetQrCode') if (!res?.data?.payload?.raw) { await this.e.reply("验证超时", true) return false @@ -86,7 +90,7 @@ export default class mysTopLogin { this.e.reply('接口效验失败,请重新尝试~') return false } - let validate=vlData.geetest_validate + let validate = vlData.geetest_validate let aigis = res.aigis_data.session_id + ";" + Buffer.from(JSON.stringify({ geetest_challenge: vlData?.geetest_challenge, geetest_seccode: validate + "|jordan", diff --git a/model/mys/utils.js b/model/mys/utils.js index e921781..972cdb0 100644 --- a/model/mys/utils.js +++ b/model/mys/utils.js @@ -1,5 +1,5 @@ import _ from 'lodash'; - +import moment from 'moment'; export async function sleepAsync(sleepms) { return new Promise((resolve, reject) => { setTimeout(() => { @@ -21,9 +21,11 @@ export function randomString(length, os = false) { } return randomStr; } - +export async function redisDel(userId, type = 'bbs') { + return await redis.del(`xiaoyao:${type}:${userId}`) +} export async function redisGet(userId, type = 'bbs') { - await redis.get(`xiaoyao:${type}:${userId}`); + return JSON.parse(await redis.get(`xiaoyao:${type}:${userId}`)) } export async function redisSet(userId="all", type = 'bbs', data, time=0) { var time = moment(Date.now()).add('days', 1).format('YYYY-MM-DD 00:00:00') @@ -31,7 +33,7 @@ export async function redisSet(userId="all", type = 'bbs', data, time=0) { if (time!==0) { new_date = time } - await redis.set(`xiaoyao:${type}:${userId}`, JSON.stringify(data), { + return await redis.set(`xiaoyao:${type}:${userId}`, JSON.stringify(data), { EX: parseInt(new_date) }); } @@ -121,7 +123,7 @@ export function recallMsg(e,r,times){ export default { - sleepAsync, + sleepAsync,redisDel, getServer, randomSleepAsync, replyMake,