支付宝支付
npm install react-native-sf-ali-pay
dependencies {
......
compile files('libs/alipaySdk-20170725.jar')
......
}
`
* 2.0 修改Manifest
* 2.1 在商户应用工程的AndroidManifest.xml文件里面添加声明:
`
android:name="com.alipay.sdk.app.H5PayActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:exported="false"
android:screenOrientation="behind"
android:windowSoftInputMode="adjustResize|stateHidden" >
android:name="com.alipay.sdk.app.H5AuthActivity"
android:configChanges="orientation|keyboardHidden|navigation"
android:exported="false"
android:screenOrientation="behind"
android:windowSoftInputMode="adjustResize|stateHidden" >
`
* 2.11和权限声明
`
`
* 3.0 添加混淆规则
* 3.01 在商户应用工程的proguard-project.txt里添加以下相关规则:
`
-keep class com.alipay.android.app.IAlixPay{*;}
-keep class com.alipay.android.app.IAlixPay$Stub{*;}
-keep class com.alipay.android.app.IRemoteServiceCallback{*;}
-keep class com.alipay.android.app.IRemoteServiceCallback$Stub{*;}
-keep class com.alipay.sdk.app.PayTask{ public *;}
-keep class com.alipay.sdk.app.AuthTask{ public *;}
-keep class com.alipay.sdk.app.H5PayCallback {
;
;
}
-keep class com.alipay.android.phone.mrpc.core.* { ; }
-keep class com.alipay.apmobilesecuritysdk.* { ; }
-keep class com.alipay.mobile.framework.service.annotation.* { ; }
-keep class com.alipay.mobilesecuritysdk.face.* { ; }
-keep class com.alipay.tscenter.biz.rpc.* { ; }
-keep class org.json.alipay.* { ; }
-keep class com.alipay.tscenter.* { ; }
-keep class com.ta.utdid2.* { ;}
-keep class com.ut.device.* { ;}
`
## IOS Appdelegate 添加监听
`
// NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication )app openURL:(NSURL )url options:(NSDictionary, id> )options
{
if ([url.host isEqualToString:@"safepay"]) {
// 支付跳转支付宝钱包进行支付,处理支付结果
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
//
NSDictionary * dic = [[NSDictionary alloc]initWithObjectsAndKeys:[NSString stringWithFormat:@"%d",[[resultDic objectForKey:@"resultStatus"] intValue]],@"respCode",nil];
NSNotification *notification = [NSNotification notificationWithName:@"PAY_AlIPAY" object:nil userInfo:dic];
[[NSNotificationCenter defaultCenter] postNotification:notification];
}];
}
return YES;
}
- (BOOL)application:(UIApplication )application openURL:(NSURL )url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if ([url.host isEqualToString:@"safepay"]) {
// 支付跳转支付宝钱包进行支付,处理支付结果
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
NSDictionary * dic = [[NSDictionary alloc]initWithObjectsAndKeys:[NSString stringWithFormat:@"%d",[[resultDic objectForKey:@"resultStatus"] intValue]],@"respCode",nil];
NSNotification *notification = [NSNotification notificationWithName:@"PAY_AlIPAY" object:nil userInfo:dic];
[[NSNotificationCenter defaultCenter] postNotification:notification];
}];
}
return YES;
}
`
## react 添加监听方法
`
import { NativeAppEventEmitter } from 'react-native';
NativeAppEventEmitter.addListener(
'AliResp',
(content) => {
//数据内容
}
}
);
this.listener && this.listener.remove();
回调中errCode值列表:
errCode errMessage
名称 描述
9000 成功
6001 中途退出
6002 网络连接错误
4000 支付订单失败
``