gen cardId
This commit is contained in:
+29
-11
@@ -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 } : {}),
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { WalletType } from 'rnwalletman';
|
||||
|
||||
/** 钱包类型 → 卡 ID 编码,与 walletman/card_id.go 保持一致 */
|
||||
export const WALLET_TYPE_CODES: Record<string, string> = {
|
||||
[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}`;
|
||||
}
|
||||
Reference in New Issue
Block a user