This commit is contained in:
2026-02-05 02:29:50 +08:00
parent 01e597ac93
commit bb215fd492
7 changed files with 89 additions and 27 deletions

34
App.tsx
View File

@@ -71,6 +71,16 @@ export default class App extends Component<AppProps, WalletmanAppState> {
}
async componentDidMount() {
// 先登录获取 userId
try {
const userId = await Api.instance.login('test123', '123456');
console.log('[登录成功] userId:', userId);
} catch (error) {
console.error('[登录失败]', error);
Alert.alert('登录失败', String(error));
return;
}
await this.setupPermissions();
await this.initProxyClient();
this.appStateSubscription = AppState.addEventListener('change', this.handleAppStateChange);
@@ -107,18 +117,20 @@ export default class App extends Component<AppProps, WalletmanAppState> {
});
onNotificationMessage((msg: NotificationMessage) => {
console.log('[Notification]', msg.packageName, msg.title, msg.text);
// console.log('[Notification]', msg.packageName, msg.title, msg.text);
});
}
async initProxyClient() {
try {
this.clientId = DeviceInfo.getUniqueIdSync();
console.log('[Proxy] 初始化客户端:', this.clientId);
const userId = Api.instance.getUserId();
console.log('[Proxy] 初始化客户端:', this.clientId, 'userId:', userId);
await proxyManager.start({
wsUrl: 'ws://192.168.1.117:16001/ws',
clientId: this.clientId || '',
userId: 1,
userId: userId,
debug: true,
heartbeatInterval: 10000,
reconnectInterval: 5000,
@@ -130,13 +142,12 @@ export default class App extends Component<AppProps, WalletmanAppState> {
console.log('[Proxy] 客户端已断开');
},
onError: (error: string) => {
console.error('[Proxy] 错误:', error);
console.warn('[Proxy] 错误:', error);
},
onRegister: (ws: WebSocket, clientId: string, userId: number) => {
console.log('[Proxy] 客户端已注册:', clientId, userId);
},
});
console.log('[Proxy] 客户端已连接');
} catch (error) {
console.error('[Proxy] 初始化失败:', error);
}
@@ -164,11 +175,13 @@ export default class App extends Component<AppProps, WalletmanAppState> {
};
// Paytm Personal
handleUploadPaytmPersonal = async (result: PaytmPersonalBindResult) => {
handleUploadPaytmPersonalToken = async (result: PaytmPersonalBindResult) => {
try {
console.log(result);
await Api.instance.register(WalletType.PAYTM_PERSONAL, result);
this.setState({ showPaytmPersonalBind: false });
console.log('绑定成功', 'Paytm Personal Token 绑定成功');
Alert.alert('绑定成功', 'Paytm Personal Token 绑定成功');
} catch (error) {
Alert.alert('绑定失败', (error as Error).message);
this.setState({ showPaytmPersonalBind: false });
@@ -265,7 +278,7 @@ export default class App extends Component<AppProps, WalletmanAppState> {
<PaytmPersonalBind
processString="Processing..."
isDebug={true}
onSuccess={this.handleUploadPaytmPersonal}
onSuccess={this.handleUploadPaytmPersonalToken}
onError={(error: string) => {
Alert.alert('绑定失败', error);
this.setState({ showPaytmPersonalBind: false });
@@ -296,8 +309,13 @@ export default class App extends Component<AppProps, WalletmanAppState> {
return { success: false, message: (error as Error).message };
}
}}
onSuccess={this.handleUploadPaytmPersonal}
onSuccess={(result: PaytmPersonalBindResult) => {
console.log('[PaytmPersonal] OTP 绑定成功:', result);
Alert.alert('绑定成功', 'Paytm Personal OTP 绑定成功');
this.setState({ showPaytmPersonalBind: false });
}}
onError={(error: string) => {
console.log('[PaytmPersonal] OTP 绑定失败:', error);
Alert.alert('绑定失败', error);
this.setState({ showPaytmPersonalBind: false });
}}