gen cardId

This commit is contained in:
2026-07-20 00:27:31 +08:00
parent b47f6019af
commit 5b0a3569a5
2 changed files with 53 additions and 11 deletions
+29 -11
View File
@@ -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<any, HomeScreenState> {
};
// 重绑用原 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<any, HomeScreenState> {
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<any, HomeScreenState> {
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<any, HomeScreenState> {
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<any, HomeScreenState> {
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<any, HomeScreenState> {
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<any, HomeScreenState> {
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<any, HomeScreenState> {
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<any, HomeScreenState> {
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 } : {}),