diff --git a/CHANGELOG.md b/CHANGELOG.md index fe0aa23..d27bc64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 1.2.8 * 增加`#原神充值` 原神离线充值 * 增加`#商品列表` +* 增加`#订单查询` # 1.2.7 * 增加`#扫码登录`支持扫码获取sk以及ck * 增加`#账号密码登录`支持获取sk以及ck diff --git a/apps/mhyTopUpLogin.js b/apps/mhyTopUpLogin.js index 30798a7..028eefb 100644 --- a/apps/mhyTopUpLogin.js +++ b/apps/mhyTopUpLogin.js @@ -22,7 +22,7 @@ export const rule = { }, payOrder: { /** 命令正则匹配 */ - reg: '^#?((原神(微信)?充值(微信)?(.*))|(商品列表)|(订单查询))$', + reg: '^#?((原神(微信)?充值(微信)?(.*))|((商品|充值)列表)|((订单|查询)(订单|查询)(.*)))$', /** 执行方法 */ describe: '原神充值(离线)' } @@ -31,12 +31,10 @@ export const rule = { export async function payOrder(e, { render }) { let Mys = new mys(e) - if (/商品列表/.test(e.msg)) { + if (/(商品|充值)列表/.test(e.msg)) { return await Mys.showgoods( { render }) - } else if (/订单查询/.test(e.msg)) { - //容我摆烂会 - e.reply('作者还在咕咕咕~~~~') - //return await Mys.checkOrder() + } else if (/(订单|查询)(订单|查询)/.test(e.msg)) { + return await Mys.checkOrder() } else if (e.msg.includes('充值')) { return await Mys.GetCode({ render }) } diff --git a/model/mhyTopUpLogin.js b/model/mhyTopUpLogin.js index 9070fb6..121f6ff 100644 --- a/model/mhyTopUpLogin.js +++ b/model/mhyTopUpLogin.js @@ -9,7 +9,9 @@ export default class mysTopLogin { //消息提示以及风险警告 this.sendMsgUser = `免责声明:您将通过扫码完成获取米游社sk以及ck。\n本Bot将不会保存您的登录状态。\n我方仅提供米游社查询及相关游戏内容服务,若您的账号封禁、被盗等处罚与我方无关。\n害怕风险请勿扫码~` this.sendMsgUserPassLogin = `免责声明:您将通过密码完成获取米游社sk以及ck。\n本Bot将不会保存您的账号和密码。\n我方仅提供米游社查询及相关游戏内容服务,若您的账号封禁、被盗等处罚与我方无关。\n害怕风险请勿发送账号密码~` - this.sendMagPay = `格式参考:#原神充值 6(商品ID)\n可通过【#商品列表】获取可操作商品` + this.sendMsgPay = `格式参考:#原神充值 6(商品ID)\n可通过【#商品列表】获取可操作商品` + this.sendMsgOrderReg = `消息格式无法识别,格式参考:#订单查询16347*****(订单号),100000000(uid)` + this.keys = `xiaoyao:payOrder` } async init() { this.user = new User(this.e) @@ -142,31 +144,28 @@ export default class mysTopLogin { // let msg = ['当前支持的商品有:\n'] for (const [i, goods] of Object.entries(goodslist)) { if (i == 'api') continue; - goods.num = `${goods['goods_name']}×${(goods['goods_unit'])}` + ((goods['goods_unit']) < 0 ? goods["goods_name"] : '') - // console.log(`ID:${i} ${num} 价格:${parseInt(goods['price']) / 100}元`) + goods.num = `${goods['goods_name']} × ${(goods['goods_unit'] * 1 == 0 ? '1' : goods['goods_unit'])} ` + ((goods['goods_unit']) < 0 ? goods["goods_name"] : '') goods.index = i - // goods.msg =`ID:${i} ${num} 价格:${parseInt(goods['price']) / 100}元\n` } - let r = await Common.render(`pay/goods`, { + return await Common.render(`pay/goods`, { goodslist }, { e: this.e, render, - scale: 1.2, retMsgId: true + scale: 1.2, }) - return true; } async GetCode({ render }) { try { let msg = this.e.msg.replace(/,|,|\|/g, ' ').split(' ') if (msg.length != 2) { - this.e.reply(this.sendMagPay) + this.e.reply(this.sendMsgPay) return true; } let iswx = msg[0].includes('微信') ? 'weixin' : 'alipay' if (msg[1].length != 1) { - this.e.reply(this.sendMagPay) + this.e.reply(this.sendMsgPay) return true; } let goods = (await this.goodsList())[msg[1]] @@ -174,11 +173,17 @@ export default class mysTopLogin { this.e.reply('请先 #绑定cookie') return true; } + let redisData = await utils.redisGet(this.e.uid, "payOrder") + if (redisData) { + this.e.reply(`uid:${this.e.uid},已有充值订单存在,请五分钟后再创建新充值订单`) + return true + } let ckData = await utils.getCookieMap(this.e.cookie) let device_id = utils.randomString(4) + let region = utils.getServer(this.e.uid) let order = { - "account": ckData?.get('ltuid') || ckData.get('account_id'), - "region": utils.getServer(this.e.uid), + "account": ckData?.get('ltuid') || ckData?.get('account_id'), + "region": region, "uid": this.e.uid, "delivery_url": "", "device": device_id, @@ -207,7 +212,6 @@ export default class mysTopLogin { //记录操作日志 logger.mark(`当前操作用户:${this.e.user_id},操作uid:${this.e.uid},操作商品id:${goods?.goods_id},操作商品:${goods?.goods_name + (Number(goods.goods_unit) > 0 ? "×" + goods.goods_unit : "")}`) logger.mark(`支付链接:${res['data']['encode_order']}\n订单号:${res['data']['order_no']}\n 价格:${(res['data']['amount']) / 100}元`) - //待定,等周末再咕 let r = await Common.render(`pay/index`, { url: res.data.encode_order, data: res.data, uid: this.e.uid, @@ -217,6 +221,7 @@ export default class mysTopLogin { render, scale: 1.2, retMsgId: true }) + await utils.redisSet(this.e.uid, "payOrder", { uid: this.e.uid, oId: res?.data?.order_no, message_id: r.message_id, region }, 300) return true } catch (error) { console.log(error) @@ -233,26 +238,71 @@ export default class mysTopLogin { } return goods?.data?.goods_list; } + + async GetPayData(key, value) { + let keys = await redis.keys(`${this.keys}:*`) + if (keys.length == 0) { + return '' + } + let redisKays = await redis.mGet(keys) + for (const i of redisKays) { + let item = JSON.parse(i) + if (item[key] == value) { + return item + } + } + return '' + } + async checkOrder() { - let msg, uid, order_no - if (!this.e.source) { - msg = this.e.msg.match(/\d{9,}/g) - uid = msg[0], order_no = msg[1] - } else { - msg = this.e.source.message.match(/\d{9,}/g) - uid = msg[0], order_no = msg[1] + try { + let msg, data = await this.user.getCookie(this.e), redisData = await utils.redisGet(data.uid, "payOrder") + if (this.e.source) { + // 获取原消息 + let source + if (this.e.isGroup) { + source = (await this.e.group.getChatHistory(this.e.source.seq, 1)).pop() + } else { + source = (await this.e.friend.getChatHistory(this.e.source.time, 1)).pop() + } + if (source) { + redisData = await this.GetPayData('message_id', source.message_id) + } + } else { + msg = this.e.msg.match(/\d{9,}/g) + if (msg?.length == 2) { + let data; + if (msg[0].length > 9 && msg[1].length == 9) { + data = { uid: msg[1], oId: msg[0] } + } else if (msg[1].length > 9 && msg[0].length == 9) { + data = { uid: msg[0], oId: msg[1] } + } else { + this.e.reply(this.sendMsgOrderReg) + return true + } + redisData = data + } + } + if (!redisData?.uid) { + this.e.reply(`uid:${data.uid},未查询到充值订单`) + return true + } + let res = await this.user.getData('checkOrder', { + uid: redisData.uid, order_no: redisData.oId + }, false) + if (!res) return false; + if (res?.data?.status == 1) { + this.e.reply(`uid:${redisData.uid}\n商品:${res?.data?.goods_title} x ${res?.data?.goods_num}\n订单:${redisData.oId}等待支付中`) + } else if (res?.data?.status == 999) { + this.e.reply(`uid:${redisData.uid}\n商品:${res?.data?.goods_title} x ${res?.data?.goods_num}\n订单:${redisData.oId}已支付完成`) + } else { + this.e.reply(`订单:${redisData.oId},${res.message}`) + } + return true + } catch (error) { + console.log('查询订单异常',error) + return true } - let res = await this.user.getData('checkOrder', { - uid, order_no - }, false) - if (!res) return false; - if (res?.data?.status == 1) { - this.e.reply(`uid:${uid},订单:${order_no}等待支付中`) - } else if (res?.data?.status == 999) { - this.e.reply(`uid:${uid},订单:${order_no}已支付完成`) - } else { - this.e.reply(`订单:${order_no},${res.message}`) - } - return true + } } \ No newline at end of file