MatchMaster/assets/Script/seven_day_gift/SevenDayGiftBootstrapApi.ts

59 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Utils from "../module/Pay/Utils";
// 主包用于判断是否展示的活动快照,具体奖励由分包解析。
export interface SevenDayActivityInfo {
serverNow: string | number;
activityId: string;
status: string;
triggerLevel: number;
triggerReached: boolean;
startAt: string | number;
endAt: string | number;
claimedCount: number;
todayClaimed: boolean;
canClaim: boolean;
nextRewardDay: number;
rewards: any[];
}
interface SevenDayInfoResponse {
code: number;
data: SevenDayActivityInfo | false;
msg?: string;
}
/** 七日活动查询入口,与分包内的资产同步接口分开。 */
export default class SevenDayGiftBootstrapApi {
// 主包只查询活动信息,不提前加载活动资源。
public static getInfo(callback: (response: SevenDayInfoResponse) => void) {
const endpoint = "signInActivityInfo";
const params = { uid: this.getUid() };
let completed = false; // 超时后到达的响应不再处理。
const timeoutHandle = setTimeout(() => {
if (completed) return;
completed = true;
cc.warn("[SevenDayGiftBootstrapApi] 请求超时:" + endpoint);
callback({ code: 0, data: null, msg: "请求超时,请稍后重试" });
}, 5500);
Utils.POST(endpoint, params, response => {
console.log("[signInActivityInfo] 回复" + (completed ? "(已超时或重复,不再处理)" : ""), JSON.stringify(response, null, 2));
if (completed) return;
completed = true;
clearTimeout(timeoutHandle);
callback(response);
});
}
// 优先使用本地登录 UID,并同步到运行时账号信息。
public static getUid(): string {
const storedUid = cc.fx.StorageMessage.getStorage("uid");
if (storedUid !== undefined && storedUid !== null && storedUid !== "") {
cc.fx.GameConfig.GM_INFO.uid = storedUid;
}
return cc.fx.GameConfig.GM_INFO.uid || "";
}
}