feat(iOS): Add authInfo feature.
This commit is contained in:
parent
1440075ed4
commit
bd3af94b32
33
README.md
33
README.md
@ -10,8 +10,9 @@ react-native-uiwjs-alipay
|
||||
1. Android:支持2.3及以上的系统版本运行。
|
||||
2. iOS:iOS 6.0以上(包含iOS 6.0)。
|
||||
3. 支持手机系统:iOS(苹果)、Android(安卓)。
|
||||
4. 调试请注意 支付宝接入应用必须 `已审核通过`。
|
||||
5. 适用于 `react-native >= 0.60+` 低版本未测试。
|
||||
4. 调试请注意 支付宝接入应用必须 `已审核通过` 状态。
|
||||
5. 支付宝开放平台-管理中心,签约 `APP支付` 和 `APP支付宝登录` 功能。
|
||||
6. 适用于 `react-native >= 0.60+` 低版本未测试。
|
||||
|
||||
## 安装依赖
|
||||
|
||||
@ -55,6 +56,34 @@ alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=xxxxxxxxxxxxx&biz_content=%7B
|
||||
- ⚠️ 后台 SDK 根据所有数据生成 `sign`,建议通过 API 拿到这个数据,拼接数据会报错。
|
||||
- ⚠️ `out_trade_no` 订单 id 和 `sign` 签名 是唯一的,每次不一样,需要后台生成。
|
||||
|
||||
## 快速登录授权
|
||||
|
||||
> - ⚠️ 注意授权成功返回结果是一个字符串
|
||||
> - ⚠️ 支付宝需要设置 `Scheme` 和 iOS添加原生代码,才能支持验证[回弹商家APP](#支付宝返回应用-ios-设置)的功能
|
||||
> - ⚠️ 支付宝 `管理中心-支付宝开放平台` 需要签约 `APP支付宝登录`
|
||||
|
||||
```javascript
|
||||
import Alipay from 'react-native-uiwjs-alipay';
|
||||
|
||||
// 设置 支付宝 URL Schemes,要表述他是宇宙唯一性,可以使用 `bundle Identifier`
|
||||
// scheme = `alipay` + `APPID`,`APPID` 为支付宝分配给开发者的应用ID
|
||||
Alipay.setAlipayScheme(scheme);
|
||||
// 支付宝端支付
|
||||
// authInfoStr 是后台拼接好的验证参数
|
||||
// 如:apiname=com.alipay.account.auth&app_id=xxxxx&app_name=mc&auth_type=AUTHACCOUNT&biz_type=openservice&method=alipay.open.auth.sdk.code.get&pid=xxxxx&product_id=APP_FAST_LOGIN&scope=kuaijie&sign_type=RSA2&target_id=20141225xxxx&sign=fMcp4GtiM6rxSIeFnJCVePJKV43eXrUP86CQgiLhDHH2u%2FdN75eEvmywc2ulkm7qKRetkU9fbVZtJIqFdMJcJ9Yp%2BJI%2FF%2FpESafFR6rB2fRjiQQLGXvxmDGVMjPSxHxVtIqpZy5FDoKUSjQ2%2FILDKpu3%2F%2BtAtm2jRw1rUoMhgt0%3D
|
||||
Alipay.authInfo(authInfoStr, (res)=> console.log(res))
|
||||
```
|
||||
|
||||
授权返回结果,支付宝[返回结果参数说明](https://opendocs.alipay.com/open/218/105327#%E8%BF%94%E5%9B%9E%E7%BB%93%E6%9E%9C%E8%AF%B4%E6%98%8E):
|
||||
|
||||
```json
|
||||
{
|
||||
"resultStatus": 9000,
|
||||
"memo": "处理成功",
|
||||
"result": "success=true&result_code=200&app_id=202100117265&auth_code=8b6e5581b85WX84&scope=kuaijie&alipay_open_id=20881029919664670&user_id=20880025&target_id=15946456110003465"
|
||||
}
|
||||
```
|
||||
|
||||
## 支付宝返回应用 iOS 设置
|
||||
|
||||
⚠️ Android 端不需要做任何设置。
|
||||
|
@ -5,28 +5,19 @@ import Alipay from 'react-native-uiwjs-alipay';
|
||||
export default class App extends Component {
|
||||
componentDidMount() {
|
||||
Alipay.setAlipayScheme('uiwjspay');
|
||||
AppState.addEventListener('change', this._handleAppStateChange);
|
||||
}
|
||||
componentWillUnmount(){
|
||||
AppState.removeEventListener('change', this._handleAppStateChange)
|
||||
}
|
||||
// [info][tid:com.facebook.react.JavaScript] 'nextAppState:', 'inactive'
|
||||
// [info][tid:com.facebook.react.JavaScript] 'nextAppState:', 'background'
|
||||
// [info][tid:com.facebook.react.JavaScript] 'nextAppState:', 'active'
|
||||
// [info][tid:com.facebook.react.JavaScript] 'nextAppState:res:', null
|
||||
_handleAppStateChange = (nextAppState) => {
|
||||
console.log('nextAppState:', nextAppState)
|
||||
if(nextAppState==='active'){
|
||||
Linking.getInitialURL().then(res => {
|
||||
console.log('nextAppState:res:', res)
|
||||
})
|
||||
}
|
||||
}
|
||||
aliPay = () => {
|
||||
// return_url=
|
||||
const payInfo = `alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2021001172656340&biz_content=%7B%22out_trade_no%22%3A%221111112222222%22%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%221234%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&charset=UTF-8&format=json&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2Fane.boshu.ltd%2Fowner%2Fpay%2Fapi%2FownerPay%2Fcallback&sign=oUQmGtkv8mrhJ0YwHl9%2FfxMcoLACWuSFKiMTC4Id8nc%2FZVvDQ6MLQq5hhtEN03Qn1%2BAtzTAaofE8nNixdroxOek2l5YtOAcYcXVYlJIyogN%2B22erN2NpDTWJ7tQTKgYFDJLRiG0DZJaxfADhUUF6UR9kdA8omoXKLDlP17ZPUs5Jr4aKv5HJtH5C53ui7PbmyWYg934L4UDC2F%2F9pPQlRwwDeE1SAaV3HW9Dt83kK52o8%2FlChXdotbFdAvH0d4qYGhpEYU5sepj9xiOMyL9aC4pMXW9INYLLGbvtqtlRchZTAfH5yji6nqqQm9KKMmcVrWdBDLyjFVNpejq1UjbJBw%3D%3D&sign_type=RSA2×tamp=2020-07-09+12%3A16%3A16&version=1.0`;
|
||||
const payInfo = 'alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2021001172656340&biz_content=%7B%22out_trade_no%22%3A%221111112222222%22%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%221234%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&charset=UTF-8&format=json&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2Fane.boshu.ltd%2Fowner%2Fpay%2Fapi%2FownerPay%2Fcallback&sign=oUQmGtkv8mrhJ0YwHl9%2FfxMcoLACWuSFKiMTC4Id8nc%2FZVvDQ6MLQq5hhtEN03Qn1%2BAtzTAaofE8nNixdroxOek2l5YtOAcYcXVYlJIyogN%2B22erN2NpDTWJ7tQTKgYFDJLRiG0DZJaxfADhUUF6UR9kdA8omoXKLDlP17ZPUs5Jr4aKv5HJtH5C53ui7PbmyWYg934L4UDC2F%2F9pPQlRwwDeE1SAaV3HW9Dt83kK52o8%2FlChXdotbFdAvH0d4qYGhpEYU5sepj9xiOMyL9aC4pMXW9INYLLGbvtqtlRchZTAfH5yji6nqqQm9KKMmcVrWdBDLyjFVNpejq1UjbJBw%3D%3D&sign_type=RSA2×tamp=2020-07-09+12%3A16%3A16&version=1.0';
|
||||
Alipay.alipay(payInfo, (resule) => {
|
||||
console.log('resule-->>>', resule)
|
||||
console.log('alipay:resule-->>>', resule)
|
||||
});
|
||||
}
|
||||
authInfo = () => {
|
||||
const authInfoStr = 'app_name=mc&auth_type=AUTHACCOUNT&apiname=com.alipay.account.auth&biz_type=openservice&product_id=APP_FAST_LOGIN&scope=kuaijie&pid=2088421915791034&target_id=15946456110003465&app_id=2021001172656340&sign_type=RSA2&sign=keluG28qbbLwAcSDI4VmCNOGHJoF3xgpVeqXu1nCBCYo%2FlYYGe00fTfV9L4G73Sk7%2B4IwK%2BZV8IL%2F04cVtk6SR74lKAR3rYOoUdQ09ZrZFuQoUkO0vekajhp75IDQIg6PedCyY0SjFTqrHlH%2FImscBwitxrlSc9YbN7uW0gY34K8t7v8NhDoqzKJeoIz43UxF5U1DpUA1ISBVxwO7du1t6rYltsRhReayPS3hnvmwYSKQZUEgBvJ%2BT2XdyCaz%2FdGV907lYagPp1Oxkoaj%2FvW5NjNsRnid7vH944CoFj9XtBK%2FNTk2tBPTHFxYRQTEG1PkgkBohGpAWOFGGOuapH0ag%3D%3D';
|
||||
Alipay.authInfo(authInfoStr, (resule) => {
|
||||
// resule => success=true&auth_code=9c11732de44f4f1790b63978b6fbOX53&result_code=200&alipay_open_id=20881001757376426161095132517425&user_id=2088003646494707
|
||||
console.log('authInfo:resule-->>>', resule)
|
||||
});
|
||||
}
|
||||
render() {
|
||||
@ -39,6 +30,12 @@ export default class App extends Component {
|
||||
color="#841584"
|
||||
accessibilityLabel="Learn more about this purple button"
|
||||
/>
|
||||
<Button
|
||||
onPress={this.authInfo}
|
||||
title="登录验证"
|
||||
color="#841584"
|
||||
accessibilityLabel="Learn more about this purple button"
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
50
index.d.ts
vendored
50
index.d.ts
vendored
@ -47,13 +47,13 @@ export interface AliOrderResult {
|
||||
}
|
||||
|
||||
|
||||
|
||||
interface Resule {
|
||||
interface OrderResult {
|
||||
/**
|
||||
* "Error Domain=系统繁忙,请稍后再试 Code=1000 "(null)""
|
||||
* 优惠券备注信息
|
||||
* @callback AliOrderResult
|
||||
* 支付返回结果:
|
||||
* 支付宝支付返回结果文档地址:https://opendocs.alipay.com/open/204/105301#%E8%BF%94%E5%9B%9E%E7%BB%93%E6%9E%9C%E7%A4%BA%E4%BE%8B%EF%BC%88iOS%7CAndroid%EF%BC%89
|
||||
* '{"alipay_trade_app_pay_response":{"code":"10000","msg":"Success","app_id":"2021001172656340","auth_app_id":"2021001172656340","charset":"UTF-8","timestamp":"2020-07-08 21:30:14","out_trade_no":"123123213123214","total_amount":"0.01","trade_no":"2020070822001414841426413774","seller_id":"2088421915791034"},"sign":"LY7wCsNLp+QnDqCq6VelY/RvyK7ZGY8wsXoKvS+Or7JjONLDUx5P6lDgqRKkpkng7br3y6GZzfGKaZ88Tf4eMnBMKyqU+huR2Um47xUxP383njvHlxuQZsSTLQZRswy4wmb/fPkFfvyH6Or6+oj0eboePOTu63bNr+h03w0QnP4znuHpfRuoVgWpsYh/6B1DL+4xfWRKJ21zm1SV9Feo9RWqnyTaGZyFVi6IKge0dUCYs9hXju95fOUVUOx5YflOFtSEnZafY9Ls4FCRQE1ANkjaKiKIE0+c4c4sEVEf/9Dwh88N+aSQOoLT+AV4RpjMoA8hF2k+vv2OKNeqr6SYGQ==","sign_type":"RSA2"}'
|
||||
*/
|
||||
memo: string;
|
||||
result?: string;
|
||||
/**
|
||||
* 9000 订单支付成功
|
||||
@ -66,6 +66,11 @@ interface Resule {
|
||||
* 其它 其它支付错误
|
||||
*/
|
||||
resultStatus?: '9000' | '8000' | '4000' | '5000' | '6001' | '6002' | '6004' | string;
|
||||
/**
|
||||
* "Error Domain=系统繁忙,请稍后再试 Code=1000 "(null)""
|
||||
* 优惠券备注信息
|
||||
*/
|
||||
memo: string;
|
||||
}
|
||||
|
||||
// 错误返回
|
||||
@ -81,13 +86,46 @@ interface Resule {
|
||||
// memo: ''
|
||||
// }
|
||||
|
||||
/**
|
||||
* 快速登录授权
|
||||
* https://opendocs.alipay.com/open/218/105327#%E8%BF%94%E5%9B%9E%E7%BB%93%E6%9E%9C%E8%AF%B4%E6%98%8E
|
||||
*/
|
||||
interface AuthResult {
|
||||
/**
|
||||
* 长度:144,本次操作返回的结果数据。
|
||||
* - `result_code` 具体状态码值请参见“result_code状态代码”。仅当resultStatus为“9000”且result_code为“200”时,代表授权成功。
|
||||
* - `auth_code` 表示授权成功的授码。
|
||||
* @example `success=true&auth_code=9c11732de44f4f1790b63978b6fbOX53&result_code=200&alipay_open_id=20881001757376426161095132517425&user_id=2088003646494707`
|
||||
*/
|
||||
result: string;
|
||||
/**
|
||||
* 长度:5,本次操作的状态返回值,标识本次调用的结果,参见“resultStatus状态代码”。
|
||||
* - 9000 请求处理成功
|
||||
* - 4000 系统异常
|
||||
* - 6001 用户中途取消
|
||||
* - 6002 网络连接出错
|
||||
*/
|
||||
resultStatus: 9000 | 4000 | 6001 | 6002;
|
||||
/**
|
||||
* 长度:无,保留参数,一般无内容。 处理成功
|
||||
*/
|
||||
memo: string;
|
||||
}
|
||||
|
||||
|
||||
export const Alipay: {
|
||||
/**
|
||||
* 支付
|
||||
* @param payInfo 支付详情
|
||||
* @param result 支付宝回调结果
|
||||
*/
|
||||
alipay: (payInfo: string, callback?: (result: Resule) => void) => void;
|
||||
alipay: (payInfo: string, callback?: (result: OrderResult) => void) => void;
|
||||
/**
|
||||
* 快速登录授权
|
||||
* @param authInfoStr 验证详情
|
||||
* @param result 支付宝回调结果
|
||||
*/
|
||||
authInfo: (authInfoStr: string, callback?: (result: AuthResult) => void) => void;
|
||||
/**
|
||||
* 设置支付宝跳转Scheme,仅 iOS
|
||||
* @param scheme scheme = `ap` + `APPID`
|
||||
|
9
index.js
9
index.js
@ -11,6 +11,15 @@ export default class Alipay {
|
||||
NativeModules.Alipay.alipay(orderInfo, callback)
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝授权请求信息
|
||||
* @param infoStr 授权请求信息字串
|
||||
* @param callback 授权结果回调 详情见 https://opendocs.alipay.com/open/218/105325
|
||||
*/
|
||||
static authInfo(infoStr, callback) {
|
||||
NativeModules.Alipay.authInfo(infoStr, callback)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置支付宝跳转Scheme,仅 iOS
|
||||
* @param scheme
|
||||
|
13
ios/Alipay.m
13
ios/Alipay.m
@ -66,13 +66,24 @@ RCT_EXPORT_MODULE()
|
||||
RCT_EXPORT_METHOD(setAlipayScheme:(NSString *)scheme){
|
||||
alipayScheme = scheme;
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(alipay:(NSString *)info callback:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
alipayCallBack = callback;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[AlipaySDK defaultService] payOrder:info fromScheme:alipayScheme callback:^(NSDictionary *resultDic) {
|
||||
NSLog(@"alipay:callback");
|
||||
NSLog(@"alipay:payOrder:callback", resultDic);
|
||||
callback([[NSArray alloc] initWithObjects:resultDic, nil]);
|
||||
}];
|
||||
});
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(authInfo:(NSString *)info callback:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
alipayCallBack = callback;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[AlipaySDK defaultService] auth_V2WithInfo:info fromScheme:alipayScheme callback:^(NSDictionary *resultDic) {
|
||||
NSLog(@"alipay:auth_V2WithInfo:callback", resultDic);
|
||||
callback([[NSArray alloc] initWithObjects:resultDic, nil]);
|
||||
}];
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user