MCPcopy Create free account
hub / github.com/chavyleung/scripts / getPackInfo

Function getPackInfo

zsfc/zsfc.js:688–733  ·  view source on GitHub ↗

* @description 掌飞购物相关函数,获取点券和消费券信息 * @param {string} argument - 余额状态,可选值为 "before" 或 "after" * @returns {Promise } - 包含点券和消费券数量的对象,或者在获取失败时返回 false

(argument)

Source from the content-addressed store, hash-verified

686 * @returns {Promise<object|false>} - 包含点券和消费券数量的对象,或者在获取失败时返回 false
687 */
688async function getPackInfo(argument) {
689 // 创建一个空对象,用于存储点券和消费券信息
690 let result = {};
691
692 // 根据参数值设置状态文本
693 const statu = (argument === "before") ? "当前" : "剩余";
694
695 // 构建请求体
696 const options = {
697 url: `https://bang.qq.com/app/speed/mall/main2?${$.queryStr({
698 'areaId': $.read(`zsfc_areaId`),
699 'accessToken': $.read(`zsfc_accessToken`),
700 'token': $.read(`zsfc_token`),
701 'uin': $.read(`zsfc_uin`),
702 'userId': $.read(`zsfc_userId`),
703 })}`
704 };
705
706 // 输出日志,表示开始获取点券和消费券
707 if (statu === "before") $.log(`🧑‍💻 开始获取${statu}点券和消费券`);
708
709 // 返回一个 Promise 对象,用于异步操作
710 return new Promise(resolve => {
711 // 发送 GET 请求,获取点券和消费券信息
712 $.get(options, (err, resp, data) => {
713 if (data) {
714 // 将响应数据转换为字符串
715 const body = data.toString();
716
717 // 使用正则表达式匹配点券和消费券数量
718 money = body.match(/<b id="super_money">(\d+)<\/b>/)[1];
719 coupons = body.match(/<b id="coupons">(\d+)<\/b>/)[1];
720
721 // 将点券和消费券数量存储在结果对象中
722 result.money = Number(money);
723 result.coupons = Number(coupons);
724 } else {
725 // 如果获取失败,将结果对象设置为 false
726 result = false;
727 }
728
729 // 解析 Promise,将结果对象传递给 resolve 函数
730 resolve(result);
731 });
732 });
733}
734
735/**
736 * @description 掌飞购物相关函数,购买道具

Callers 1

zsfc.jsFile · 0.85

Calls 3

queryStrMethod · 0.45
logMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected