Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
004af0975b | ||
![]() |
cf0ca78dc7 | ||
![]() |
175f295f8f | ||
![]() |
ddae4e78c1 | ||
![]() |
c16c1be2c0 | ||
![]() |
fb9a44575d | ||
![]() |
90361afb76 | ||
![]() |
05b4dc3d87 |
63
.npmignore
Normal file
63
.npmignore
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
# JS
|
||||||
|
node_modules
|
||||||
|
yarn.lock
|
||||||
|
|
||||||
|
# Config files
|
||||||
|
renovate.json
|
||||||
|
|
||||||
|
# Example
|
||||||
|
example/
|
||||||
|
|
||||||
|
# Android
|
||||||
|
android/*/build/
|
||||||
|
android/gradlew
|
||||||
|
android/build
|
||||||
|
android/gradlew.bat
|
||||||
|
android/gradle/
|
||||||
|
android/com_crashlytics_export_strings.xml
|
||||||
|
android/local.properties
|
||||||
|
android/.gradle/
|
||||||
|
android/.signing/
|
||||||
|
android/.idea/gradle.xml
|
||||||
|
android/.idea/libraries/
|
||||||
|
android/.idea/workspace.xml
|
||||||
|
android/.idea/tasks.xml
|
||||||
|
android/.idea/.name
|
||||||
|
android/.idea/compiler.xml
|
||||||
|
android/.idea/copyright/profiles_settings.xml
|
||||||
|
android/.idea/encodings.xml
|
||||||
|
android/.idea/misc.xml
|
||||||
|
android/.idea/modules.xml
|
||||||
|
android/.idea/scopes/scope_settings.xml
|
||||||
|
android/.idea/vcs.xml
|
||||||
|
android/*.iml
|
||||||
|
android/.settings
|
||||||
|
|
||||||
|
# iOS
|
||||||
|
ios/*.xcodeproj/xcuserdata
|
||||||
|
*.pbxuser
|
||||||
|
*.mode1v3
|
||||||
|
*.mode2v3
|
||||||
|
*.perspectivev3
|
||||||
|
*.xcuserstate
|
||||||
|
project.xcworkspace/
|
||||||
|
xcuserdata/
|
||||||
|
ios/build/
|
||||||
|
|
||||||
|
# Misc
|
||||||
|
.DS_Store
|
||||||
|
.DS_Store?
|
||||||
|
coverage.android.json
|
||||||
|
coverage.ios.json
|
||||||
|
npm-debug.log
|
||||||
|
.github
|
||||||
|
._*
|
||||||
|
.Spotlight-V100
|
||||||
|
.Trashes
|
||||||
|
ehthumbs.db
|
||||||
|
Thumbs.dbandroid/gradle
|
||||||
|
docs
|
||||||
|
.idea
|
||||||
|
bin/test.js
|
||||||
|
codorials
|
||||||
|
website/
|
56
README.md
56
README.md
@@ -1,12 +1,16 @@
|
|||||||
react-native-uiwjs-alipay
|
react-native-uiwjs-alipay
|
||||||
===
|
===
|
||||||
|
|
||||||
|
[](https://npmjs.org/package/jaywcjlove/react-native-uiwjs-alipay)
|
||||||
|
|
||||||
基于 React Native 的宝支付插件。适用于商家在 App 应用中集成支付宝支付功能,商家 APP 调用支付宝提供的 SDK,SDK 再调用支付宝 APP 内的支付模块。如果用户已安装支付宝APP,商家APP会跳转到支付宝中完成支付,支付完后跳回到商家 APP 内,最后展示支付结果。如果用户没有安装支付宝 APP,商家 APP 内会调起支付宝网页支付收银台,用户登录支付宝账户,支付完后展示支付结果。完整实例 [Example](./example)
|
基于 React Native 的宝支付插件。适用于商家在 App 应用中集成支付宝支付功能,商家 APP 调用支付宝提供的 SDK,SDK 再调用支付宝 APP 内的支付模块。如果用户已安装支付宝APP,商家APP会跳转到支付宝中完成支付,支付完后跳回到商家 APP 内,最后展示支付结果。如果用户没有安装支付宝 APP,商家 APP 内会调起支付宝网页支付收银台,用户登录支付宝账户,支付完后展示支付结果。完整实例 [Example](./example)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
1. Android:支持2.3及以上的系统版本运行。
|
1. Android:支持2.3及以上的系统版本运行。
|
||||||
2. iOS:iOS 6.0以上(包含iOS 6.0)。
|
2. iOS:iOS 6.0以上(包含iOS 6.0)。
|
||||||
3. 支持手机系统:iOS(苹果)、Android(安卓)。
|
3. 支持手机系统:iOS(苹果)、Android(安卓)。
|
||||||
@@ -26,7 +30,9 @@ $ cd ios && pod install
|
|||||||
|
|
||||||
### `Alipay.alipay` 支付
|
### `Alipay.alipay` 支付
|
||||||
|
|
||||||
- ⚠️ 注意支付成功返回结果是一个字符串,[返回内容](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/4c89c4e0e623e5073e4dc84a86978b1c5da18704/index.d.ts#L50-L74)
|
> `Alipay.alipay: (payInfo: string) => Promise<OrderResult>;`
|
||||||
|
|
||||||
|
- ⚠️ 注意支付成功返回结果是一个字符串,[返回内容](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/05b4dc3d87ea309b6b6153690faee508cd23e2bf/index.d.ts#L50-L74)
|
||||||
- ⚠️ 支付宝需要设置 `Scheme` 和 iOS添加原生代码,才能支持支付和[回弹商家APP](#支付宝返回应用-ios-设置)的功能
|
- ⚠️ 支付宝需要设置 `Scheme` 和 iOS添加原生代码,才能支持支付和[回弹商家APP](#支付宝返回应用-ios-设置)的功能
|
||||||
- ⚠️ 支付宝 `管理中心-支付宝开放平台` 需要签约 [`APP支付`](https://opendocs.alipay.com/open/200/105310#%E6%B7%BB%E5%8A%A0%E5%BA%94%E7%94%A8%E5%8A%9F%E8%83%BD)
|
- ⚠️ 支付宝 `管理中心-支付宝开放平台` 需要签约 [`APP支付`](https://opendocs.alipay.com/open/200/105310#%E6%B7%BB%E5%8A%A0%E5%BA%94%E7%94%A8%E5%8A%9F%E8%83%BD)
|
||||||
|
|
||||||
@@ -38,9 +44,15 @@ import Alipay from 'react-native-uiwjs-alipay';
|
|||||||
Alipay.setAlipayScheme(scheme);
|
Alipay.setAlipayScheme(scheme);
|
||||||
// ⚠️ 目前不可用,设置支付宝沙箱环境,仅 Android 支持
|
// ⚠️ 目前不可用,设置支付宝沙箱环境,仅 Android 支持
|
||||||
// Alipay.setAlipaySandbox(isSandbox);
|
// Alipay.setAlipaySandbox(isSandbox);
|
||||||
|
|
||||||
|
async function aliPay() {
|
||||||
// 支付宝端支付
|
// 支付宝端支付
|
||||||
// payInfo 是后台拼接好的支付参数
|
// payInfo 是后台拼接好的支付参数
|
||||||
Alipay.alipay(payInfo, (res)=> console.log(res))
|
// 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 resule = await Alipay.alipay(payInfo);
|
||||||
|
console.log('alipay:resule-->>>', resule);
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
订单详情 [`payInfo`](https://opendocs.alipay.com/open/204/105295#%E5%BF%AB%E6%8D%B7%E8%AE%A2%E5%8D%95%E6%94%AF%E4%BB%98%20iOS) 编码前的数据
|
订单详情 [`payInfo`](https://opendocs.alipay.com/open/204/105295#%E5%BF%AB%E6%8D%B7%E8%AE%A2%E5%8D%95%E6%94%AF%E4%BB%98%20iOS) 编码前的数据
|
||||||
@@ -58,7 +70,7 @@ alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=xxxxxxxxxxxxx&biz_content=%7B
|
|||||||
- ⚠️ 后台 SDK 根据所有数据生成 `sign`,建议通过 API 拿到这个数据,拼接数据会报错。
|
- ⚠️ 后台 SDK 根据所有数据生成 `sign`,建议通过 API 拿到这个数据,拼接数据会报错。
|
||||||
- ⚠️ `out_trade_no` 订单 id 和 `sign` 签名 是唯一的,每次不一样,需要后台生成。
|
- ⚠️ `out_trade_no` 订单 id 和 `sign` 签名 是唯一的,每次不一样,需要后台生成。
|
||||||
|
|
||||||
支付返回结果,支付宝[返回结果参数说明](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/4c89c4e0e623e5073e4dc84a86978b1c5da18704/index.d.ts#L50-L74):
|
支付返回结果,支付宝[返回结果参数说明](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/05b4dc3d87ea309b6b6153690faee508cd23e2bf/index.d.ts#L50-L74):
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@@ -70,7 +82,9 @@ alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=xxxxxxxxxxxxx&biz_content=%7B
|
|||||||
|
|
||||||
### `Alipay.authInfo` 登录授权
|
### `Alipay.authInfo` 登录授权
|
||||||
|
|
||||||
- ⚠️ 注意授权成功返回结果是一个字符串,[返回内容](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/4c89c4e0e623e5073e4dc84a86978b1c5da18704/index.d.ts#L89-L113)
|
> `Alipay.authInfo: (authInfoStr: string) => Promise<AuthResult>`;
|
||||||
|
|
||||||
|
- ⚠️ 注意授权成功返回结果是一个字符串,[返回内容](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/05b4dc3d87ea309b6b6153690faee508cd23e2bf/index.d.ts#L89-L113)
|
||||||
- ⚠️ 支付宝需要设置 `Scheme` 和 iOS添加原生代码,才能支持验证[回弹商家APP](#支付宝返回应用-ios-设置)的功能
|
- ⚠️ 支付宝需要设置 `Scheme` 和 iOS添加原生代码,才能支持验证[回弹商家APP](#支付宝返回应用-ios-设置)的功能
|
||||||
- ⚠️ 支付宝 `管理中心-支付宝开放平台` 需要签约 [`APP支付宝登录`](https://opendocs.alipay.com/open/200/105310#%E6%B7%BB%E5%8A%A0%E5%BA%94%E7%94%A8%E5%8A%9F%E8%83%BD)
|
- ⚠️ 支付宝 `管理中心-支付宝开放平台` 需要签约 [`APP支付宝登录`](https://opendocs.alipay.com/open/200/105310#%E6%B7%BB%E5%8A%A0%E5%BA%94%E7%94%A8%E5%8A%9F%E8%83%BD)
|
||||||
|
|
||||||
@@ -80,13 +94,18 @@ import Alipay from 'react-native-uiwjs-alipay';
|
|||||||
// 设置 支付宝 URL Schemes,要表述他是宇宙唯一性,可以使用 `bundle Identifier`
|
// 设置 支付宝 URL Schemes,要表述他是宇宙唯一性,可以使用 `bundle Identifier`
|
||||||
// scheme = `alipay` + `APPID`,`APPID` 为支付宝分配给开发者的应用ID
|
// scheme = `alipay` + `APPID`,`APPID` 为支付宝分配给开发者的应用ID
|
||||||
Alipay.setAlipayScheme(scheme);
|
Alipay.setAlipayScheme(scheme);
|
||||||
// 支付宝端支付
|
|
||||||
|
async function authInfo() {
|
||||||
|
// 支付宝端授权验证
|
||||||
// authInfoStr 是后台拼接好的验证参数
|
// 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
|
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, (res)=> console.log(res))
|
const resule = await Alipay.authInfo(authInfoStr);
|
||||||
|
// resule => success=true&auth_code=9c11732de44f4f1790b63978b6fbOX53&result_code=200&alipay_open_id=20881001757376426161095132517425&user_id=2088003646494707
|
||||||
|
console.log('authInfo:resule-->>>', resule);
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
授权返回结果,支付宝[返回结果参数说明](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/4c89c4e0e623e5073e4dc84a86978b1c5da18704/index.d.ts#L89-L113):
|
授权返回结果,支付宝[返回结果参数说明](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/05b4dc3d87ea309b6b6153690faee508cd23e2bf/index.d.ts#L89-L113):
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@@ -96,25 +115,38 @@ Alipay.authInfo(authInfoStr, (res)=> console.log(res))
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `Alipay.getVersion` 获取 SDK 版本
|
||||||
|
|
||||||
|
> `Alipay.getVersion: () => Promise<string>;`
|
||||||
|
|
||||||
|
```js
|
||||||
|
import Alipay from 'react-native-uiwjs-alipay';
|
||||||
|
|
||||||
|
async function getVersion() {
|
||||||
|
const version = await Alipay.getVersion();
|
||||||
|
console.log('version:', version);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 支付宝返回应用 iOS 设置
|
## 支付宝返回应用 iOS 设置
|
||||||
|
|
||||||
- ⚠️ Android 端不需要做任何设置。
|
- ⚠️ Android 端不需要做任何设置。
|
||||||
- ⚠️ 如果用户从 `支付宝App` 跳转到 `商家APP`,是通过系统功能切换,而不是通过 `支付宝APP` 功能键返回 `商家APP`,回调函数是不起作用的,可通过 [`AppState.addEventListener`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/5daea87bf0af05d60d0ae9e4c04e1e2d1a6e4273/example/App.js#L8-L24) 监听事件请求后台 API,来优化这一用户体验。
|
- ⚠️ 如果用户从 `支付宝App` 跳转到 `商家APP`,是通过系统功能切换,而不是通过 `支付宝APP` 功能键返回 `商家APP`,回调函数是不起作用的,可通过 [`AppState.addEventListener`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/5daea87bf0af05d60d0ae9e4c04e1e2d1a6e4273/example/App.js#L8-L24) 监听事件请求后台 API,来优化这一用户体验。
|
||||||
|
|
||||||
1. 在代码中设置支付宝 [`URL Schemes`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/5daea87bf0af05d60d0ae9e4c04e1e2d1a6e4273/example/App.js#L7),下面实例 [`uiwjspay`](https://github.com/uiwjs/react-native-uiwjs-alipay/commit/f6d21b6b7ec7236b195c56281f971092f3c9bb08) 是定义的 `scheme`,你也可以定义为 `alipay` + `appid`,`appid` 为支付宝分配给开发者的应用ID,用来表述 `scheme` 唯一性。
|
1. 在代码中设置支付宝 [`URL Schemes`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/05b4dc3d87ea309b6b6153690faee508cd23e2bf/example/App.js#L7),下面实例 [`uiwjspay`](https://github.com/uiwjs/react-native-uiwjs-alipay/commit/f6d21b6b7ec7236b195c56281f971092f3c9bb08) 是定义的 `scheme`,你也可以定义为 `alipay` + `appid`,`appid` 为支付宝分配给开发者的应用ID,用来表述 `scheme` 唯一性。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
Alipay.setAlipayScheme('uiwjspay');
|
Alipay.setAlipayScheme('uiwjspay');
|
||||||
```
|
```
|
||||||
|
|
||||||
2. 在请求支付的 [`payInfo`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/1eff1dd94f3ae733db2913400e1aac382d056871/example/App.js#L27-L30) 中必须包含 [`return_url=uiwjspay://`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/5daea87bf0af05d60d0ae9e4c04e1e2d1a6e4273/example/App.js#L27-L28),`return_url` 的值为定义的 `scheme` => `uiwjspay://`,才会返回[支付宝订单支付状态结果](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)
|
2. 在请求支付的 [`payInfo`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/05b4dc3d87ea309b6b6153690faee508cd23e2bf/example/App.js#L11) 中必须包含 [`return_url=uiwjspay://`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/05b4dc3d87ea309b6b6153690faee508cd23e2bf/example/App.js#L11),`return_url` 的值为定义的 `scheme` => `uiwjspay://`,才会返回[支付宝订单支付状态结果](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)
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// payInfo 是后台拼接好的支付参数,这个参数必须包含 `return_url=uiwjspay://`
|
// payInfo 是后台拼接好的支付参数,这个参数必须包含 `return_url=uiwjspay://`
|
||||||
Alipay.alipay(payInfo, (res)=>console.log(res))
|
Alipay.alipay(payInfo, (res)=>console.log(res))
|
||||||
```
|
```
|
||||||
|
|
||||||
3. 用的 `URL Schemes` 列为白名单,在 [`ios/<应用名称>/Info.plist`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/5daea87bf0af05d60d0ae9e4c04e1e2d1a6e4273/example/ios/example/Info.plist#L23-L41) 中添加
|
3. 用的 `URL Schemes` 列为白名单,在 [`ios/<应用名称>/Info.plist`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/05b4dc3d87ea309b6b6153690faee508cd23e2bf/example/ios/example/Info.plist#L23-L41) 中添加
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<key>LSApplicationQueriesSchemes</key>
|
<key>LSApplicationQueriesSchemes</key>
|
||||||
@@ -136,7 +168,7 @@ Alipay.alipay(payInfo, (res)=>console.log(res))
|
|||||||
</array>
|
</array>
|
||||||
```
|
```
|
||||||
|
|
||||||
4. 修改 [`ios/<应用名称>/AppDelegate.m`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/4329bd62443bf377221860cd1acfaa710bbe562d/example/ios/example/AppDelegate.m#L60-L70) 添加下列代码:
|
4. 修改 [`ios/<应用名称>/AppDelegate.m`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/05b4dc3d87ea309b6b6153690faee508cd23e2bf/example/ios/example/AppDelegate.m#L60-L70) 添加下列代码:
|
||||||
|
|
||||||
```objective-c
|
```objective-c
|
||||||
#import <React/RCTLinkingManager.h>
|
#import <React/RCTLinkingManager.h>
|
||||||
|
@@ -35,13 +35,13 @@ public class AlipayModule extends ReactContextBaseJavaModule {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void authInfo(final String infoStr, final Callback promise) {
|
public void authInfo(final String infoStr, final Promise promise) {
|
||||||
Runnable runnable = new Runnable() {
|
Runnable runnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
AuthTask alipay = new AuthTask(getCurrentActivity());
|
AuthTask authTask = new AuthTask(getCurrentActivity());
|
||||||
Map<String, String> map = alipay.authV2(infoStr, true);
|
Map<String, String> map = authTask.authV2(infoStr, true);
|
||||||
promise.invoke(getWritableMap(map));
|
promise.resolve(getWritableMap(map));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Thread thread = new Thread(runnable);
|
Thread thread = new Thread(runnable);
|
||||||
@@ -57,13 +57,13 @@ public class AlipayModule extends ReactContextBaseJavaModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void alipay(final String orderInfo, final Callback promise) {
|
public void alipay(final String orderInfo, final Promise promise) {
|
||||||
Runnable payRunnable = new Runnable() {
|
Runnable payRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PayTask alipay = new PayTask(getCurrentActivity());
|
PayTask alipay = new PayTask(getCurrentActivity());
|
||||||
Map<String, String> result = alipay.payV2(orderInfo, true);
|
Map<String, String> result = alipay.payV2(orderInfo, true);
|
||||||
promise.invoke(getWritableMap(result));
|
promise.resolve(getWritableMap(result));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// 必须异步调用
|
// 必须异步调用
|
||||||
@@ -71,6 +71,12 @@ public class AlipayModule extends ReactContextBaseJavaModule {
|
|||||||
payThread.start();
|
payThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void getVersion(Promise promise) {
|
||||||
|
PayTask payTask = new PayTask(getCurrentActivity());
|
||||||
|
promise.resolve(payTask.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
private WritableMap getWritableMap(Map<String, String> map) {
|
private WritableMap getWritableMap(Map<String, String> map) {
|
||||||
WritableMap writableMap = Arguments.createMap();
|
WritableMap writableMap = Arguments.createMap();
|
||||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
|
@@ -3,22 +3,31 @@ import { Button, StyleSheet, Text, View, Linking, AppState } from 'react-native'
|
|||||||
import Alipay from 'react-native-uiwjs-alipay';
|
import Alipay from 'react-native-uiwjs-alipay';
|
||||||
|
|
||||||
export default class App extends Component {
|
export default class App extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
version: '',
|
||||||
|
}
|
||||||
|
}
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
Alipay.setAlipayScheme('uiwjspay');
|
Alipay.setAlipayScheme('uiwjspay');
|
||||||
}
|
}
|
||||||
aliPay = () => {
|
aliPay = async () => {
|
||||||
// return_url=
|
// 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) => {
|
const resule = await Alipay.alipay(payInfo);
|
||||||
console.log('alipay:resule-->>>', resule)
|
console.log('alipay:resule-->>>', resule);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
authInfo = () => {
|
authInfo = async () => {
|
||||||
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';
|
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) => {
|
const resule = await Alipay.authInfo(authInfoStr);
|
||||||
// resule => success=true&auth_code=9c11732de44f4f1790b63978b6fbOX53&result_code=200&alipay_open_id=20881001757376426161095132517425&user_id=2088003646494707
|
// resule => success=true&auth_code=9c11732de44f4f1790b63978b6fbOX53&result_code=200&alipay_open_id=20881001757376426161095132517425&user_id=2088003646494707
|
||||||
console.log('authInfo:resule-->>>', resule)
|
console.log('authInfo:resule-->>>', resule);
|
||||||
});
|
}
|
||||||
|
getVersion = async () => {
|
||||||
|
const version = await Alipay.getVersion();
|
||||||
|
this.setState({ version });
|
||||||
|
console.log('version:', version);
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@@ -36,6 +45,12 @@ export default class App extends Component {
|
|||||||
color="#841584"
|
color="#841584"
|
||||||
accessibilityLabel="Learn more about this purple button"
|
accessibilityLabel="Learn more about this purple button"
|
||||||
/>
|
/>
|
||||||
|
<Button
|
||||||
|
onPress={this.getVersion}
|
||||||
|
title="获取 SDK 版本"
|
||||||
|
color="#841584"
|
||||||
|
/>
|
||||||
|
<Text>{this.state.version}</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
13
index.d.ts
vendored
13
index.d.ts
vendored
@@ -117,15 +117,20 @@ export const Alipay: {
|
|||||||
/**
|
/**
|
||||||
* 支付
|
* 支付
|
||||||
* @param payInfo 支付详情
|
* @param payInfo 支付详情
|
||||||
* @param result 支付宝回调结果
|
* @returns result 支付宝回调结果 https://docs.open.alipay.com/204/105301
|
||||||
*/
|
*/
|
||||||
alipay: (payInfo: string, callback?: (result: OrderResult) => void) => void;
|
alipay: (payInfo: string) => Promise<OrderResult>;
|
||||||
/**
|
/**
|
||||||
* 快速登录授权
|
* 快速登录授权
|
||||||
* @param authInfoStr 验证详情
|
* @param authInfoStr 验证详情
|
||||||
* @param result 支付宝回调结果
|
* @returns result 支付宝回调结果 https://opendocs.alipay.com/open/218/105327
|
||||||
*/
|
*/
|
||||||
authInfo: (authInfoStr: string, callback?: (result: AuthResult) => void) => void;
|
authInfo: (authInfoStr: string) => Promise<AuthResult>;
|
||||||
|
/**
|
||||||
|
* 获取当前 SDK 版本号
|
||||||
|
* @return 当前 SDK 版本字符串
|
||||||
|
*/
|
||||||
|
getVersion: () => Promise<string>;
|
||||||
/**
|
/**
|
||||||
* 设置支付宝跳转Scheme,仅 iOS
|
* 设置支付宝跳转Scheme,仅 iOS
|
||||||
* @param scheme scheme = `ap` + `APPID`
|
* @param scheme scheme = `ap` + `APPID`
|
||||||
|
27
index.js
27
index.js
@@ -1,23 +1,30 @@
|
|||||||
import { NativeModules, Platform } from 'react-native';
|
import { NativeModules, Platform } from 'react-native';
|
||||||
|
|
||||||
export default class Alipay {
|
export default class Alipay {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付宝端支付
|
* 支付
|
||||||
* @param orderInfo 支付详情
|
* @param orderInfo 支付详情
|
||||||
* @param callback 支付宝回调结果 详情见 https://docs.open.alipay.com/204/105301
|
* @returns result 支付宝回调结果 https://docs.open.alipay.com/204/105301
|
||||||
*/
|
*/
|
||||||
static alipay(orderInfo, callback) {
|
static alipay(orderInfo) {
|
||||||
NativeModules.Alipay.alipay(orderInfo, callback)
|
return NativeModules.Alipay.alipay(orderInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付宝授权请求信息
|
* 快速登录授权
|
||||||
* @param infoStr 授权请求信息字串
|
* @param authInfoStr 验证详情
|
||||||
* @param callback 授权结果回调 详情见 https://opendocs.alipay.com/open/218/105325
|
* @returns result 支付宝回调结果 详情见 https://opendocs.alipay.com/open/218/105325
|
||||||
*/
|
*/
|
||||||
static authInfo(infoStr, callback) {
|
static authInfo(authInfoStr) {
|
||||||
NativeModules.Alipay.authInfo(infoStr, callback)
|
return NativeModules.Alipay.authInfo(authInfoStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前版本号
|
||||||
|
* @return 当前版本字符串
|
||||||
|
*/
|
||||||
|
static getVersion() {
|
||||||
|
return NativeModules.Alipay.getVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
64
ios/Alipay.m
64
ios/Alipay.m
@@ -1,6 +1,12 @@
|
|||||||
#import "Alipay.h"
|
#import "Alipay.h"
|
||||||
#import <AlipaySDK/AlipaySDK.h>
|
#import <AlipaySDK/AlipaySDK.h>
|
||||||
|
|
||||||
|
|
||||||
|
@interface Alipay ()
|
||||||
|
@property (nonatomic, copy) RCTPromiseResolveBlock payOrderResolve;
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation Alipay
|
@implementation Alipay
|
||||||
{
|
{
|
||||||
NSString *alipayScheme;
|
NSString *alipayScheme;
|
||||||
@@ -14,6 +20,10 @@ RCT_EXPORT_MODULE()
|
|||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:@"RCTOpenURLNotification" object:nil];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:@"RCTOpenURLNotification" object:nil];
|
||||||
|
// 反注释下面代码,可以输出支付宝 SDK 调试信息,便于诊断问题
|
||||||
|
// [AlipaySDK startLogWithBlock:^(NSString* log){
|
||||||
|
// NSLog(@"%@", log);
|
||||||
|
// }];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -28,16 +38,27 @@ RCT_EXPORT_MODULE()
|
|||||||
NSString * aURLString = [aNotification userInfo][@"url"];
|
NSString * aURLString = [aNotification userInfo][@"url"];
|
||||||
NSURL * aURL = [NSURL URLWithString:aURLString];
|
NSURL * aURL = [NSURL URLWithString:aURLString];
|
||||||
if ([aURL.host isEqualToString:@"safepay"]) {
|
if ([aURL.host isEqualToString:@"safepay"]) {
|
||||||
// 支付跳转支付宝钱包进行支付,处理支付结果
|
__weak __typeof__(self) weakSelf = self;
|
||||||
|
/**
|
||||||
|
* 处理支付宝app支付后跳回商户app携带的支付结果Url
|
||||||
|
*
|
||||||
|
* @param resultUrl 支付宝app返回的支付结果url
|
||||||
|
* @param completionBlock 支付结果回调 为nil时默认使用支付接口的completionBlock
|
||||||
|
*/
|
||||||
[[AlipaySDK defaultService] processOrderWithPaymentResult:aURL standbyCallback:^(NSDictionary *resultDic) {
|
[[AlipaySDK defaultService] processOrderWithPaymentResult:aURL standbyCallback:^(NSDictionary *resultDic) {
|
||||||
if (self->alipayCallBack != nil) {
|
|
||||||
self->alipayCallBack([[NSArray alloc] initWithObjects:resultDic, nil]);
|
|
||||||
self->alipayCallBack = nil;
|
|
||||||
}
|
|
||||||
NSLog(@"result-->1 = %@", resultDic);
|
NSLog(@"result-->1 = %@", resultDic);
|
||||||
|
if (weakSelf.payOrderResolve) {
|
||||||
|
weakSelf.payOrderResolve(resultDic);
|
||||||
|
weakSelf.payOrderResolve = nil;
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// 授权跳转支付宝钱包进行支付,处理支付结果
|
/**
|
||||||
|
* 处理支付宝app授权后跳回商户app携带的授权结果Url
|
||||||
|
*
|
||||||
|
* @param aURL 支付宝app返回的授权结果url
|
||||||
|
* @param completionBlock 授权结果回调,用于处理跳转支付宝授权过程中商户APP被系统终止的情况
|
||||||
|
*/
|
||||||
[[AlipaySDK defaultService] processAuth_V2Result:aURL standbyCallback:^(NSDictionary *resultDic) {
|
[[AlipaySDK defaultService] processAuth_V2Result:aURL standbyCallback:^(NSDictionary *resultDic) {
|
||||||
NSLog(@"result-->2 = %@", resultDic);
|
NSLog(@"result-->2 = %@", resultDic);
|
||||||
// 解析 auth code
|
// 解析 auth code
|
||||||
@@ -52,9 +73,9 @@ RCT_EXPORT_MODULE()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 返回结果回调
|
// 返回结果回调
|
||||||
if (self->alipayCallBack != nil) {
|
if (weakSelf.payOrderResolve) {
|
||||||
self->alipayCallBack([[NSArray alloc] initWithObjects:resultArr, nil]);
|
weakSelf.payOrderResolve([[NSArray alloc] initWithObjects:resultArr, nil]);
|
||||||
self->alipayCallBack = nil;
|
weakSelf.payOrderResolve = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NSLog(@"授权结果 authCode = %@", authCode?:@"");
|
NSLog(@"授权结果 authCode = %@", authCode?:@"");
|
||||||
@@ -67,24 +88,21 @@ RCT_EXPORT_METHOD(setAlipayScheme:(NSString *)scheme){
|
|||||||
alipayScheme = scheme;
|
alipayScheme = scheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(alipay:(NSString *)info callback:(RCTResponseSenderBlock)callback)
|
RCT_EXPORT_METHOD(alipay:(NSString *)info resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
{
|
self.payOrderResolve = resolve;
|
||||||
alipayCallBack = callback;
|
[AlipaySDK.defaultService payOrder:info fromScheme: alipayScheme callback:^(NSDictionary *resultDic) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
resolve(resultDic);
|
||||||
[[AlipaySDK defaultService] payOrder:info fromScheme: alipayScheme callback:^(NSDictionary *resultDic) {
|
|
||||||
callback([[NSArray alloc] initWithObjects:resultDic, nil]);
|
|
||||||
}];
|
}];
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(authInfo:(NSString *)info callback:(RCTResponseSenderBlock)callback)
|
RCT_EXPORT_METHOD(authInfo:(NSString *)info resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
{
|
[AlipaySDK.defaultService auth_V2WithInfo:info fromScheme: alipayScheme callback:^(NSDictionary *resultDic) {
|
||||||
alipayCallBack = callback;
|
resolve(resultDic);
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
[[AlipaySDK defaultService] auth_V2WithInfo:info fromScheme:alipayScheme callback:^(NSDictionary *resultDic) {
|
|
||||||
callback([[NSArray alloc] initWithObjects:resultDic, nil]);
|
|
||||||
}];
|
}];
|
||||||
});
|
}
|
||||||
|
|
||||||
|
RCT_EXPORT_METHOD(getVersion: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
|
resolve([[AlipaySDK defaultService] currentVersion]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-uiwjs-alipay",
|
"name": "react-native-uiwjs-alipay",
|
||||||
"version": "1.3.1",
|
"version": "1.5.1",
|
||||||
"description": "基于 React Native 的宝支付插件",
|
"description": "基于 React Native 的宝支付插件",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
Reference in New Issue
Block a user