MatchMaster/assets/Script/seven_day_gift/SevenDayGiftBootstrapApi.ts

54 lines
1.5 KiB
TypeScript

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;
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 => {
if (completed) return;
completed = true;
clearTimeout(timeoutHandle);
callback(response);
});
}
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 || "";
}
}