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

Function purchaseItem

zsfc/zsfc.js:743–789  ·  view source on GitHub ↗

* @description 掌飞购物相关函数,购买道具 * @param {string} name - 道具名称 * @param {number} count - 购买数量 * @param {string} id - 道具的唯一标识符 * @param {string} idx - 道具的价格索引 * @returns {Promise } - 返回成功购买的道具数量

(name, count, id, idx)

Source from the content-addressed store, hash-verified

741 * @returns {Promise<number>} - 返回成功购买的道具数量
742 */
743async function purchaseItem(name, count, id, idx) {
744 // 构建请求体
745 const options = {
746 url: `https://bang.qq.com/app/speed/mall/getPurchase`,
747 headers: {
748 "Referer": `https://bang.qq.com/app/speed/mall/detail2`
749 },
750 body: $.queryStr({
751 'areaId': $.read(`zsfc_areaId`),
752 'token': $.read(`zsfc_token`),
753 'userId': $.read(`zsfc_userId`),
754 'uin': $.read(`zsfc_uin`),
755 'pay_type': "1",
756 'commodity_id': id,
757 'price_idx': idx
758 })
759 };
760
761 // 返回一个 Promise 对象,用于异步操作
762 return new Promise(resolve => {
763 // 发送 POST 请求,购买道具
764 $.post(options, (err, resp, data) => {
765 if (data) {
766 // 将响应数据转换为对象
767 const body = $.toObj(data);
768
769 // 提取响应中的消息
770 const msg = body.msg;
771
772 // 检查响应结果,如果购买失败,输出错误消息
773 if (body.res == -1) {
774 $.log(`❌ ${msg}`);
775 } else {
776 // 如果购买成功,将成功购买的道具数量设置为购买数量
777 totalCount = count;
778 }
779 } else {
780 // 如果发生错误,输出错误消息和错误信息
781 $.log(`❌ 购买${name}时发生错误`);
782 $.log($.toStr(err));
783 }
784
785 // 解析 Promise,将成功购买的道具数量传递给 resolve 函数
786 resolve(totalCount ? totalCount : 0);
787 });
788 });
789}
790
791/**
792 * @description 获取青龙面板令牌

Callers 1

zsfc.jsFile · 0.85

Calls 5

queryStrMethod · 0.45
postMethod · 0.45
toObjMethod · 0.45
logMethod · 0.45
toStrMethod · 0.45

Tested by

no test coverage detected