2504 lines
109 KiB
TypeScript
2504 lines
109 KiB
TypeScript
import { MiniGameSdk } from "../../Sdk/MiniGameSdk";
|
||
import { normalizePass, mergePassInfo, legacyPassInfo, legacyExperience, passTier, PASS_PERIOD } from '../Config/BattlePassModel';
|
||
import { settlementRewards, settlementClaimFlags } from '../Config/BattlePassSettlementModel';
|
||
import BattlePassSettlementCheck from '../Config/BattlePassSettlementCheck';
|
||
import ClientUpdate from '../Config/ClientUpdate';
|
||
import ServerEnvironment from '../Config/ServerEnvironment';
|
||
//#region 测试
|
||
/** 测试 */
|
||
export default class Utils {
|
||
private static coinSaveTail: Promise<any> = Promise.resolve();
|
||
private static pendingRequests = new Set<Promise<void>>();
|
||
private static wucaiPreparation: Promise<void> = null;
|
||
private static wucaiUnconfirmedWrites = new Map<string, any>();
|
||
private static wucaiPreparationVersion = 0;
|
||
private static wucaiRequestsBlocked = false;
|
||
private static serverSwitchPreparation: Promise<void> = null;
|
||
private static serverSwitchVersion = 0;
|
||
private static serverSwitchBlocked = false;
|
||
|
||
/** Drain old-server saves (including nested callbacks) before persisting a new choice. */
|
||
static prepareServerSwitch(): Promise<void> {
|
||
if (this.wucaiPreparation || ClientUpdate.blocked) return Promise.reject(new Error("正在处理游戏进度或更新,请稍后重试"));
|
||
if (this.serverSwitchPreparation) return this.serverSwitchPreparation;
|
||
const version = this.serverSwitchVersion;
|
||
let timer: any;
|
||
const drain = async () => {
|
||
while (true) {
|
||
const tail = this.coinSaveTail;
|
||
await Promise.all([...Array.from(this.pendingRequests), tail]);
|
||
await new Promise(resolve => setTimeout(resolve, 0));
|
||
if (version !== this.serverSwitchVersion) throw new Error("切换已取消");
|
||
if (ClientUpdate.blocked) throw new Error("请先完成游戏更新");
|
||
if (this.pendingRequests.size || tail !== this.coinSaveTail) continue;
|
||
if (this.wucaiUnconfirmedWrites.size) throw new Error("有存档尚未确认保存成功,请重试保存后再切换");
|
||
this.serverSwitchBlocked = true;
|
||
return;
|
||
}
|
||
};
|
||
this.serverSwitchPreparation = Promise.race([
|
||
drain(),
|
||
new Promise<void>((_, reject) => {
|
||
timer = setTimeout(() => reject(new Error("等待存档超时,本次未切换服务器")), 10000);
|
||
}),
|
||
]).then(() => { clearTimeout(timer); }, error => {
|
||
clearTimeout(timer);
|
||
this.cancelServerSwitch();
|
||
throw error;
|
||
});
|
||
return this.serverSwitchPreparation;
|
||
}
|
||
|
||
static cancelServerSwitch(): void {
|
||
this.serverSwitchVersion++;
|
||
this.serverSwitchPreparation = null;
|
||
this.serverSwitchBlocked = false;
|
||
}
|
||
|
||
/** The caller blocks input while existing saves and their callbacks finish. */
|
||
static prepareWucaiTransfer(): Promise<void> {
|
||
if (this.serverSwitchPreparation) return Promise.reject(new Error("正在切换服务器"));
|
||
if (this.wucaiPreparation) return this.wucaiPreparation;
|
||
const version = this.wucaiPreparationVersion;
|
||
this.wucaiPreparation = (async () => {
|
||
while (true) {
|
||
const coinTail = this.coinSaveTail;
|
||
await Promise.all([...Array.from(this.pendingRequests), coinTail]);
|
||
// Request callbacks can continue through several nested Promise handlers.
|
||
await new Promise(resolve => setTimeout(resolve, 0));
|
||
if (version !== this.wucaiPreparationVersion) throw { code: 0, msg: "进度选择准备已取消" };
|
||
if (this.pendingRequests.size || coinTail !== this.coinSaveTail) continue;
|
||
if (this.wucaiUnconfirmedWrites.size) throw this.wucaiUnconfirmedWrites.values().next().value;
|
||
this.wucaiRequestsBlocked = true;
|
||
return;
|
||
}
|
||
})().catch(error => {
|
||
if (version === this.wucaiPreparationVersion) this.cancelWucaiTransferPreparation();
|
||
throw error;
|
||
});
|
||
return this.wucaiPreparation;
|
||
}
|
||
|
||
static cancelWucaiTransferPreparation(): void {
|
||
this.wucaiPreparationVersion++;
|
||
this.wucaiPreparation = null;
|
||
this.wucaiRequestsBlocked = false;
|
||
}
|
||
|
||
private static trackWucaiRequest(path: string, body: any, callback): ((response: any) => void) | null {
|
||
if (ClientUpdate.blocked) {
|
||
// Do not start another transport or recursively invoke callers' retry handlers.
|
||
setTimeout(() => callback(ClientUpdate.blockedResponse), 0);
|
||
return null;
|
||
}
|
||
if (this.serverSwitchBlocked) {
|
||
setTimeout(() => callback({ code: 0, data: null, errorCode: "SERVER_SWITCHING", msg: "正在重启切换服务器" }), 0);
|
||
return null;
|
||
}
|
||
if (this.wucaiRequestsBlocked && path !== "login" && path !== "wucaiTransfer") {
|
||
callback({ code: 0, data: null, errorCode: "WUCAI_PREPARING", msg: "正在准备选择游戏进度" });
|
||
return null;
|
||
}
|
||
const action = body && body.action;
|
||
const entryRequest = path === "login" || path === "wucaiTransfer";
|
||
const save = !entryRequest && (action === "save" || action === "save_reward");
|
||
// These no-action endpoints were checked against their server implementations.
|
||
const readOnly = action === "read" || action === "info" || [
|
||
"getRank", "getSRank", "getAddressRank", "getAddressRankOther", "getAddressRankSelf",
|
||
"getUserInfoByID", "getShareLv", "getHeadInfo", "getFilm", "activityConfig/list",
|
||
].indexOf(path) >= 0;
|
||
const mayWrite = !entryRequest && !readOnly;
|
||
const writeKey = JSON.stringify([path, ...["uid", "action", "propType", "runId", "stage", "end", "outTradeNo", "requestId"]
|
||
.map(key => body && body[key])]);
|
||
let resolve: () => void;
|
||
const request = new Promise<void>(done => { resolve = done; });
|
||
this.pendingRequests.add(request);
|
||
return response => {
|
||
response = ClientUpdate.handleResponse(response);
|
||
const uncertain = !response || response.networkError || response.errorCode === "NETWORK_UNKNOWN";
|
||
if ((save || mayWrite) && response && response.code === 1) {
|
||
this.wucaiUnconfirmedWrites.delete(writeKey);
|
||
} else if ((save && (!response || response.code !== 1)) || (mayWrite && uncertain)) {
|
||
this.wucaiUnconfirmedWrites.set(writeKey, response || { code: 0, msg: "存档保存结果未确认,请重试" });
|
||
}
|
||
try { callback(response); }
|
||
finally { this.pendingRequests.delete(request); resolve(); }
|
||
};
|
||
}
|
||
|
||
/** Serialize activity delivery with ordinary wallet uploads; capture balances inside the queue. */
|
||
static withCoinSave<T>(work: () => Promise<T>): Promise<T> {
|
||
const result = this.coinSaveTail.then(work);
|
||
this.coinSaveTail = result.catch(() => undefined);
|
||
return result;
|
||
}
|
||
static serverUrl(): string {
|
||
return this.apiBaseUrl();
|
||
}
|
||
/** JSON is required by goldMiner and its nested victory payload. */
|
||
static POSTJSON(path: string, body: any, callback: (response: any) => void, authenticated = true) {
|
||
callback = this.trackWucaiRequest(path, body, callback);
|
||
if (!callback) return;
|
||
let xhr;
|
||
try { xhr = cc.loader.getXMLHttpRequest(); }
|
||
catch (_) {
|
||
callback({ code: 0, data: null, errorCode: "NETWORK_UNKNOWN", msg: "请求未能发出" });
|
||
return;
|
||
}
|
||
let done = false;
|
||
const finish = response => { if (!done) { done = true; callback(response); } };
|
||
const fail = (reason: string) => finish({
|
||
|
||
code: 0, data: null, errorCode: 'NETWORK_UNKNOWN',
|
||
transportReason: reason, httpStatus: xhr.status || 0,
|
||
msg: path + ':' + reason + ',保存结果未确认,请先核对'
|
||
|
||
});
|
||
xhr.onerror = () => fail('网络连接失败');
|
||
xhr.ontimeout = () => fail('请求超时(10秒)');
|
||
xhr.onabort = () => fail('请求被中断');
|
||
xhr.onreadystatechange = () => {
|
||
if (xhr.readyState !== 4) return;
|
||
if (xhr.status < 200 || xhr.status >= 300) { fail('HTTP ' + (xhr.status || 0)); return; }
|
||
if (!xhr.responseText || !xhr.responseText.trim()) { fail('服务器返回空内容(HTTP ' + xhr.status + ')'); return; }
|
||
let response;
|
||
try { response = JSON.parse(xhr.responseText); } catch (_) { fail('服务器返回非JSON内容'); return; }
|
||
if (!response || typeof response !== 'object') { fail('服务器返回无效数据'); return; }
|
||
finish(response);
|
||
};
|
||
try {
|
||
xhr.open('POST', this.serverUrl() + path, true);
|
||
xhr.timeout = 10000;
|
||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||
const payload = { ...body, version: cc.fx.GameConfig.GM_INFO.version };
|
||
xhr.send(JSON.stringify(authenticated ? { ...payload, token: cc.fx.GameConfig.GM_INFO.token } : payload));
|
||
} catch (_) { fail('请求未能发出'); }
|
||
}
|
||
static uid: string = "";
|
||
static session_key = "";
|
||
static appid: string = "";
|
||
static openid: string = "";
|
||
static outTradeNo: string = "";
|
||
// static httpip: string = `https://laf.nika4games.com/`; //五彩消消乐
|
||
static httpip: string = `https://q6rvwvtnga.sealoshzh.site/`; //消消王者
|
||
static testHttpip: string = `https://sor779u2w8.sealoshzh.site/`; //测试服务器
|
||
// static testHttpip: string = `https://q6rvwvtnga.sealoshzh.site/`; //消消王者测试服暂替
|
||
//#region 安卓支付
|
||
/**获取用户信息*/
|
||
static getUserInfo(callBack, from?: string, wucaiEntryId = "") {
|
||
//微信登录
|
||
if (MiniGameSdk.isWechat()) {
|
||
//@ts-ignore
|
||
wx.login({
|
||
success(res) {
|
||
console.log("微信login成功");
|
||
let restart = 0;
|
||
//console.log(res.code);
|
||
if (res.code) {
|
||
// 标志位,用于记录 callBack 是否已经被调用
|
||
let isCallBackCalled = false;
|
||
// 定义轮询函数
|
||
const pollLogin = () => {
|
||
if (isCallBackCalled || ClientUpdate.blocked) {
|
||
console.log("回调已被调用,不再发起请求");
|
||
return;
|
||
}
|
||
let isDebug = false;
|
||
let test = cc.fx.GameTool.getWechatGameVersion();
|
||
if (test == "正式版") {
|
||
isDebug = true;
|
||
}
|
||
console.log("___________发起登录请求", isDebug);
|
||
const loginData: any = {
|
||
code: res.code,
|
||
isDebug: isDebug,
|
||
distinctId: cc.fx.GameConfig.GM_INFO.shushu_DistinctId,
|
||
wucai_capability: 2,
|
||
passVersion: 2,
|
||
};
|
||
if (from === "wucai") {
|
||
loginData.from = from;
|
||
loginData.wucai_entry_id = wucaiEntryId;
|
||
}
|
||
Utils.POST("login", loginData, ret => {
|
||
console.log("__________请求结果:", ret);
|
||
if (!isCallBackCalled) {
|
||
isCallBackCalled = true;
|
||
if (ret.code === 1) { // 假设返回 code 为 1 表示成功
|
||
Utils.openid = ret.data.openid;
|
||
Utils.session_key = ret.data.session_key;
|
||
Utils.uid = ret.data._id;
|
||
}
|
||
callBack(ret);
|
||
}
|
||
});
|
||
// 如果回调未调用,6 秒后再次请求
|
||
if (!isCallBackCalled) {
|
||
restart++;
|
||
if (restart > 10) {
|
||
MiniGameSdk.API.showToast("网络异常,请稍后尝试重新登录");
|
||
console.log("登录失败,重试次数超过5次");
|
||
cc.fx.GameTool.trackErrorToShushu({ message: "登录失败,重试次数超过5次" })
|
||
}
|
||
setTimeout(pollLogin, 6000);
|
||
}
|
||
};
|
||
// 首次调用轮询函数
|
||
pollLogin();
|
||
} else {
|
||
console.log('登录失败!' + res.errMsg)
|
||
callBack({ code: 0, data: { openid: "登录失败" }, message: res.errMsg });
|
||
}
|
||
}
|
||
})
|
||
}
|
||
//字节登录
|
||
else if (MiniGameSdk.isBytedance()) {
|
||
//@ts-ignore
|
||
tt.login({
|
||
success(res) {
|
||
console.log("字节login成功");
|
||
//console.log(res.code);
|
||
}
|
||
})
|
||
}
|
||
|
||
}
|
||
|
||
//#region 道具直购接口
|
||
/**道具直购接口*/
|
||
static buyProp(id, count, price, systemType, productId, callBack, passEnd?: string, starterPackRound?: number, passOfferToken?: string,
|
||
options?: { params?: any; json?: boolean; isCurrent?: () => boolean }) {
|
||
if (!/^starter_pack(?:_[2-5])?$/.test(productId)) cc.fx.GameTool.starterPackQueuedReason = "purchase";
|
||
let postName = "wx/orderPaySig";
|
||
if (systemType == "ios") {
|
||
postName = "wx/iosorderPaySig";
|
||
}
|
||
console.log("请求uid:" + Utils.uid, "请求id:" + id, "请求数量:" + count, "请求价格:" + price, "请求链接:" + postName);
|
||
Utils.POST(postName, {
|
||
uid: Utils.uid, itemid: id, itemCount: count, itemPrice: price,
|
||
...(passEnd ? { passVersion: 2, passEnd } : {}),
|
||
...(passOfferToken ? { passOfferToken } : {}),
|
||
...(starterPackRound ? { starterPackRound } : {}),
|
||
...(options?.params || {})
|
||
}, res => {
|
||
if (options?.isCurrent && !options.isCurrent()) { callBack({ err: "账号已切换" }); return; }
|
||
if (res.code == 1) {
|
||
if (options?.params?.activityType === "pyramid" && res.data.outTradeNo !== options.params.outTradeNo) {
|
||
callBack({ err: "支付订单号不一致", errCode: -1 }); return;
|
||
}
|
||
if (res.data.resumeOnly) { callBack({ err: "订单已结束", outTradeNo: res.data.outTradeNo }); return; }
|
||
Utils.outTradeNo = res.data.outTradeNo;
|
||
const passOrder = res.data.outTradeNo;
|
||
const data = {
|
||
outTradeNo: res.data.outTradeNo,
|
||
price: price,
|
||
payment_name: productId,
|
||
payment_num: 1,
|
||
type: systemType,
|
||
}
|
||
cc.fx.GameTool.shushu_Track("init_order", data);
|
||
//console.log("创建的最新订单的订单号:", Utils.outTradeNo);
|
||
// let timeoutId: number;
|
||
// const timeoutDuration = 30000; // 30 秒超时时间
|
||
// // 设置超时定时器
|
||
// timeoutId = setTimeout(() => {
|
||
// console.error('支付请求超时');
|
||
// callBack("请求支付超时");
|
||
// }, timeoutDuration);
|
||
const orderNumber = res.data.outTradeNo;
|
||
if (/^jungle_treasure_[1-8]$/.test(id)) Utils.rememberJunglePayment(orderNumber, id, price * count, false);
|
||
try {
|
||
//@ts-ignore
|
||
wx.requestMidasPaymentGameItem({
|
||
signData: res.data.signData,
|
||
paySig: res.data.paySig,
|
||
signature: res.data.signature,
|
||
success(res, errCode) {
|
||
// clearTimeout(timeoutId); // 清除超时定时器
|
||
//console.log('成功', res, errCode);
|
||
callBack({ ...res, outTradeNo: orderNumber });
|
||
},
|
||
fail({ errMsg, errCode }) {
|
||
// clearTimeout(timeoutId); // 清除超时定时器
|
||
//console.log('失败');
|
||
//console.log(errMsg, errCode)
|
||
let data = {
|
||
errMsg: errMsg,
|
||
errCode: errCode,
|
||
err: "请求支付失败",
|
||
paymentFailed: true,
|
||
outTradeNo: orderNumber,
|
||
}
|
||
callBack(data);
|
||
}
|
||
})
|
||
} catch (error) {
|
||
callBack({
|
||
err: "请求支付失败", errCode: systemType === "ios" ? 16 : -1,
|
||
paymentFailed: true, outTradeNo: orderNumber
|
||
});
|
||
}
|
||
} else {
|
||
callBack({ ...res, err: "创建订单失败", errCode: -1, errMsg: res.msg || "创建订单失败,请重试" });
|
||
}
|
||
|
||
}, { json: !!options?.json });
|
||
}
|
||
|
||
//#region 安卓获取支付结果
|
||
/** 安卓获取支付结果 */
|
||
static getPayInfo(callBack, order: string = Utils.outTradeNo,
|
||
options?: { timeoutMs: number; onProgress?: (response: any) => void }) {
|
||
// 延迟时间数组,按照 1 秒 3 次、2 秒 5 次、5 秒 6 次、15 秒 5 次的规则生成
|
||
const delays = [
|
||
...Array(3).fill(3000),
|
||
...Array(5).fill(4000),
|
||
...Array(6).fill(5000),
|
||
...Array(5).fill(15000)
|
||
];
|
||
let attempt = 0; // 轮询次数
|
||
let completed = false;
|
||
let retryTimer = null;
|
||
let deadlineTimer = null;
|
||
const finish = (response) => {
|
||
if (completed) return;
|
||
completed = true;
|
||
clearTimeout(retryTimer);
|
||
clearTimeout(deadlineTimer);
|
||
callBack(response);
|
||
};
|
||
const timeout = () => {
|
||
if (completed) return;
|
||
MiniGameSdk.API.showToast(options
|
||
? "支付结果尚未确认,请稍后重新领取"
|
||
: "网络异常,如付款成功,重进游戏可领取奖励");
|
||
finish({ code: 0, data: { pay_state: -1 }, message: '轮询超时' });
|
||
};
|
||
if (options?.timeoutMs > 0) deadlineTimer = setTimeout(timeout, options.timeoutMs);
|
||
|
||
const poll = () => {
|
||
if (completed) return;
|
||
if (attempt >= delays.length) {
|
||
timeout();
|
||
return;
|
||
}
|
||
|
||
//console.log("请求uid:", Utils.uid);
|
||
//console.log("outTradeNo:", Utils.outTradeNo);
|
||
Utils.POST("wx/getPayInfo", { uid: Utils.uid, outTradeNo: order }, res => {
|
||
if (completed) return;
|
||
if (options?.onProgress) options.onProgress(res);
|
||
if (res?.code === 1 && (res.data?.pay_state === 1 || res.data?.pay_state === 2)) {
|
||
finish(res);
|
||
} else {
|
||
attempt++;
|
||
retryTimer = setTimeout(poll, delays[attempt - 1]);
|
||
}
|
||
});
|
||
};
|
||
|
||
poll();
|
||
}
|
||
//#region 上传领取充值奖励
|
||
/**上传领取充值奖励 */
|
||
static setPayInfo(callBack, order) {
|
||
const delays = [3000, 3000, 6000, 9000, 12000, 15000, 18000, 21000];// 延迟时间数组
|
||
let attempt = 0; // 重试次数
|
||
const sendRequest = () => {
|
||
if (attempt > delays.length) {
|
||
// 达到最大重试次数,调用回调并返回错误信息
|
||
callBack({ code: 0, message: '请求失败,已达到最大重试次数' });
|
||
return;
|
||
}
|
||
let orderTemp = Utils.outTradeNo;
|
||
if (order) orderTemp = order;
|
||
//console.log("告知服务器发货的订单号:", orderTemp);
|
||
Utils.POST("wx/getOrderReward", { outTradeNo: orderTemp, uid: cc.fx.GameConfig.GM_INFO.uid }, res => {
|
||
//console.log("告知服务器发货:", res);
|
||
if (res.code === 1) {
|
||
console.log("告知服务器发货成功:", res);
|
||
// 请求成功,调用回调并返回结果
|
||
callBack(res);
|
||
} else {
|
||
// 请求失败,增加重试次数并设置下一次请求的延迟
|
||
console.log("告知服务器发货失败:", res);
|
||
attempt++;
|
||
if (attempt <= delays.length) {
|
||
setTimeout(sendRequest, delays[attempt - 1]);
|
||
} else {
|
||
callBack({ code: 0, message: '请求失败,已达到最大重试次数' });
|
||
}
|
||
}
|
||
});
|
||
};
|
||
sendRequest();
|
||
}
|
||
|
||
|
||
static createPaymentOrderNo(): string {
|
||
const normalizeUrl = (url: string) => url.replace(/\/+$/, '');
|
||
const isTest = normalizeUrl(this.apiBaseUrl()) === normalizeUrl(this.testHttpip)
|
||
&& normalizeUrl(this.testHttpip) !== normalizeUrl(this.httpip);
|
||
return (isTest ? "wct_" : "wcx_") + Math.round(Math.random() * 10 ** 13) + Date.now();
|
||
}
|
||
|
||
//#region ios支付
|
||
/**跳转客服,ios支付*/
|
||
static GoKEFu(iosPayInfo, callBack, onOrderCreated?: (order: string) => void) {
|
||
if (!/^starter_pack(?:_[2-5])?$/.test(iosPayInfo.payment_name)) cc.fx.GameTool.starterPackQueuedReason = "purchase";
|
||
console.log("创建新的订单,清空老订单");
|
||
const order = iosPayInfo.activityType === "pyramid" ? iosPayInfo.outTradeNo : this.createPaymentOrderNo();
|
||
if (!order) { callBack("fail", { err: "支付订单号缺失" }); return; }
|
||
if (iosPayInfo.payment_name == "month_Card") {
|
||
cc.fx.GameConfig.GM_INFO.iosMonthOrder = null;
|
||
cc.fx.GameConfig.GM_INFO.iosMonthOrder = order;
|
||
}
|
||
else if (/^reborn_Gift(?:_[2-5])?$/.test(iosPayInfo.payment_name)) {
|
||
cc.fx.GameConfig.GM_INFO.iosReviveOrder = null;
|
||
cc.fx.GameConfig.GM_INFO.iosReviveOrder = order;
|
||
}
|
||
else if (/^starter_pack(?:_[2-5])?$/.test(iosPayInfo.payment_name)) {
|
||
cc.fx.GameConfig.GM_INFO.iosStarterOrder = null;
|
||
cc.fx.GameConfig.GM_INFO.iosStarterOrder = order;
|
||
}
|
||
else if (/^battlepass(?:_30|_12)?$/.test(iosPayInfo.payment_name)) {
|
||
cc.fx.GameConfig.GM_INFO.iosPassCheckOrder = null;
|
||
cc.fx.GameConfig.GM_INFO.iosPassCheckOrder = order;
|
||
}
|
||
else if (iosPayInfo.activityType == "pyramid") {
|
||
// 金字塔订单由 PyramidService 自己持久化,且必须复用服务端已校验的米大师订单号。
|
||
}
|
||
else if (/^jungle_treasure_\d+$/.test(String(iosPayInfo.payment_name || ""))) {
|
||
cc.fx.GameConfig.GM_INFO.iosJungleOrder = null;
|
||
cc.fx.GameConfig.GM_INFO.iosJungleOrder = order;
|
||
Utils.rememberJunglePayment(order, iosPayInfo.payment_name, iosPayInfo.price * iosPayInfo.payment_count, true);
|
||
}
|
||
else if (/^gold_miner(?:_\d+)?$/.test(String(iosPayInfo.payment_name || ""))) {
|
||
// The activity persists its order separately; do not overwrite shop orders.
|
||
}
|
||
else if (iosPayInfo.payment_name === "StaminaPack") {
|
||
cc.fx.GameConfig.GM_INFO.iosStaminaPackOrder = order;
|
||
}
|
||
else {
|
||
cc.fx.GameConfig.GM_INFO.iosShopOrder = null;
|
||
cc.fx.GameConfig.GM_INFO.iosShopOrder = order;
|
||
}
|
||
const data = {
|
||
tpye: "ios",
|
||
outTradeNo: order,
|
||
propName: iosPayInfo.payment_name,
|
||
count: iosPayInfo.payment_count,
|
||
price: iosPayInfo.price,//价格单位是分
|
||
...(iosPayInfo.passEnd ? { passEnd: iosPayInfo.passEnd, passVersion: 2 } : {}),
|
||
...(iosPayInfo.passOfferToken ? { passOfferToken: iosPayInfo.passOfferToken } : {}),
|
||
...(iosPayInfo.starterPackRound ? { starterPackRound: iosPayInfo.starterPackRound } : {}),
|
||
...(iosPayInfo.activityType == "pyramid" ? {
|
||
activityType: "pyramid", periodId: iosPayInfo.periodId, level: iosPayInfo.level,
|
||
} : {}),
|
||
}
|
||
const shushu_data = {
|
||
outTradeNo: order,
|
||
price: iosPayInfo.price,
|
||
payment_name: iosPayInfo.payment_name,
|
||
payment_num: iosPayInfo.payment_count,
|
||
type: "ios",
|
||
}
|
||
console.log("________ios创建订单信息:", data);
|
||
cc.fx.GameTool.shushu_Track("init_order", shushu_data);
|
||
//@ts-ignore
|
||
if (onOrderCreated) onOrderCreated(order);
|
||
wx.openCustomerServiceConversation({
|
||
sessionFrom: JSON.stringify(data), // 会话来源(可选)
|
||
showMessageCard: false, // 是否展示消息卡片
|
||
success() {
|
||
callBack("success");
|
||
console.log('客服会话已successr');
|
||
},
|
||
fail(e) {
|
||
console.log('客服会话已over', e);
|
||
callBack("fail", e);
|
||
}
|
||
});
|
||
}
|
||
|
||
private static jungleRecovery: Promise<void> = null;
|
||
static junglePaymentKey(): string {
|
||
return "junglePayments:v1:" + this.apiBaseUrl() + ":" + String(cc.fx.GameConfig.GM_INFO.uid || "");
|
||
}
|
||
static rememberJunglePayment(order: string, productId: string, price: number, ios: boolean): void {
|
||
const key = this.junglePaymentKey(), orders = cc.fx.StorageMessage.getStorage(key) || {};
|
||
orders[order] = { productId, price, ios };
|
||
cc.fx.StorageMessage.setStorage(key, orders);
|
||
}
|
||
static forgetJunglePayment(order: string): void {
|
||
const key = this.junglePaymentKey(), orders = cc.fx.StorageMessage.getStorage(key) || {};
|
||
delete orders[order]; cc.fx.StorageMessage.setStorage(key, orders);
|
||
}
|
||
/** Login recovery only; the activity still reports its normal payment callbacks. */
|
||
static recoverJunglePayments(loginOrders: any[]): Promise<void> {
|
||
if (this.jungleRecovery) return this.jungleRecovery;
|
||
const key = this.junglePaymentKey(), uid = cc.fx.GameConfig.GM_INFO.uid, token = cc.fx.GameConfig.GM_INFO.token;
|
||
for (const order of loginOrders) {
|
||
if (/^jungle_treasure_[1-8]$/.test(order.itemid))
|
||
this.rememberJunglePayment(order.outTradeNo, order.itemid, Number(order.goodsPrice) * Number(order.itemCount || 1), order.type === "ios");
|
||
}
|
||
const orders = cc.fx.StorageMessage.getStorage(key) || {};
|
||
const current = () => key === this.junglePaymentKey() && token === cc.fx.GameConfig.GM_INFO.token;
|
||
this.jungleRecovery = (async () => {
|
||
for (const order of Object.keys(orders)) {
|
||
if (!current()) return;
|
||
try {
|
||
const payment = orders[order];
|
||
const query = (route: string): Promise<any> => new Promise(resolve => this.POST(route, { uid, outTradeNo: order }, resolve));
|
||
let response = await query("wx/getPayInfo");
|
||
if (!current()) return;
|
||
let paid = response?.code === 1 && response.data?.pay_state === 2;
|
||
if (!paid && payment.ios) {
|
||
response = await query("wx/iosgetPayInfo");
|
||
if (!current()) return;
|
||
paid = response?.code === 1;
|
||
}
|
||
if (!paid) continue;
|
||
const completed: any = await new Promise(resolve => this.setPayInfo(resolve, order));
|
||
if (!current()) return;
|
||
// The activity may have reported while the query was in flight.
|
||
if (completed?.code !== 1 || !(cc.fx.StorageMessage.getStorage(key) || {})[order]) continue;
|
||
if (!Number.isSafeInteger(payment.price) || payment.price <= 0) throw new Error("订单金额缺失");
|
||
MiniGameSdk.API.yinli_Pay(payment.price, order, "补发充值成功" + payment.productId);
|
||
this.forgetJunglePayment(order);
|
||
} catch (error) { console.warn("丛林宝藏付费补报待重试", order, error); }
|
||
}
|
||
})().then(() => { this.jungleRecovery = null; }, error => {
|
||
this.jungleRecovery = null; console.warn("丛林宝藏付费补报待重试", error);
|
||
});
|
||
return this.jungleRecovery;
|
||
}
|
||
|
||
//#region ios获取支付结果
|
||
/** ios获取支付结果 */
|
||
static getIosPayInfo(order, callBack) {
|
||
// 延迟 0.5 秒执行后续逻辑
|
||
setTimeout(() => {
|
||
// 最大重试次数
|
||
const maxRetries = 7;
|
||
let retryCount = 0;
|
||
// 标志位,用于记录 callBack 是否已经被调用
|
||
let isCallBackCalled = false;
|
||
|
||
const makeRequest = () => {
|
||
if (retryCount > maxRetries) {
|
||
if (!isCallBackCalled) {
|
||
MiniGameSdk.API.showToast("网络异常,如充值成功,重进游戏可领取奖励");
|
||
callBack({ code: 2, data: null, message: '轮询超时,达到最大重试次数' });
|
||
isCallBackCalled = true;
|
||
}
|
||
return;
|
||
}
|
||
|
||
// 设置超时定时器
|
||
const timeoutId = setTimeout(() => {
|
||
retryCount++;
|
||
console.log(`请求超时,第 ${retryCount} 次重新申请接口`);
|
||
makeRequest();
|
||
}, 4000);
|
||
|
||
const orderNow = order;
|
||
console.log("请求uid:" + Utils.uid);
|
||
console.log("outTradeNo:" + orderNow);
|
||
Utils.POST("wx/iosgetPayInfo", { outTradeNo: orderNow, uid: cc.fx.GameConfig.GM_INFO.uid, rebornGiftVersion: 1 }, res => {
|
||
console.log("查询字符结果IOS");
|
||
console.log(res);
|
||
// 清除超时定时器
|
||
clearTimeout(timeoutId);
|
||
if (!isCallBackCalled) {
|
||
callBack(res);
|
||
isCallBackCalled = true;
|
||
}
|
||
});
|
||
};
|
||
makeRequest();
|
||
}, 1000);
|
||
}
|
||
|
||
/** Keep public cache namespaces aligned with the actual request environment. */
|
||
static apiBaseUrl(): string {
|
||
return ServerEnvironment.current() === "test" ? this.testHttpip : this.httpip;
|
||
}
|
||
|
||
//#region POST请求
|
||
/**
|
||
* POST请求
|
||
*
|
||
* @static
|
||
* @param {*} url
|
||
* @param {object} [param={}]
|
||
* @param {*} callback
|
||
* @memberof HttpUtil
|
||
*/
|
||
public static POST(url, param: object | any, callback, options?: { json?: boolean; timeoutMs?: number }) {
|
||
callback = this.trackWucaiRequest(url, param, callback);
|
||
if (!callback) return;
|
||
let xhr;
|
||
try { xhr = cc.loader.getXMLHttpRequest(); }
|
||
catch (_) {
|
||
callback({ code: 0, data: null, networkError: true, msg: "请求未能发出" });
|
||
return;
|
||
}
|
||
xhr.timeout = options?.timeoutMs || 5000;//超时时间
|
||
let completed = false;
|
||
const finish = (response) => {
|
||
if (completed) return;
|
||
completed = true;
|
||
callback(response);
|
||
};
|
||
const networkFailure = () => finish({ code: 0, data: null, msg: "网络异常,请重试", networkError: true });
|
||
xhr.onerror = networkFailure;
|
||
xhr.ontimeout = networkFailure;
|
||
xhr.onabort = networkFailure;
|
||
let dataStr = '';
|
||
let isDebug = false;
|
||
param = { ...param, token: cc.fx.GameConfig.GM_INFO.token, version: cc.fx.GameConfig.GM_INFO.version };
|
||
let test = cc.fx.GameTool.getWechatGameVersion();
|
||
if (test == "正式版") {
|
||
isDebug = true;
|
||
}
|
||
const requestHttpip = this.apiBaseUrl();
|
||
param.isDebug = isDebug;
|
||
if (options?.json) dataStr = JSON.stringify(param);
|
||
else Object.keys(param).forEach(key => {
|
||
dataStr += key + '=' + encodeURIComponent(param[key]) + '&';
|
||
})
|
||
if (!options?.json && dataStr !== '') {
|
||
dataStr = dataStr.substr(0, dataStr.lastIndexOf('&'));
|
||
}
|
||
if (url != "getSRank" && url != "getRank") {
|
||
url = requestHttpip + url;
|
||
}
|
||
else {
|
||
url = "https://bx7gi3d4oq.sealoshzh.site/" + url;
|
||
}
|
||
|
||
|
||
if (url == requestHttpip + "getAddressRankOther") {
|
||
url = "https://laf.nika4games.com/getAddressRank";
|
||
}
|
||
else if (url == requestHttpip + "getAddressRankSelf") {
|
||
url = requestHttpip + "getAddressRank";
|
||
}
|
||
|
||
xhr.onreadystatechange = function () {
|
||
if (xhr && xhr.readyState) {
|
||
if (xhr.readyState === 4) {
|
||
let response: any = xhr.responseText;
|
||
if (xhr.status >= 200 && xhr.status < 300) {
|
||
// callback(true, JSON.parse(response));
|
||
try {
|
||
response = JSON.parse(response);
|
||
if (!response || typeof response !== "object") throw new Error("Invalid response");
|
||
} catch {
|
||
response = { data: null, code: 0, msg: "数据有误", networkError: true };
|
||
}
|
||
if (response.code == 0) {
|
||
if (response.msg === "token校验失败") {
|
||
if (MiniGameSdk) {
|
||
MiniGameSdk.API.showToast("游戏已更新,请关闭游戏重新进入");
|
||
}
|
||
}
|
||
|
||
}
|
||
finish(response);
|
||
|
||
} else {
|
||
networkFailure();
|
||
}
|
||
} else if (xhr.readyState === 4) {
|
||
callback({ code: 0, msg: "服务器未返回数据,请重试" });
|
||
}
|
||
}
|
||
|
||
};
|
||
try {
|
||
xhr.open("POST", url, true);
|
||
xhr.setRequestHeader("Content-Type", options?.json ? "application/json" : "application/x-www-form-urlencoded");
|
||
xhr.send(dataStr);
|
||
} catch (_) { networkFailure(); }
|
||
}
|
||
|
||
|
||
|
||
|
||
//#region 获取用户数据
|
||
/** 获取用户数据,包含头像昵称注册时间 */
|
||
static getUserData(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let data = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
|
||
Utils.POST("userData", data, res => {
|
||
//console.log("获得userData数据:", res);
|
||
if (res.code === 1) {
|
||
//console.log("服务器:获取用户数据成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
//console.log("服务器:获取用户数据失败", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
|
||
//#region 上传用户信息
|
||
/** 上传用户信息 */
|
||
static setUserData(data, callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
userData: JSON.stringify(data)
|
||
}
|
||
console.log("准备上传头像昵称最后一步", data);
|
||
Utils.POST("userData", setData, res => {
|
||
// console.log("获得userData数据:", res);
|
||
if (res.code === 1) {
|
||
console.log("服务器:获取用户数据成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
//console.log("服务器:获取用户数据失败", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
|
||
// useravatar:userData1.useravatar||Math.floor(Math.random()*4)+"",
|
||
// username:userData1.username||"user",
|
||
// useravatarIcon: userData1.useravatarIcon||"0",
|
||
}
|
||
|
||
}
|
||
//#region 金币,等级,道具,体力
|
||
/** 获得金币信息 */
|
||
static getUserCoin(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
Utils.POST("userCoin", setData, res => {
|
||
//console.log("获得userCoin数据:", res);
|
||
if (res.code === 1) {
|
||
//console.log("服务器:获得金币成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
//console.log("服务器:获得金币失败", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
/** 上传金币信息 */
|
||
//上传金币信息
|
||
static setUserCoin(callBack) {
|
||
const uid = cc.fx.GameConfig.GM_INFO.uid;
|
||
const server = Utils.serverUrl();
|
||
Utils.withCoinSave<void>(() => new Promise(resolve => {
|
||
if (uid !== cc.fx.GameConfig.GM_INFO.uid || server !== Utils.serverUrl()) {
|
||
resolve(); if (callBack) callBack({ code: 0, msg: '账号已切换' }); return;
|
||
}
|
||
Utils.saveUserCoinNow(response => { resolve(); if (callBack) callBack(response); });
|
||
}));
|
||
}
|
||
private static saveUserCoinNow(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
if (cc.fx.GameConfig.GM_INFO.coin <= 0 || cc.fx.GameConfig.GM_INFO.coin == undefined) {
|
||
cc.fx.GameConfig.GM_INFO.coin = 0;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
coinAmount: Math.floor(cc.fx.GameConfig.GM_INFO.coin)
|
||
}
|
||
//console.log("服务器:上传金币", Math.floor(cc.fx.GameConfig.GM_INFO.coin));
|
||
Utils.POST("userCoin", setData, res => {
|
||
//console.log("获得userCoin数据:", res);
|
||
if (res.code === 1) {
|
||
//console.log("服务器:上传金币成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
//console.log("服务器:上传金币失败", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
|
||
/** 获得关卡等级信息 */
|
||
//获得关卡等级信息
|
||
static getUserLevel(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
Utils.POST("userLevel", setData, res => {
|
||
//console.log("获得userLevel数据:", res);
|
||
if (res.code === 1) {
|
||
if (res.data && res.data.film !== undefined) {
|
||
cc.fx.GameConfig.GM_INFO.film = Number(res.data.film);
|
||
}
|
||
//console.log("服务器:获得等级成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
//console.log("服务器:获得等级失败", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
|
||
/** 上传关卡等级信息 */
|
||
//上传关卡等级信息
|
||
static setUserLevel(callBack, wuxian?, goldMiner?) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
if (cc.fx.GameConfig.GM_INFO.level <= 0 || cc.fx.GameConfig.GM_INFO.level == undefined) {
|
||
cc.fx.GameConfig.GM_INFO.level = 0;
|
||
}
|
||
|
||
let isWuxian = wuxian !== undefined ? wuxian : false; // 如果wuxian有传值则使用该值,否则默认为false
|
||
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
levelAmount: parseInt(cc.fx.GameConfig.GM_INFO.level),
|
||
isWuXian: isWuxian
|
||
}
|
||
console.log("无限值", isWuxian);
|
||
console.log('[GoldMiner通关] userLevel 请求', JSON.stringify({
|
||
url: (goldMiner ? Utils.serverUrl() : Utils.apiBaseUrl()) + 'userLevel',
|
||
action: setData.action, levelAmount: setData.levelAmount,
|
||
isWuXian: goldMiner ? (goldMiner.mode === 'endless' ? 'true' : undefined) : isWuxian,
|
||
goldMiner: goldMiner || null,
|
||
}));
|
||
const saveLevel = goldMiner
|
||
? (body, callback) => Utils.POSTJSON('userLevel', { ...body, isWuXian: goldMiner.mode === 'endless' ? 'true' : undefined, goldMiner }, callback)
|
||
: (body, callback) => Utils.POST('userLevel', body, callback);
|
||
saveLevel(setData, res => {
|
||
const activityResult = res && res.data && res.data.goldMiner;
|
||
console.log('[GoldMiner通关] userLevel 返回', JSON.stringify({
|
||
eventId: goldMiner && goldMiner.eventId,
|
||
code: res && res.code, errorCode: res && res.errorCode,
|
||
msg: res && res.msg, httpStatus: res && res.httpStatus,
|
||
transportReason: res && res.transportReason, networkError: res && res.networkError,
|
||
levelAmount: res && res.data && res.data.levelAmount,
|
||
goldMiner: activityResult ? {
|
||
code: activityResult.code, activityCounted: activityResult.activityCounted,
|
||
progressWins: activityResult.progressWins, duplicate: activityResult.duplicate,
|
||
reason: activityResult.reason, errorCode: activityResult.errorCode,
|
||
msg: activityResult.msg,
|
||
} : null,
|
||
}));
|
||
//console.log("获得userLevel数据:", res);
|
||
if (res.code === 1) {
|
||
if (res.data && res.data.film !== undefined) {
|
||
cc.fx.GameConfig.GM_INFO.film = Number(res.data.film);
|
||
}
|
||
//console.log("服务器:上传等级成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
//console.log("服务器:上传等级失败", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
/** 获得用户道具信息 */
|
||
//获得用户道具信息
|
||
static getUserProp(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
Utils.POST("userProp", setData, res => {
|
||
//console.log("获得userProp数据:", res);
|
||
if (res.code === 1) {
|
||
//console.log("服务器:获得道具成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
//console.log("服务器:获得道具失败", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
|
||
/** 上传道具信息 */
|
||
//上传道具信息
|
||
static setUserProp(propid, amount, callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = null;
|
||
if (propid == 0) {
|
||
setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
propType: propid,
|
||
propData: JSON.stringify(amount),
|
||
}
|
||
}
|
||
else {
|
||
setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
propType: propid,
|
||
propData: amount,
|
||
}
|
||
}
|
||
|
||
//console.log("上传道具类型", propid, "上传道具数量:", amount);
|
||
Utils.POST("userProp", setData, res => {
|
||
//console.log("获得userProp数据:", res);
|
||
if (res.code === 1) {
|
||
//console.log("服务器:上传道具成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
//console.log("服务器:上传道具失败", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
|
||
/** 获取体力信息 */
|
||
static getUserHealth(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
Utils.POST("userHealth", setData, res => {
|
||
//console.log("获得userHealth数据:", res);
|
||
if (res.code === 1) {
|
||
//console.log("服务器:获得体力成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
//console.log("服务器:获得体力失败", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
/** 上传体力信息 */
|
||
//上传关卡等级信息
|
||
static setUserHealth(timestamp, callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
healthAmount: cc.fx.GameConfig.GM_INFO.hp,
|
||
timestamp: timestamp
|
||
}
|
||
Utils.POST("userHealth", setData, res => {
|
||
//console.log("获得userHealth数据:", res);
|
||
if (res.code === 1) {
|
||
//console.log("服务器:上传体力成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
//console.log("服务器:上传体力失败", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//#region 无限体力相关
|
||
/** 获取无限体力信息 */
|
||
static getUserPowerTime(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
Utils.POST("userPower", setData, res => {
|
||
//console.log("获得userPower数据:", res);
|
||
if (res.code === 1) {
|
||
//console.log("服务器:获得无限体力成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
//console.log("服务器:获得无限体力失败", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
/** 上传无限体力信息 */
|
||
static setUserPowerTime(userPowerTime, callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
userPowerTime: userPowerTime
|
||
}
|
||
|
||
Utils.POST("userPower", setData, res => {
|
||
//console.log("获得userPower数据:", res);
|
||
if (res.code === 1) {
|
||
//console.log("服务器:上传无限体力成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
//console.log("服务器:上传无限体力失败", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
//#region 月卡相关
|
||
/** 获得月卡奖励信息 */
|
||
static monthGetReward(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
}
|
||
Utils.POST("monthGetReward", setData, res => {
|
||
// //console.log("获得monthGetReward数据:", res);
|
||
if (res.code === 1) {
|
||
// //console.log("服务器:领取获得monthGetReward成功'✅ ", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
// //console.log("服务器:获得monthGetReward失败'❌ ", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
/** 获得月卡信息 */
|
||
static getMonthlyCard(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
// //console.log("获取monthlyCard信息:", uid, monthCardTime);
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
|
||
Utils.POST("monthlyCard", setData, res => {
|
||
// //console.log("获得monthlyCard数据:", res);
|
||
if (res.code === 1) {
|
||
// //console.log("服务器:获取monthlyCard成功'✅ ", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
// //console.log("服务器:获取monthlyCard失败'❌ ", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
/** 上传月卡信息 */
|
||
//上传monthlyCard信息
|
||
static setMonthlyCard(monthCardTime, callBack, outTradeNo?: string) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
// //console.log("上传monthlyCard信息:", uid, monthCardTime);
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
monthCardTime: monthCardTime,
|
||
outTradeNo: outTradeNo || Utils.outTradeNo,
|
||
}
|
||
|
||
Utils.POST("monthlyCard", setData, res => {
|
||
// //console.log("获得monthlyCard数据:", res);
|
||
if (res.code === 1) {
|
||
// //console.log("服务器:上传monthlyCard成功'✅ ", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
// //console.log("服务器:上传monthlyCard失败'❌ ", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//#region 复活礼包相关
|
||
/** 是否还有复活礼包出现机会 */
|
||
static canRebonGift(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
}
|
||
|
||
Utils.POST("canRebornGift", setData, res => {
|
||
if (res.code === 1) {
|
||
//console.log("服务器:canRebonGift'✅ ", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
/** 购买复活礼包后上传 */
|
||
//上传monthlyCard信息
|
||
static rebornGift(rebornGift, callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
// //console.log("上传monthlyCard信息:", uid, monthCardTime);
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
rebornGift: rebornGift,
|
||
}
|
||
|
||
Utils.POST("rebornGift", setData, res => {
|
||
// //console.log("获得rebornGift数据:", res);
|
||
if (res.code === 1) {
|
||
//console.log("服务器:上传rebornGift成功'✅ ", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
// //console.log("服务器:上传rebornGift失败'❌ ", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//#region 分享相关
|
||
//设置分享成功信息,帮别人成功
|
||
static shareLevel(otherLevel, uid, callBack) {
|
||
let otheruid = uid || "";
|
||
let level = otherLevel || 0;
|
||
let data = {
|
||
uid: otheruid,
|
||
otherUid: cc.fx.GameConfig.GM_INFO.uid,
|
||
shareLv: level,
|
||
};
|
||
|
||
// 延迟时间数组,按照 1 秒 3 次、2 秒 5 次、5 秒 6 次、15 秒 5 次的规则生成
|
||
const delays = [
|
||
...Array(3).fill(1000),
|
||
...Array(5).fill(2000),
|
||
...Array(6).fill(5000),
|
||
...Array(5).fill(15000)
|
||
];
|
||
let attempt = 0; // 轮询次数
|
||
|
||
const poll = () => {
|
||
if (attempt >= delays.length) {
|
||
MiniGameSdk.API.showToast("网络异常,分享数据提交失败");
|
||
callBack({ code: 0, data: null, message: '轮询超时' });
|
||
return;
|
||
}
|
||
|
||
Utils.POST("shareLvSuccess", data, res => {
|
||
console.log("获得shareLvSuccess数据:", res);
|
||
if (res.code === 1) {
|
||
//console.log("服务器:分享帮助通过关卡数据成功", res);
|
||
callBack(res);
|
||
} else {
|
||
attempt++;
|
||
setTimeout(poll, delays[attempt - 1]);
|
||
}
|
||
});
|
||
};
|
||
|
||
poll();
|
||
}
|
||
|
||
/** 获取分享信息 */
|
||
//获取分享信息
|
||
static getShareLevel(callBack) {
|
||
let data = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid
|
||
};
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
Utils.POST("getShareLv", data, res => {
|
||
console.log("获得shareLvSuccess数据:", res);
|
||
if (res.code === 1) {
|
||
console.log("服务器:分享帮助通过关卡数据成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
//#region 排行榜相关
|
||
/** 获取世界排行榜 */
|
||
static getRank(callBack) {
|
||
// 最大重试次数
|
||
const maxRetries = 5;
|
||
let retryCount = 0;
|
||
// 标志位,用于记录 callBack 是否已经被调用
|
||
let isCallBackCalled = false;
|
||
const makeRequest = () => {
|
||
if (retryCount > maxRetries) {
|
||
if (!isCallBackCalled) {
|
||
MiniGameSdk.API.showToast("网络异常,如充值成功,重进游戏可领取奖励");
|
||
callBack({ code: 2, data: null, message: '轮询超时,达到最大重试次数' });
|
||
isCallBackCalled = true;
|
||
}
|
||
return;
|
||
}
|
||
// 设置超时定时器
|
||
const timeoutId = setTimeout(() => {
|
||
retryCount++;
|
||
console.log(`请求超时,第 ${retryCount} 次重新申请接口`);
|
||
makeRequest();
|
||
}, 3000);
|
||
console.log("请求uid:" + Utils.uid);
|
||
Utils.POST("getRank", { uid: cc.fx.GameConfig.GM_INFO.uid }, res => {
|
||
//console.log("查询排行榜结果");
|
||
//console.log(res);
|
||
// 清除超时定时器
|
||
clearTimeout(timeoutId);
|
||
if (!isCallBackCalled) {
|
||
callBack(res);
|
||
isCallBackCalled = true;
|
||
}
|
||
});
|
||
};
|
||
makeRequest();
|
||
}
|
||
|
||
/** 获取入职排行榜 */
|
||
static getSRank(callBack) {
|
||
// 最大重试次数
|
||
const maxRetries = 5;
|
||
let retryCount = 0;
|
||
// 标志位,用于记录 callBack 是否已经被调用
|
||
let isCallBackCalled = false;
|
||
const makeRequest = () => {
|
||
if (retryCount > maxRetries) {
|
||
if (!isCallBackCalled) {
|
||
MiniGameSdk.API.showToast("网络异常,获取排行失败");
|
||
callBack({ code: 2, data: null, message: '轮询超时,达到最大重试次数' });
|
||
isCallBackCalled = true;
|
||
}
|
||
return;
|
||
}
|
||
// 设置超时定时器
|
||
const timeoutId = setTimeout(() => {
|
||
retryCount++;
|
||
console.log(`请求超时,第 ${retryCount} 次重新申请接口`);
|
||
makeRequest();
|
||
}, 3000);
|
||
console.log("请求uid:" + Utils.uid);
|
||
Utils.POST("getSRank", { uid: cc.fx.GameConfig.GM_INFO.uid }, res => {
|
||
// 清除超时定时器
|
||
clearTimeout(timeoutId);
|
||
if (!isCallBackCalled) {
|
||
callBack(res);
|
||
isCallBackCalled = true;
|
||
}
|
||
});
|
||
};
|
||
makeRequest();
|
||
}
|
||
|
||
//#region 丛林宝藏活动
|
||
/** 获取丛林宝藏配置和玩家档位状态 */
|
||
static getJungleTreasure(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
Utils.POST("jungleTreasure", setData, res => {
|
||
console.log("获得丛林宝藏数据:", res);
|
||
if (callBack) callBack(res);
|
||
});
|
||
}
|
||
}
|
||
|
||
/** 领取丛林宝藏指定档位,tierId 从 1 开始 */
|
||
static claimJungleTreasure(tierId, callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'claim',
|
||
tierId: tierId,
|
||
}
|
||
Utils.POST("jungleTreasure", setData, res => {
|
||
console.log("领取丛林宝藏数据:", res);
|
||
if (callBack) callBack(res);
|
||
});
|
||
}
|
||
}
|
||
|
||
/** 到期批量结算:资源基数来自客户端,奖励数量由服务端配置计算。 */
|
||
static settleExpiredJungleTreasure(resources, callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
Utils.POST("jungleTreasure", {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'settle_expired',
|
||
resources: JSON.stringify(resources),
|
||
}, res => {
|
||
console.log("结算到期丛林宝藏:", res);
|
||
if (callBack) callBack(res);
|
||
});
|
||
}
|
||
}
|
||
|
||
/** 玩家关闭汇总弹窗后确认结算;重复确认由服务端按成功处理。 */
|
||
static ackJungleTreasureSettlement(settlementId, callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
Utils.POST("jungleTreasure", {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'ack_settlement',
|
||
settlementId: settlementId,
|
||
}, res => {
|
||
console.log("确认丛林宝藏结算:", res);
|
||
if (callBack) callBack(res);
|
||
});
|
||
}
|
||
}
|
||
|
||
//#region 新手礼包相关
|
||
static reactivateStarter_pack(reason: string, failureCount: number, lastShownAt: number, callBack) {
|
||
Utils.POST("limitedTimeEvent", {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid, event: "starter_pack", action: "reactivate",
|
||
reason, failureCount, level: cc.fx.GameConfig.GM_INFO.level, lastShownAt,
|
||
}, callBack);
|
||
}
|
||
|
||
static markStarterPackShown(expiry: number, automatic: boolean = false) {
|
||
Utils.POST("limitedTimeEvent", {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid, event: "starter_pack", action: "shown", expiry, automatic,
|
||
}, () => { });
|
||
}
|
||
|
||
//获取新手礼包是否能显示
|
||
static getStarter_pack(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
event: "starter_pack",
|
||
}
|
||
Utils.POST("limitedTimeEvent", setData, res => {
|
||
console.log("获得新手礼包数据:", res);
|
||
if (res.code === 1) {
|
||
// //console.log("服务器:领取获得monthGetReward成功'✅ ", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
// //console.log("服务器:获得monthGetReward失败'❌ ", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
//触发新手礼包事件
|
||
static setStarter_pack(callBack, reason?: string) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
event: "starter_pack",
|
||
reason, level: cc.fx.GameConfig.GM_INFO.level,
|
||
}
|
||
Utils.POST("limitedTimeEvent", setData, res => {
|
||
console.log("触发新手礼包事件:", res);
|
||
if (res.code === 1) {
|
||
console.log("服务器:领取获得monthGetReward成功'✅ ", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("服务器:获得monthGetReward失败'❌ ", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//每日任务获取
|
||
static getDailyQuestInfo(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
Utils.POST("dayTaskInfoV2", setData, res => {
|
||
console.log("获取每日任务信息:", res);
|
||
if (res.code === 1) {
|
||
// //console.log("服务器:领取获得monthGetReward成功'✅ ", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
// //console.log("服务器:获得monthGetReward失败'❌ ", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//设置每日任务信息
|
||
static setDailyQuestInfo(callBack, task = cc.fx.GameConfig.GM_INFO.tasks) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
task: JSON.stringify(task),
|
||
}
|
||
Utils.POST("dayTaskInfoV2", setData, res => {
|
||
if (res.code === 1) {
|
||
// 由 DailyTaskSync 合并回包,保留请求期间新产生的进度。
|
||
// //console.log("服务器:领取获得monthGetReward成功'✅ ", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
// //console.log("服务器:获得monthGetReward失败'❌ ", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//获取每日任务奖励
|
||
static getDailyQuestReward(data, callBack, scope: "daily" | "weekly" = "daily") {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
scope: scope,
|
||
...(scope === "weekly" ? { rewardId: data } : { taskId: data }),
|
||
}
|
||
Utils.POST("getTaskRewardV2", setData, res => {
|
||
if (res.code === 1) {
|
||
// 领取状态和并发进度由 DailyTaskSync 统一更新。
|
||
// //console.log("服务器:领取获得monthGetReward成功'✅ ", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
// //console.log("服务器:获得monthGetReward失败'❌ ", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//设置连胜次数
|
||
static setWinStreak(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
winStreak: cc.fx.GameConfig.GM_INFO.winStreak,
|
||
}
|
||
Utils.POST("setWinStreak", setData, res => {
|
||
if (res.code === 1) {
|
||
// //console.log("服务器:领取获得monthGetReward成功'✅ ", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
// //console.log("服务器:获得monthGetReward失败'❌ ", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//获取通行证等级
|
||
static getpassCheckLv(callBack) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
Utils.POST("passCheckLv", setData, res => {
|
||
|
||
if (res.code === 1) {
|
||
console.log("请求通行证等级成功:", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("请求通行证等级失败:", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//设置通行证等级
|
||
static setPassCheckLv(callBack, data) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
// let data = {
|
||
// progress: 2,
|
||
// progressLevel: 3,
|
||
// }
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
passCheckLv: JSON.stringify(data),
|
||
|
||
}
|
||
console.log("设置通行证等级数据:", setData);
|
||
Utils.POST("passCheckLv", setData, res => {
|
||
if (res.code === 1) {
|
||
console.log("设置通行证等级成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("设置通行证等级失败", res);
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
//获取通行证信息
|
||
private static passGiftPending: { [order: string]: 'pending' | 'applied' } = {};
|
||
private static applyPassGift(order: string) {
|
||
const key = (cc.fx.GameConfig.GM_INFO.uid || Utils.uid) + ':' + order;
|
||
if (Utils.passGiftPending[key] !== 'pending') return;
|
||
Utils.passGiftPending[key] = 'applied';
|
||
cc.fx.GameConfig.GM_INFO.coin += 3000;
|
||
cc.fx.StorageMessage.setStorage('coin', { coin: cc.fx.GameConfig.GM_INFO.coin, timestamp: Date.now() });
|
||
}
|
||
static getPassCheckInfo(callBack) {
|
||
if (!cc.fx.GameConfig.PASS_CHECK) {
|
||
if (callBack) callBack({ code: 0, msg: '战令配置尚未加载,请稍后重试' });
|
||
return;
|
||
}
|
||
const settlementCheck = BattlePassSettlementCheck.forPlayer(cc.fx.GameConfig.GM_INFO);
|
||
Utils.POST("passCheck", { uid: cc.fx.GameConfig.GM_INFO.uid || Utils.uid, action: 'read' }, res => {
|
||
if (res.code !== 1) { if (callBack) callBack(res); return; }
|
||
// time is the idcount period origin, not the user's archive end or server now.
|
||
settlementCheck.observeStart(Number(res.data.time));
|
||
Utils.passRequest('read').then(extra => {
|
||
const raw = typeof extra.data.legacy === 'string' ? JSON.parse(extra.data.legacy) : extra.data.legacy;
|
||
let pass = mergePassInfo(raw, extra.data.extra, cc.fx.GameConfig.PASS_CHECK);
|
||
// Expired periods are archived by the read API before the current season is rotated.
|
||
const rotated = pass && (!pass[2] || Number(pass[2].time) <= Date.now());
|
||
if (pass) {
|
||
pass[1] = { time: '0', free: [], passCheck: [] };
|
||
if (rotated) pass[2] = normalizePass({ time: String(Number(res.data.time) + PASS_PERIOD), experience: 0, activate: false, free: [], passCheck: [] }, cc.fx.GameConfig.PASS_CHECK);
|
||
}
|
||
if (pass) { pass.revision = extra.data.revision; pass.upgradeReady = true; }
|
||
for (const time of Object.keys(extra.data.extra || {})) for (const order of extra.data.extra[time].orders || []) Utils.applyPassGift(order);
|
||
res.data.passCheck = JSON.stringify(pass);
|
||
res.data.upgradeReady = true;
|
||
if (rotated) Utils.setPassCheckInfo(saved => { if (callBack) callBack(saved.code === 1 ? res : saved); }, pass);
|
||
else if (callBack) callBack(res);
|
||
}).catch(() => { if (callBack) callBack(res); });
|
||
});
|
||
}
|
||
|
||
//设置通行证信息
|
||
static setPassCheckInfo(callBack, data) {
|
||
if (data == null) {
|
||
Utils.POST('passCheck', { uid: cc.fx.GameConfig.GM_INFO.uid || Utils.uid, action: 'save', passCheck: 'null' }, callBack || (() => { }));
|
||
return;
|
||
}
|
||
const save = async () => {
|
||
if (!data) throw { code: 0, msg: '战令数据为空' };
|
||
let pass = data;
|
||
for (let attempt = 0; attempt < 3; attempt++) {
|
||
const latest = await Utils.passRequest('read');
|
||
const merged = mergePassInfo(JSON.parse(latest.data.legacy || 'null'), latest.data.extra, cc.fx.GameConfig.PASS_CHECK);
|
||
for (const key of [1, 2]) {
|
||
if (!pass[key] || !Number(pass[key].time)) continue;
|
||
pass[key] = normalizePass(pass[key], cc.fx.GameConfig.PASS_CHECK);
|
||
const current = merged && [merged[1], merged[2]].find(s => String(s && s.time) === String(pass[key].time));
|
||
if (current) {
|
||
pass[key].experience = Math.max(pass[key].experience, current.experience);
|
||
for (const lane of ['free', 'passCheck']) for (let i = 0; i < current[lane].length; i++) {
|
||
if (current[lane][i] === 0) pass[key][lane][i] = 0;
|
||
}
|
||
pass[key] = normalizePass(pass[key], cc.fx.GameConfig.PASS_CHECK);
|
||
}
|
||
}
|
||
try { return await Utils.passRequest('save', { ...Utils.passUpload(pass), revision: latest.data.revision }); }
|
||
catch (error) { if (error.code !== 409 || attempt === 2) throw error; }
|
||
}
|
||
};
|
||
save().then(res => { if (callBack) callBack(res); }, error => { if (callBack) callBack(error); });
|
||
}
|
||
/** 只用于战令接口,避免网络无回调时卡住本次战令操作。 */
|
||
private static passRequest(action: string, data: any = {}): Promise<any> {
|
||
return new Promise((resolve, reject) => {
|
||
const timer = setTimeout(() => reject({ code: 0, msg: '战令请求超时,请重试' }), 6000);
|
||
Utils.POST('passCheckUpgrade', { uid: cc.fx.GameConfig.GM_INFO.uid || Utils.uid, action, ...data }, res => {
|
||
clearTimeout(timer);
|
||
res.code === 1 ? resolve(res) : reject(res);
|
||
});
|
||
});
|
||
}
|
||
private static passUpload(pass: any, paidOrder = false): any {
|
||
pass = { ...pass };
|
||
for (const key of [1, 2]) if (!paidOrder && pass[key] && Number(pass[key].time) <= Date.now()) pass[key] = { time: '0', free: [], passCheck: [] };
|
||
const legacy = legacyPassInfo(pass, cc.fx.GameConfig.PASS_CHECK);
|
||
for (const key of [1, 2]) if (pass[key] && Number(pass[key].time)) pass[key].legacyExperience = legacyExperience(legacy[key]);
|
||
return { passCheck: JSON.stringify(pass), legacy: JSON.stringify(legacy) };
|
||
}
|
||
static addPassProgress() {
|
||
Utils.getPassCheckInfo(res => {
|
||
if (res.code !== 1 || !res.data.upgradeReady) return;
|
||
cc.fx.GameConfig.GM_INFO.getItemType = 2;
|
||
let pass = JSON.parse(res.data.passCheck);
|
||
const end = Number(res.data.time) + PASS_PERIOD;
|
||
if (!pass) pass = { 1: { time: '0', free: [], passCheck: [] } };
|
||
if (!pass[2] || Number(pass[2].time) <= Date.now()) {
|
||
if (pass[2]) pass[1] = pass[2];
|
||
pass[2] = { time: String(end), experience: 0, free: [], passCheck: [], activate: false };
|
||
}
|
||
const stage = normalizePass(pass[2], cc.fx.GameConfig.PASS_CHECK);
|
||
const before = stage.unlocked;
|
||
stage.experience += passTier(stage) === 30 ? 2 : 1;
|
||
pass[2] = normalizePass(stage, cc.fx.GameConfig.PASS_CHECK);
|
||
cc.fx.GameConfig.GM_INFO.getProgress = pass[2].progress;
|
||
cc.fx.GameConfig.GM_INFO.getProgressLevel = pass[2].progressLevel;
|
||
if (pass[2].unlocked > before) cc.fx.GameConfig.GM_INFO.popPassCheck = true;
|
||
Utils.setPassCheckInfo(() => { }, pass);
|
||
});
|
||
}
|
||
static async completePassOrder(outTradeNo: string): Promise<any> {
|
||
const check = BattlePassSettlementCheck.forPlayer(cc.fx.GameConfig.GM_INFO);
|
||
try { return await Utils.deliverPassOrder(outTradeNo); }
|
||
finally { check.invalidate(); }
|
||
}
|
||
private static async deliverPassOrder(outTradeNo: string): Promise<any> {
|
||
for (let attempt = 0; attempt < 3; attempt++) {
|
||
const order = await Utils.passRequest('order', { outTradeNo });
|
||
if (order.data.postSeason) {
|
||
const snapshot = order.data.snapshot;
|
||
if (!snapshot) throw { code: 410, msg: '上期结算记录暂不可用' };
|
||
const result = await Utils.commitPassSettlement('purchase_claim', snapshot, outTradeNo);
|
||
return { ...result, data: { ...result.data, postSeason: true } };
|
||
}
|
||
if (order.data.alreadyGranted) { Utils.applyPassGift(outTradeNo); return order; }
|
||
const pass = mergePassInfo(JSON.parse(order.data.legacy || '{}'), order.data.extra, cc.fx.GameConfig.PASS_CHECK);
|
||
let key = [1, 2].find(k => String(pass[k] && pass[k].time) === order.data.passEnd);
|
||
if (!key && order.data.extra[order.data.passEnd]) { key = 1; pass[1] = order.data.extra[order.data.passEnd]; }
|
||
if (!key) throw { code: 410, msg: '订单所属期已过期,请联系客服' };
|
||
pass[key].activate = true; pass[key].tier = order.data.targetTier;
|
||
if (order.data.bonus) pass[key].experience += 20;
|
||
pass[key] = normalizePass(pass[key], cc.fx.GameConfig.PASS_CHECK);
|
||
// 沿用客户端计算后上传,赠金仅通过战令接口随本期发奖记录一起保存。
|
||
const coinAmount = Math.floor(cc.fx.GameConfig.GM_INFO.coin) + (order.data.bonus ? 3000 : 0);
|
||
const giftKey = (cc.fx.GameConfig.GM_INFO.uid || Utils.uid) + ':' + outTradeNo;
|
||
if (order.data.bonus && Utils.passGiftPending[giftKey] !== 'applied') Utils.passGiftPending[giftKey] = 'pending';
|
||
try {
|
||
const saved = await Utils.passRequest('save', { ...Utils.passUpload(pass, true), revision: order.data.revision, outTradeNo, coinAmount });
|
||
if (saved.data.bonus && !saved.data.alreadyGranted) {
|
||
Utils.applyPassGift(outTradeNo);
|
||
}
|
||
return saved;
|
||
} catch (error) {
|
||
// 响应可能丢失,先确认战令收据;只补本次进程尚未发布的赠金。
|
||
const confirmed = await Utils.passRequest('order', { outTradeNo });
|
||
if (confirmed.data.alreadyGranted) {
|
||
Utils.applyPassGift(outTradeNo);
|
||
return { ...confirmed, data: { ...confirmed.data, bonus: order.data.bonus, targetTier: order.data.targetTier, alreadyGranted: false } };
|
||
}
|
||
if (error.code !== 409 || attempt === 2) throw error;
|
||
}
|
||
}
|
||
}
|
||
|
||
static settlementRequest(action: string, data: any = {}): Promise<any> {
|
||
return new Promise((resolve, reject) => Utils.POSTJSON('passCheckSettlement', {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid || Utils.uid, action, ...data
|
||
}, res => res.code === 1 ? resolve(res) : reject(res)));
|
||
}
|
||
|
||
static commitPassSettlement(action: string, snapshot: any, outTradeNo?: string): Promise<any> {
|
||
return Utils.withCoinSave(async () => {
|
||
const rewards = settlementRewards(snapshot, cc.fx.GameConfig.PASS_CHECK, action === 'purchase_claim');
|
||
const claimFlags = settlementClaimFlags(snapshot, cc.fx.GameConfig.PASS_CHECK, action === 'purchase_claim');
|
||
const result = await Utils.settlementRequest(action, { end: snapshot.end, rewards, claimFlags, outTradeNo });
|
||
Utils.syncPassResources(result.data.resources);
|
||
return result;
|
||
});
|
||
}
|
||
|
||
static syncPassResources(values: any) {
|
||
const gm = cc.fx.GameConfig.GM_INFO;
|
||
gm.coin = values.coinAmount;
|
||
for (const key of ['freezeAmount', 'hammerAmount', 'magicAmount', 'userPowerTime']) gm[key] = values[key];
|
||
cc.fx.StorageMessage.setStorage('coin', { coin: gm.coin, timestamp: Date.now() });
|
||
cc.fx.StorageMessage.setStorage('prop', { ...(cc.fx.StorageMessage.getStorage('prop') || {}), freezeAmount: gm.freezeAmount, hammerAmount: gm.hammerAmount, magicAmount: gm.magicAmount, timestamp: Date.now() });
|
||
cc.fx.StorageMessage.setStorage('userPowerTime', gm.userPowerTime);
|
||
}
|
||
|
||
//修改储存城市信息
|
||
static setCityInfo(callBack, data, useReverseGeocoding) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
address: data,
|
||
}
|
||
if (useReverseGeocoding == false || data == "" || data == "其他") {
|
||
if (callBack) callBack(null);
|
||
}
|
||
else {
|
||
console.log("设置城市信息数据:", setData);
|
||
Utils.POST("address", setData, res => {
|
||
if (res.code === 1) {
|
||
console.log("设置城市信息成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("设置城市信息失败", res);
|
||
}
|
||
})
|
||
}
|
||
}
|
||
}
|
||
|
||
//设置城市信息失败
|
||
static setFailCityInfo() {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let locationInfo = {
|
||
type: "coordinate",
|
||
result: cc.fx.GameConfig.GM_INFO.address,
|
||
is_success: false,
|
||
info: cc.fx.GameConfig.GM_INFO.longitude
|
||
}
|
||
cc.fx.GameTool.shushu_Track("location", locationInfo);
|
||
// let setData = {
|
||
// uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
// action: 'save',
|
||
// address: "其他",
|
||
// }
|
||
// Utils.POST("address", setData, res => {
|
||
// if (res.code === 1) {
|
||
// console.log("设置城市信息成功", res);
|
||
// } else {
|
||
// console.log("设置城市信息失败", res);
|
||
// }
|
||
// })
|
||
}
|
||
}
|
||
|
||
//获取城市前100名排名
|
||
static getCityRank(callBack, data) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
|
||
let address = data;
|
||
if (address == "" || address == null || address == undefined) {
|
||
address = "其他";
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
address: address,
|
||
}
|
||
|
||
console.log("sos_______________s:", setData);
|
||
let otherRank = null;
|
||
let selfRank = null;
|
||
|
||
Utils.POST("getAddressRankOther", setData, res => {
|
||
if (res.code === 1) {
|
||
otherRank = res.data || [];
|
||
// console.log("五彩消消乐设置城市信息成功", res);
|
||
Utils.POST("getAddressRankSelf", setData, res => {
|
||
if (res.code === 1) {
|
||
// console.log("消消王者设置城市信息成功", res);
|
||
selfRank = res.data || [];
|
||
// 合并两个数组
|
||
const mergeRank = (otherRank || []).concat(selfRank || []);
|
||
// 按 addLevel 值降序排序(addLevel 越大排名越靠前)
|
||
mergeRank.sort((a, b) => {
|
||
return (b.addLevel || 0) - (a.addLevel || 0);
|
||
});
|
||
res.data = mergeRank;
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
// console.log("1设置城市信息失败", res);
|
||
}
|
||
})
|
||
} else {
|
||
// console.log("1设置城市信息失败", res);
|
||
}
|
||
})
|
||
|
||
}
|
||
}
|
||
|
||
static getShopDouble(callBack, onComplete?: () => void) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
console.log("获取双倍信息数据:", setData);
|
||
Utils.POST("shopDouble", setData, res => {
|
||
try {
|
||
if (res.code === 1) {
|
||
console.log("获取双倍信息成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("获取双倍信息失败", res);
|
||
}
|
||
} finally {
|
||
if (onComplete) onComplete();
|
||
}
|
||
})
|
||
} else {
|
||
if (onComplete) onComplete();
|
||
}
|
||
}
|
||
|
||
static setShopDouble(callBack, data) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
shopDouble: JSON.stringify(data),
|
||
}
|
||
Utils.POST("shopDouble", setData, res => {
|
||
if (res.code === 1) {
|
||
console.log("设置双倍信息成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("设置双倍信息失败", res);
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
static setEndlessLevel(callBack, data1, data2) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
userLevel: parseInt(data1), // JSON.stringify(data1), //
|
||
endLevelNum: parseInt(data2),
|
||
}
|
||
console.log("设置无尽关卡等级:", setData);
|
||
Utils.POST("setUserLevel", setData, res => {
|
||
if (res.code === 1) {
|
||
let endLevelNum = res.data.endLevelNum;
|
||
if (parseInt(data2) < Number(endLevelNum))
|
||
cc.fx.GameConfig.GM_INFO.endLevelNum = Number(endLevelNum);
|
||
console.log("设置无尽关卡", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("设置无尽关卡", res);
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
static getEndlessLevel(callBack) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
Utils.POST("setUserLevel", setData, res => {
|
||
console.log("获得无尽关卡等级:", res);
|
||
if (res.code === 1) {
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
static getRedeemInfo(callBack, cdk) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
cdk: cdk,
|
||
}
|
||
Utils.POST("redeem", setData, res => {
|
||
if (res.code === 1) {
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
static getUserInfoByID(callBack) {
|
||
//@ts-ignore
|
||
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
|
||
let uid = cc.fx.GameConfig.GM_INFO.otherUid;
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
let setData = {
|
||
uid: uid
|
||
}
|
||
Utils.POST("getUserInfoByID", setData, res => {
|
||
// //console.log("获得monthGetReward数据:", res);
|
||
if (res.code === 1) {
|
||
console.log("服务器:获得分享人头像昵称'✅ ", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("服务器:获得分享人头像昵称'❌ ", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//获取
|
||
static getCommentInfo(callBack) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
}
|
||
Utils.POST("comment", setData, res => {
|
||
|
||
if (res.code === 1) {
|
||
console.log("请求评论成功:", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("请求评论失败:", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//设置评论
|
||
static setCommentInfo(callBack, data, _pos) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'save',
|
||
pos: _pos,
|
||
level: cc.fx.GameConfig.GM_INFO.level,
|
||
comment: JSON.stringify(data),
|
||
|
||
}
|
||
|
||
console.log("设置评论数据:", setData);
|
||
Utils.POST("comment", setData, res => {
|
||
if (res.code === 1) {
|
||
console.log("设置评论成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("设置评论失败", res);
|
||
}
|
||
})
|
||
}
|
||
}
|
||
//获取点赞
|
||
static getLikeInfo(callBack, _pos) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'read',
|
||
level: cc.fx.GameConfig.GM_INFO.level,
|
||
pos: _pos,
|
||
}
|
||
Utils.POST("comment", setData, res => {
|
||
|
||
if (res.code === 1) {
|
||
console.log("请求点赞成功:", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("请求点赞失败:", res);
|
||
if (callBack) callBack(res);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//设置点赞
|
||
static setLikeInfo(callBack, _pos, _index) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: 'like',
|
||
level: cc.fx.GameConfig.GM_INFO.level,
|
||
pos: _pos,
|
||
index: _index,
|
||
// comment: JSON.stringify(data),
|
||
|
||
}
|
||
|
||
console.log("设置点赞数据:", setData);
|
||
Utils.POST("comment", setData, res => {
|
||
if (res.code === 1) {
|
||
console.log("设置点赞成功", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("设置点赞失败", res);
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
//#region 抽卡相关
|
||
/**抽卡*/
|
||
static getGacha(callBack) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
}
|
||
Utils.POST("drawHead", setData, res => {
|
||
if (res.code === 1) {
|
||
console.log("正常获取到抽卡结果", res);
|
||
} else {
|
||
console.log("获取抽卡失败,失败原因", res);
|
||
}
|
||
// 失败也必须回调,否则抽卡页的 Loading 和防重复点击状态无法恢复。
|
||
if (callBack) callBack(res);
|
||
})
|
||
}
|
||
}
|
||
|
||
/**抽卡*/
|
||
static getCat(callBack) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
}
|
||
Utils.POST("drawCat", setData, res => {
|
||
if (res.code === 1) {
|
||
console.log("正常获取到抽猫猫结果", res);
|
||
} else {
|
||
console.log("获取抽猫猫失败,失败原因", res);
|
||
}
|
||
// 失败也必须回调,否则抽卡页的 Loading 和防重复点击状态无法恢复。
|
||
if (callBack) callBack(res);
|
||
})
|
||
}
|
||
}
|
||
|
||
/*获取所有用户所得头像*/
|
||
static getAvatar(callBack) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
}
|
||
Utils.POST("getHeadInfo", setData, res => {
|
||
if (res.code === 1) {
|
||
console.log("正常获取用户头像接口所得数据", res);
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("获取头像接口失败,失败原因", res);
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
|
||
static getAvatarWithRetry(callBack) {
|
||
const maxRetries = 3;
|
||
let retryCount = 0;
|
||
let isCallBackCalled = false;
|
||
console.log("获取头像接口________");
|
||
const makeRequest = () => {
|
||
if (retryCount >= maxRetries) {
|
||
if (!isCallBackCalled) {
|
||
console.log("获取头像失败,已达到最大重试次数");
|
||
if (callBack) callBack({ code: 0, data: null, message: '轮询超时,达到最大重试次数' });
|
||
isCallBackCalled = true;
|
||
}
|
||
return;
|
||
}
|
||
|
||
const timeoutId = setTimeout(() => {
|
||
console.log("上一次尝试失败,重新尝试");
|
||
retryCount++;
|
||
console.log(`获取头像超时,第 ${retryCount} 次重新请求`);
|
||
makeRequest();
|
||
}, 4000);
|
||
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
}
|
||
console.log("开始调用获取头像接口");
|
||
Utils.POST("getHeadInfo", setData, res => {
|
||
clearTimeout(timeoutId);
|
||
if (!isCallBackCalled) {
|
||
if (callBack) callBack(res);
|
||
isCallBackCalled = true;
|
||
}
|
||
});
|
||
};
|
||
console.log("执行");
|
||
makeRequest();
|
||
}
|
||
|
||
/*获取所有用户代币*/
|
||
static getFilm(callBack) {
|
||
//@ts-ignore
|
||
if (typeof wx !== 'undefined' && wx !== null) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
}
|
||
Utils.POST("getFilm", setData, res => {
|
||
if (res.code === 1) {
|
||
console.log("正常获取用户代币", res);
|
||
if (res.data && res.data.film !== undefined) {
|
||
cc.fx.GameConfig.GM_INFO.film = Number(res.data.film);
|
||
}
|
||
if (callBack) callBack(res);
|
||
} else {
|
||
console.log("获取代币失败,失败原因", res);
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
static setForcedUpdate(callBack?) {
|
||
let uid = cc.fx.StorageMessage.getStorage("uid");
|
||
//旧的读取数据设置数据方法,以强联网为主
|
||
if (uid != undefined && uid != "" && uid != null) {
|
||
cc.fx.GameConfig.GM_INFO.uid = uid;
|
||
}
|
||
let setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
}
|
||
Utils.POST("setForcedUpdate", setData, res => {
|
||
if (res.code === 1) {
|
||
console.log("设置强制更新成功", res);
|
||
} else {
|
||
console.log("设置强制更新失败", res);
|
||
}
|
||
if (callBack) callBack(res);
|
||
})
|
||
}
|
||
|
||
static wucaiTransfer(
|
||
action: "claim_reward" | "choose_wucai" | "choose_current" | "ack_reward_popup",
|
||
callBack?,
|
||
) {
|
||
const isProgressChoice = action === "choose_wucai" || action === "choose_current";
|
||
const wasPendingChoice = Number(cc.fx.GameConfig.GM_INFO.wucai_type) === 1;
|
||
const wucaiLevelAmount = cc.fx.GameConfig.GM_INFO.wucai_preview?.levelAmount;
|
||
const xiaoxiaoLevelAmount = cc.fx.GameConfig.GM_INFO.wucai_current_preview?.levelAmount;
|
||
const setData = {
|
||
uid: cc.fx.GameConfig.GM_INFO.uid,
|
||
action: action,
|
||
wucai_entry_id: cc.fx.GameConfig.GM_INFO.wucai_entry_id,
|
||
};
|
||
Utils.POST("wucaiTransfer", setData, res => {
|
||
if (res.code === 1 && action === "claim_reward") {
|
||
const data = res.data || {};
|
||
const coinAmount = Number(data.coinAmount);
|
||
const freezeAmount = Number(data.freezeAmount);
|
||
const hammerAmount = Number(data.hammerAmount);
|
||
const magicAmount = Number(data.magicAmount);
|
||
if (!Number.isFinite(coinAmount)
|
||
|| !Number.isFinite(freezeAmount)
|
||
|| !Number.isFinite(hammerAmount)
|
||
|| !Number.isFinite(magicAmount)) {
|
||
if (callBack) {
|
||
callBack({
|
||
code: 0,
|
||
errorCode: "WUCAI_REWARD_DATA_INVALID",
|
||
msg: "奖励数据返回异常",
|
||
});
|
||
}
|
||
return;
|
||
}
|
||
|
||
const timestamp = Date.now();
|
||
cc.fx.GameConfig.GM_INFO.coin = coinAmount;
|
||
cc.fx.GameConfig.GM_INFO.freezeAmount = freezeAmount;
|
||
cc.fx.GameConfig.GM_INFO.hammerAmount = hammerAmount;
|
||
cc.fx.GameConfig.GM_INFO.magicAmount = magicAmount;
|
||
cc.fx.StorageMessage.setStorage("coin", { coin: coinAmount, timestamp });
|
||
cc.fx.StorageMessage.setStorage("prop", {
|
||
freezeAmount,
|
||
hammerAmount,
|
||
magicAmount,
|
||
timestamp,
|
||
});
|
||
}
|
||
if (res.code === 1 && res.data) {
|
||
cc.fx.GameConfig.GM_INFO.wucai_type = Number(res.data.wucai_type);
|
||
cc.fx.GameConfig.GM_INFO.wucai_entry_id = res.data.wucai_entry_id || "";
|
||
cc.fx.GameConfig.GM_INFO.wucai_reward_granted = res.data.wucai_reward_granted === true;
|
||
cc.fx.GameConfig.GM_INFO.wucai_reward_popup_pending =
|
||
res.data.wucai_reward_popup_pending === true;
|
||
}
|
||
if (res.code === 1 && isProgressChoice && wasPendingChoice) {
|
||
MiniGameSdk.API.shushu_TrackWucaiTransfer(
|
||
1,
|
||
action === "choose_current" ? 1 : 0,
|
||
wucaiLevelAmount,
|
||
xiaoxiaoLevelAmount,
|
||
);
|
||
MiniGameSdk.API.shushu_userSetTransferredFromWucai(true);
|
||
}
|
||
if (callBack) callBack(res);
|
||
if (res.code === 1 && isProgressChoice) {
|
||
MiniGameSdk.API.reboot("?wucai_resume=1", () => {
|
||
MiniGameSdk.API.showToast("选择已保存,请关闭游戏重新进入", 4);
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|