fcm 拉活
This commit is contained in:
@@ -13,21 +13,6 @@ export interface WalletItem {
|
||||
const DEFAULT_DOMAIN = 'aa.pfgame.org';
|
||||
const STORAGE_KEY = 'server_domain';
|
||||
const HTTPS_KEY = 'server_https';
|
||||
const TOKEN_AUTO_REBIND_KEY = 'token_auto_rebind_enabled';
|
||||
const TOKEN_AUTO_REBIND_SCAN_MS_KEY = 'token_auto_rebind_scan_ms';
|
||||
const TOKEN_AUTO_REBIND_COOLDOWN_MS_KEY = 'token_auto_rebind_cooldown_ms';
|
||||
const TOKEN_AUTO_REBIND_FAIL_COOLDOWN_MS_KEY = 'token_auto_rebind_fail_cooldown_ms';
|
||||
/** 扫 list 间隔 */
|
||||
const DEFAULT_TOKEN_AUTO_REBIND_SCAN_MS = 1 * 60 * 1000;
|
||||
/** 重绑成功后冷却 */
|
||||
const DEFAULT_TOKEN_AUTO_REBIND_COOLDOWN_MS = 1 * 60 * 1000;
|
||||
/** 重绑失败后冷却 */
|
||||
const DEFAULT_TOKEN_AUTO_REBIND_FAIL_COOLDOWN_MS = 1 * 60 * 1000;
|
||||
|
||||
let _tokenAutoRebindEnabled = false;
|
||||
let _tokenAutoRebindScanMs = DEFAULT_TOKEN_AUTO_REBIND_SCAN_MS;
|
||||
let _tokenAutoRebindCooldownMs = DEFAULT_TOKEN_AUTO_REBIND_COOLDOWN_MS;
|
||||
let _tokenAutoRebindFailCooldownMs = DEFAULT_TOKEN_AUTO_REBIND_FAIL_COOLDOWN_MS;
|
||||
|
||||
let _domain = DEFAULT_DOMAIN;
|
||||
let _useHttps = true;
|
||||
@@ -37,61 +22,10 @@ export async function loadServerDomain(): Promise<string> {
|
||||
if (saved) _domain = saved;
|
||||
const https = await AsyncStorage.getItem(HTTPS_KEY);
|
||||
if (https !== null) _useHttps = https === 'true';
|
||||
const autoRebind = await AsyncStorage.getItem(TOKEN_AUTO_REBIND_KEY);
|
||||
_tokenAutoRebindEnabled = autoRebind === 'true';
|
||||
const scanMs = await AsyncStorage.getItem(TOKEN_AUTO_REBIND_SCAN_MS_KEY);
|
||||
const cooldownMs = await AsyncStorage.getItem(TOKEN_AUTO_REBIND_COOLDOWN_MS_KEY);
|
||||
if (scanMs) {
|
||||
const n = parseInt(scanMs, 10);
|
||||
if (Number.isFinite(n) && n > 0) _tokenAutoRebindScanMs = n;
|
||||
}
|
||||
if (cooldownMs) {
|
||||
const n = parseInt(cooldownMs, 10);
|
||||
if (Number.isFinite(n) && n > 0) _tokenAutoRebindCooldownMs = n;
|
||||
}
|
||||
const failCooldownMs = await AsyncStorage.getItem(TOKEN_AUTO_REBIND_FAIL_COOLDOWN_MS_KEY);
|
||||
if (failCooldownMs) {
|
||||
const n = parseInt(failCooldownMs, 10);
|
||||
if (Number.isFinite(n) && n > 0) _tokenAutoRebindFailCooldownMs = n;
|
||||
}
|
||||
console.log('loadServerDomain', _domain, 'https:', _useHttps);
|
||||
return _domain;
|
||||
}
|
||||
|
||||
export function getTokenAutoRebindOptions(): {
|
||||
scanIntervalMs: number;
|
||||
cooldownMs: number;
|
||||
failCooldownMs: number;
|
||||
} {
|
||||
return {
|
||||
scanIntervalMs: _tokenAutoRebindScanMs,
|
||||
cooldownMs: _tokenAutoRebindCooldownMs,
|
||||
failCooldownMs: _tokenAutoRebindFailCooldownMs,
|
||||
};
|
||||
}
|
||||
|
||||
export async function saveTokenAutoRebindOptions(
|
||||
scanIntervalMs: number,
|
||||
cooldownMs: number,
|
||||
failCooldownMs: number = DEFAULT_TOKEN_AUTO_REBIND_FAIL_COOLDOWN_MS,
|
||||
): Promise<void> {
|
||||
_tokenAutoRebindScanMs = scanIntervalMs;
|
||||
_tokenAutoRebindCooldownMs = cooldownMs;
|
||||
_tokenAutoRebindFailCooldownMs = failCooldownMs;
|
||||
await AsyncStorage.setItem(TOKEN_AUTO_REBIND_SCAN_MS_KEY, String(scanIntervalMs));
|
||||
await AsyncStorage.setItem(TOKEN_AUTO_REBIND_COOLDOWN_MS_KEY, String(cooldownMs));
|
||||
await AsyncStorage.setItem(TOKEN_AUTO_REBIND_FAIL_COOLDOWN_MS_KEY, String(failCooldownMs));
|
||||
}
|
||||
|
||||
export function getTokenAutoRebindEnabled(): boolean {
|
||||
return _tokenAutoRebindEnabled;
|
||||
}
|
||||
|
||||
export async function saveTokenAutoRebindEnabled(enabled: boolean): Promise<void> {
|
||||
_tokenAutoRebindEnabled = enabled;
|
||||
await AsyncStorage.setItem(TOKEN_AUTO_REBIND_KEY, String(enabled));
|
||||
}
|
||||
|
||||
export async function saveServerDomain(domain: string, useHttps: boolean): Promise<void> {
|
||||
_domain = domain;
|
||||
_useHttps = useHttps;
|
||||
@@ -237,6 +171,16 @@ class Api {
|
||||
return data.data?.status ?? '';
|
||||
}
|
||||
|
||||
public async registerFcmToken(clientId: string, fcmToken: string): Promise<void> {
|
||||
const res = await fetch(`${Api.BASE_URL}/fcm/register`, {
|
||||
method: 'POST',
|
||||
headers: this.headers(),
|
||||
body: JSON.stringify({ clientId, fcmToken }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!data.success) throw new Error(data.message);
|
||||
}
|
||||
|
||||
public async generateLink(walletId: string, amount: string): Promise<{ link: string; orderId: string }> {
|
||||
const res = await fetch(`${Api.BASE_URL}/generate-link`, {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user