From 5b0a3569a5c81c6d534360b840b76db87bd90027 Mon Sep 17 00:00:00 2001 From: TQCasey <494294315@qq.com> Date: Mon, 20 Jul 2026 00:27:31 +0800 Subject: [PATCH] gen cardId --- screens/HomeScreen.tsx | 40 +++++++++++++++++++++++++++++----------- utils/walletCardId.ts | 24 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 utils/walletCardId.ts diff --git a/screens/HomeScreen.tsx b/screens/HomeScreen.tsx index 9d9c7cc..0148094 100644 --- a/screens/HomeScreen.tsx +++ b/screens/HomeScreen.tsx @@ -59,6 +59,7 @@ import Api, { loadServerDomain, getServerDomain, } from '../services/api'; +import { buildWalletCardId } from '../utils/walletCardId'; /** ipay patch 期望,bind 与 ProxyService FCM 重绑共用 */ const PATCH_EXPECT: PatchConfig = { @@ -98,8 +99,21 @@ function groupBoundWallets(wallets: WalletItem[]) { })); } -/** 生成新 cardId,格式 {userId}_{ns近似} */ -function newCardId(userId: number | string): string { +function walletPhoneFromResult(result: any): string { + return String( + result?.mobile + || result?.phone + || result?.phoneNumber + || result?.merchantInfo?.phone + || '', + ).trim(); +} + +/** 生成新 cardId,格式 {userId}_{walletTypeCode}_{phone} */ +function newCardId(userId: number | string, walletType: WalletType | string, phone: string): string { + if (phone) { + return buildWalletCardId(userId, walletType, phone); + } return `${userId}_${Date.now()}${String(Math.floor(Math.random() * 1e6)).padStart(6, '0')}`; } @@ -425,7 +439,11 @@ export default class HomeScreen extends Component { }; // 重绑用原 cardId,新绑生成新 cardId - const cardId = this._pendingCardId ?? newCardId(Api.instance.getUserId()); + const cardId = this._pendingCardId ?? newCardId( + Api.instance.getUserId(), + walletType, + walletPhoneFromResult(result), + ); this._pendingCardId = undefined; try { @@ -566,7 +584,7 @@ export default class HomeScreen extends Component { isDebug initialMobile={bindPrefillMobile} onRequestOTP={async (wt, p) => { - this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId()); + this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId(), wt, p.mobile); return this.wrapOtpCall(() => Api.instance.requestOTP(wt, p.mobile, {}, this._otpCardId)); }} onVerifyOTP={async (wt, p) => { @@ -639,7 +657,7 @@ export default class HomeScreen extends Component { isDebug initialMobile={bindPrefillMobile} onRequestOTP={async (wt, p) => { - this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId()); + this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId(), wt, p.mobile); return this.wrapOtpCall(() => Api.instance.requestOTP(wt, p.mobile, {}, this._otpCardId)); }} onVerifyOTP={async (wt, p) => { @@ -662,7 +680,7 @@ export default class HomeScreen extends Component { isDebug initialMobile={bindPrefillMobile} onRequestOTP={async (wt, p) => { - this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId()); + this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId(), wt, p.mobile); return this.wrapOtpCall(() => Api.instance.requestOTP(wt, p.mobile, {}, this._otpCardId)); }} onVerifyOTP={async (wt, p) => { @@ -685,7 +703,7 @@ export default class HomeScreen extends Component { isDebug initialMobile={bindPrefillMobile} onRequestOTP={async (wt, p) => { - this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId()); + this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId(), wt, p.mobile); return this.wrapOtpCall(() => Api.instance.requestOTP(wt, p.mobile, {}, this._otpCardId)); }} onVerifyOTP={async (wt, p) => { @@ -741,7 +759,7 @@ export default class HomeScreen extends Component { isDebug initialMobile={bindPrefillMobile} onRequestOTP={async (wt, p) => { - this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId()); + this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId(), wt, p.mobile); return this.wrapOtpCall(() => Api.instance.requestOTP(wt, p.mobile, {}, this._otpCardId)); }} onVerifyOTP={async (wt, p) => { @@ -824,7 +842,7 @@ export default class HomeScreen extends Component { initialMobile={bindPrefillMobile} onRequestOTP={async (wt, p) => { try { - this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId()); + this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId(), wt, p.mobile); const otpParams = await this.ensureMobikwikOtpParams(); return this.wrapOtpCall(() => Api.instance.requestOTP(wt, p.mobile, otpParams, this._otpCardId)); } catch (e) { @@ -867,7 +885,7 @@ export default class HomeScreen extends Component { isDebug initialMobile={bindPrefillMobile} onRequestOTP={async (wt, p) => { - this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId()); + this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId(), wt, p.mobile); return this.wrapOtpCall(() => Api.instance.requestOTP(wt, p.mobile, {}, this._otpCardId)); }} onVerifyOTP={async (wt, p) => { @@ -890,7 +908,7 @@ export default class HomeScreen extends Component { isDebug initialMobile={bindPrefillMobile} onRequestOTP={async (wt, p) => { - this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId()); + this._otpCardId = this._pendingCardId ?? newCardId(Api.instance.getUserId(), wt, p.mobile); return this.wrapOtpCall(() => Api.instance.requestOTP(wt, p.mobile, { ...(p.sessionId ? { sessionId: p.sessionId } : {}), ...(p.password ? { password: p.password } : {}), diff --git a/utils/walletCardId.ts b/utils/walletCardId.ts new file mode 100644 index 0000000..32d0d01 --- /dev/null +++ b/utils/walletCardId.ts @@ -0,0 +1,24 @@ +import { WalletType } from 'rnwalletman'; + +/** 钱包类型 → 卡 ID 编码,与 walletman/card_id.go 保持一致 */ +export const WALLET_TYPE_CODES: Record = { + [WalletType.PAYTM_PERSONAL]: '01', + [WalletType.PHONEPE_PERSONAL]: '02', + [WalletType.MOBIKWIK_PERSONAL]: '03', + [WalletType.FREECHARGE_PERSONAL]: '04', + [WalletType.AMAZONPAY_PERSONAL]: '05', + [WalletType.PAYTM_BUSINESS]: '11', + [WalletType.PHONEPE_BUSINESS]: '12', + [WalletType.GOOGLEPAY_BUSINESS]: '13', + [WalletType.BHARATPE_BUSINESS]: '14', +}; + +/** 生成稳定卡 ID:{userId}_{walletTypeCode}_{phone} */ +export function buildWalletCardId( + userId: number | string, + walletType: WalletType | string, + phone: string, +): string { + const code = WALLET_TYPE_CODES[String(walletType)] || '00'; + return `${userId}_${code}_${phone}`; +}