From 8a104b3e7f30806073f115ca7c56029e5be72e84 Mon Sep 17 00:00:00 2001 From: TQCasey <494294315@qq.com> Date: Wed, 11 Mar 2026 12:09:01 +0800 Subject: [PATCH] =?UTF-8?q?bharatpe=20business=20=E6=94=B9=E4=B8=BA=20otp?= =?UTF-8?q?=20=E6=A8=A1=E5=BC=8F=20=EF=BC=8C=E5=8E=BB=E9=99=A4=20web=20?= =?UTF-8?q?=E7=9A=84=E6=8A=93=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.tsx | 142 ++++++++++++++++++++++++++-- components/WalletBindComponents.tsx | 25 ++++- servers/walletman | 2 +- 3 files changed, 157 insertions(+), 12 deletions(-) diff --git a/App.tsx b/App.tsx index e147d0b..50fbfe9 100644 --- a/App.tsx +++ b/App.tsx @@ -1,11 +1,10 @@ import React, { Component } from "react"; -import { Alert, AppState, AppStateStatus, Modal, Text, TouchableOpacity, View } from "react-native"; +import { Alert, AppState, AppStateStatus, Modal, Text, TextInput, TouchableOpacity, View } from "react-native"; import DeviceInfo from 'react-native-device-info'; import { PaytmBusinessBind, PhonePeBusinessBind, GooglePayBusinessBind, - BharatPeBusinessBind, WalletType, PaytmBusinessBindResult, PhonePeBusinessBindResult, @@ -32,19 +31,23 @@ import { FreeChargeBind, MobikwikOTPBind, PayTmPersonalOTPBind, - PhonePePersonalOTPBind + PhonePePersonalOTPBind, + BharatPeBusinessOTPBind, } from './components/WalletBindComponents'; import Api from './services/api'; import { AppProps, WalletmanAppState } from './types'; import { styles } from './styles'; +import WebView from "react-native-webview"; export default class App extends Component { private deviceId: string; private tuneUserId: string; private clientId: string = ''; private appStateSubscription?: any; - + + private webViewRef: WebView | null = null; + constructor(props: AppProps) { super(props); this.state = { @@ -234,11 +237,9 @@ export default class App extends Component { // BharatPe Business handleUploadBharatPeBusiness = async (result: BharatPeBusinessBindResult) => { try { - console.log(result); - const response = await Api.instance.register(WalletType.BHARATPE_BUSINESS, result); - console.log(response); + console.log(JSON.stringify(result)); this.setState({ showBharatPeBusinessBind: false }); - + Alert.alert('绑定成功', 'BharatPe Business 绑定成功'); } catch (error) { Alert.alert('绑定失败', (error as Error).message); this.setState({ showBharatPeBusinessBind: false }); @@ -423,9 +424,24 @@ export default class App extends Component { renderBharatPeBusinessBind = () => { return ( this.setState({ showBharatPeBusinessBind: false })}> - { + try { + return await Api.instance.requestOTP(walletType, params.mobile); + } catch (error) { + return { success: false, message: (error as Error).message }; + } + }} + onVerifyOTP={async (walletType, params) => { + try { + return await Api.instance.verifyOTP(walletType, params.mobile, params.otp, { + sessionId: params.sessionId, + }); + } catch (error) { + return { success: false, message: (error as Error).message }; + } + }} onSuccess={this.handleUploadBharatPeBusiness} onError={(error: string) => { Alert.alert('绑定失败', error); @@ -560,7 +576,113 @@ export default class App extends Component { return null; } + renderWebDemo() { + const handleMessage = (event: any) => { + try { + const data = JSON.parse(event.nativeEvent.data); + if (data.type === 'iframe_message') { + console.log('[Demo] iframe message:', data.data); + } + } catch (e) { + console.error('[Demo] Parse error:', e); + } + }; + + const syncToIframe = (fieldId: string, value: string) => { + const js = ` + window.postMessage({ + type: 'set_field', + fieldId: '${fieldId}', + value: '${value.replace(/'/g, "\\'")}' + }, '*'); + `; + this.webViewRef?.injectJavaScript(js); + }; + + const clickLogin = () => { + const js = `window.postMessage({type: 'click_login'}, '*');`; + this.webViewRef?.injectJavaScript(js); + }; + + const injectedJS = ` + window.addEventListener('message', function(event) { + window.ReactNativeWebView.postMessage(JSON.stringify({ + type: 'iframe_message', + data: event.data + })); + }); + true; + `; + + return ( + + { this.webViewRef = ref; }} + source={{ uri: 'https://dashboard.paytm.com' }} + javaScriptEnabled={true} + domStorageEnabled={true} + thirdPartyCookiesEnabled={true} + sharedCookiesEnabled={true} + onMessage={handleMessage} + injectedJavaScript={injectedJS} + interceptUrlPattern="accounts.paytm.com/oauth-js-sdk/" + interceptInjectedScript={` +if (!window.__paytmMessageHandler) { + window.__paytmMessageHandler = function(event) { + if (event.data.type === 'set_field') { + const el = document.getElementById(event.data.fieldId); + if (el) { + el.click(); + el.focus(); + el.value = event.data.value; + el.dispatchEvent(new Event('input', { bubbles: true })); + el.dispatchEvent(new Event('change', { bubbles: true })); + el.dispatchEvent(new Event('blur', { bubbles: true })); + } + } + if (event.data.type === 'click_login') { + const btn = document.getElementById('login_button'); + if (btn) btn.click(); + } + }; + window.addEventListener('message', window.__paytmMessageHandler); + window.parent.postMessage({type: 'iframe_ready'}, '*'); +} + `} + /> + + + Test Controls + + Mobile: + syncToIframe('email_mobile_login', text)} + placeholder="Enter mobile number" + keyboardType="phone-pad" + /> + + Password: + syncToIframe('password_login', text)} + placeholder="Enter password" + secureTextEntry + /> + + + Login + + + + ); + } + render() { + // return this.renderWebDemo(); return ( {(() => { diff --git a/components/WalletBindComponents.tsx b/components/WalletBindComponents.tsx index bc488b8..d953cec 100644 --- a/components/WalletBindComponents.tsx +++ b/components/WalletBindComponents.tsx @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { WalletType, FreechargePersonalBindResult, MobikwikPersonalBindResult, PaytmPersonalBindResult, PhonePePersonalBindResult } from 'rnwalletman'; +import { WalletType, FreechargePersonalBindResult, MobikwikPersonalBindResult, PaytmPersonalBindResult, PhonePePersonalBindResult, BharatPeBusinessBindResult } from 'rnwalletman'; import { OTPBindUI } from './OTPBindUI'; export class FreeChargeBind extends Component<{ @@ -77,6 +77,29 @@ export class PayTmPersonalOTPBind extends Component<{ } } +export class BharatPeBusinessOTPBind extends Component<{ + onRequestOTP: (walletType: WalletType, params: any) => Promise; + onVerifyOTP: (walletType: WalletType, params: any) => Promise; + onSuccess: (result: BharatPeBusinessBindResult) => void; + onError: (error: string) => void; + isDebug: boolean; +}> { + render() { + return ( + + ); + } +} + export class PhonePePersonalOTPBind extends Component<{ onRequestOTP: (walletType: WalletType, params: any) => Promise; onVerifyOTP: (walletType: WalletType, params: any) => Promise; diff --git a/servers/walletman b/servers/walletman index 0eaa98c..ae94e22 160000 --- a/servers/walletman +++ b/servers/walletman @@ -1 +1 @@ -Subproject commit 0eaa98c661d67f02640694d3fd4885ec71b2d170 +Subproject commit ae94e22e384fde8734c6ec575c14c11bc89f724b