Compare commits
48 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
004af0975b | ||
![]() |
cf0ca78dc7 | ||
![]() |
175f295f8f | ||
![]() |
ddae4e78c1 | ||
![]() |
c16c1be2c0 | ||
![]() |
fb9a44575d | ||
![]() |
90361afb76 | ||
![]() |
05b4dc3d87 | ||
![]() |
bbc36d501b | ||
![]() |
7c2f89ee0b | ||
![]() |
2c6d149047 | ||
![]() |
b082768cd9 | ||
![]() |
c686194c21 | ||
![]() |
abd48f74db | ||
![]() |
60d6d0a8f1 | ||
![]() |
3620e89bf3 | ||
![]() |
4c89c4e0e6 | ||
![]() |
bd3af94b32 | ||
![]() |
1440075ed4 | ||
![]() |
5ae0ad90ab | ||
![]() |
5de74df3b6 | ||
![]() |
3d35ed67e4 | ||
![]() |
55bfe74932 | ||
![]() |
38e73ca823 | ||
![]() |
0d174dcda0 | ||
![]() |
742e40d922 | ||
![]() |
240965be2a | ||
![]() |
5daea87bf0 | ||
![]() |
f6d21b6b7e | ||
![]() |
0ec59424d8 | ||
![]() |
aba68a6170 | ||
![]() |
1a54d02a47 | ||
![]() |
e47161fa5b | ||
![]() |
1eff1dd94f | ||
![]() |
09d363da5c | ||
![]() |
866f388945 | ||
![]() |
bc61ace241 | ||
![]() |
4329bd6244 | ||
![]() |
cdc5ca58d9 | ||
![]() |
b8b5b3e6e5 | ||
![]() |
08da574fc7 | ||
![]() |
687ea94cb0 | ||
![]() |
96c86045a9 | ||
![]() |
866888a3ed | ||
![]() |
07cc6c69ff | ||
![]() |
8881148994 | ||
![]() |
b6a11caf86 | ||
![]() |
afa8dee9b6 |
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/
|
200
README.md
200
README.md
@@ -1,50 +1,204 @@
|
|||||||
react-native-uiwjs-alipay
|
react-native-uiwjs-alipay
|
||||||
===
|
===
|
||||||
|
|
||||||
基于 React Native 的宝支付插件。
|
[](https://npmjs.org/package/jaywcjlove/react-native-uiwjs-alipay)
|
||||||
|
|
||||||
1. Android:支持2.3及以上的系统版本运行
|
基于 React Native 的宝支付插件。适用于商家在 App 应用中集成支付宝支付功能,商家 APP 调用支付宝提供的 SDK,SDK 再调用支付宝 APP 内的支付模块。如果用户已安装支付宝APP,商家APP会跳转到支付宝中完成支付,支付完后跳回到商家 APP 内,最后展示支付结果。如果用户没有安装支付宝 APP,商家 APP 内会调起支付宝网页支付收银台,用户登录支付宝账户,支付完后展示支付结果。完整实例 [Example](./example)
|
||||||
2. iOS:iOS 6.0以上(包含iOS 6.0)
|
|
||||||
3. 支持手机系统:iOS(苹果)、Android(安卓)
|
|
||||||
|
|
||||||
## Getting started
|

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

|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
1. Android:支持2.3及以上的系统版本运行。
|
||||||
|
2. iOS:iOS 6.0以上(包含iOS 6.0)。
|
||||||
|
3. 支持手机系统:iOS(苹果)、Android(安卓)。
|
||||||
|
4. 调试请注意 支付宝接入应用必须 `已审核通过` 状态。
|
||||||
|
5. 支付宝开放平台-管理中心,签约 `APP支付` 和 `APP支付宝登录` 功能。
|
||||||
|
6. 适用于 `react-native >= 0.60+` 低版本未测试。
|
||||||
|
|
||||||
|
## 安装依赖
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn add react-native-uiwjs-alipay
|
yarn add react-native-uiwjs-alipay
|
||||||
# react-native version >= 0.60+
|
# react-native version >= 0.60+
|
||||||
$ cd ios && pod install
|
$ cd ios && pod install
|
||||||
# or
|
|
||||||
$ react-native link react-native-uiwjs-alipay
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## API
|
||||||
|
|
||||||
|
### `Alipay.alipay` 支付
|
||||||
|
|
||||||
|
> `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-设置)的功能
|
||||||
|
- ⚠️ 支付宝 `管理中心-支付宝开放平台` 需要签约 [`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)
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import Alipay from 'react-native-uiwjs-alipay';
|
import Alipay from 'react-native-uiwjs-alipay';
|
||||||
|
|
||||||
// 设置 支付宝 URL Schemes
|
// 设置 支付宝 URL Schemes,要表述他是宇宙唯一性,可以使用 `bundle Identifier`
|
||||||
// scheme = `ap` + `APPID`
|
// scheme = `alipay` + `APPID`,`APPID` 为支付宝分配给开发者的应用ID
|
||||||
Alipay.setAlipayScheme(scheme);
|
Alipay.setAlipayScheme(scheme);
|
||||||
// 支付宝 iOS 端的支付
|
// ⚠️ 目前不可用,设置支付宝沙箱环境,仅 Android 支持
|
||||||
// payInfo 是后台拼接好的支付参数
|
// Alipay.setAlipaySandbox(isSandbox);
|
||||||
Alipay.alipay(payInfo, (res)=>console.log(res))
|
|
||||||
|
async function aliPay() {
|
||||||
|
// 支付宝端支付
|
||||||
|
// payInfo 是后台拼接好的支付参数
|
||||||
|
// 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) 编码前的数据
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
app_id=xxxxxxxxx&biz_content={"timeout_express":"30m","product_code":"QUICK_MSECURITY_PAY","total_amount":"0.01","subject":"1","body":"我是测试数据","out_trade_no":"IQJZSRC1YMQB5HU"}&charset=utf-8&format=json&method=alipay.trade.app.pay¬ify_url=http://domain.merchant.com/payment_notify&sign_type=RSA2×tamp=2016-08-25 20:26:31&version=1.0&sign=cYmuUnKi5QdBsoZEAbMXVMmRWjsuUj+y48A2DvWAVVBuYkiBj13CFDHu2vZQvmOfkjE0YqCUQE04kqm9Xg3tIX8tPeIGIFtsIyp/M45w1ZsDOiduBbduGfRo1XRsvAyVAv2hCrBLLrDI5Vi7uZZ77Lo5J0PpUUWwyQGt0M4cj8g=
|
alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=xxxxxxxxxxxxx&biz_content={ "out_trade_no":"123123123123123", "total_amount":"0.01", "subject":"1234", "product_code":"QUICK_MSECURITY_PAY" }&charset=UTF-8&format=json&method=alipay.trade.app.pay¬ify_url=http://ane.boshu.ltd/owner/pay/api/ownerPay/callback&return_url=uiwjspay://&sign=re/+2SICQggOUjfxl7MtP/qzir2e+LdH4m+02gDcw0fkByO5MqXW/9bmXw+c4RMqo835OAjMZs7s966ZuDx2PB+hO0tJ/bzdHLLqYlBeCcETkrfwRx+AFZNgzsCn75eRCA7GONH35BpfSeGkQUZ+vNXftqd6hWaa7m/MhQYrjQcV98IVJM+UR67Gj68c+LM586cnk0+rbj8zoos6tCvN8c3xx5UaCobzw4Ogf0PWZ7PZROTU9w2gtoxFfOC5d5slN3laaAXVjAxSf9JCNs8q95fDbzpbmstQOuPgGHkASkd/beH0F8eqTVv8gW1ZTo5v/d/E2wSDGV1DciaEnCroTw==&sign_type=RSA2×tamp=2020-07-09 09:50:41&version=1.0
|
||||||
```
|
```
|
||||||
|
|
||||||
订单详情 `payInfo` 编码的数据
|
订单详情 `payInfo` 编码的数据
|
||||||
|
|
||||||
> 订单参数通过 `encodeURIComponent` 编码 和 `decodeURIComponent` 解码。
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
app_id=xxxxxxxxx&biz_content=%7B%22timeout_express%22%3A%2230m%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%221%22%2C%22body%22%3A%22%E6%88%91%E6%98%AF%E6%B5%8B%E8%AF%95%E6%95%B0%E6%8D%AE%22%2C%22out_trade_no%22%3A%22IQJZSRC1YMQB5HU%22%7D&charset=utf-8&format=json&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2Fdomain.merchant.com%2Fpayment_notify&sign_type=RSA2×tamp=2016-08-25%2020%3A26%3A31&version=1.0&sign=cYmuUnKi5QdBsoZEAbMXVMmRWjsuUj%2By48A2DvWAVVBuYkiBj13CFDHu2vZQvmOfkjE0YqCUQE04kqm9Xg3tIX8tPeIGIFtsIyp%2FM45w1ZsDOiduBbduGfRo1XRsvAyVAv2hCrBLLrDI5Vi7uZZ77Lo5J0PpUUWwyQGt0M4cj8g%3D
|
alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=xxxxxxxxxxxxx&biz_content=%7B+%22out_trade_no%22%3A%22123123123123123%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&return_url=uiwjspay%3A%2F%2F&sign=re%2F%2B2SICQggOUjfxl7MtP%2Fqzir2e%2BLdH4m%2B02gDcw0fkByO5MqXW%2F9bmXw%2Bc4RMqo835OAjMZs7s966ZuDx2PB%2BhO0tJ%2FbzdHLLqYlBeCcETkrfwRx%2BAFZNgzsCn75eRCA7GONH35BpfSeGkQUZ%2BvNXftqd6hWaa7m%2FMhQYrjQcV98IVJM%2BUR67Gj68c%2BLM586cnk0%2Brbj8zoos6tCvN8c3xx5UaCobzw4Ogf0PWZ7PZROTU9w2gtoxFfOC5d5slN3laaAXVjAxSf9JCNs8q95fDbzpbmstQOuPgGHkASkd%2FbeH0F8eqTVv8gW1ZTo5v%2Fd%2FE2wSDGV1DciaEnCroTw%3D%3D&sign_type=RSA2×tamp=2020-07-09+09%3A50%3A41&version=1.0
|
||||||
```
|
```
|
||||||
|
|
||||||
### 其它
|
- ⚠️ 后台 SDK 根据所有数据生成 `sign`,建议通过 API 拿到这个数据,拼接数据会报错。
|
||||||
|
- ⚠️ `out_trade_no` 订单 id 和 `sign` 签名 是唯一的,每次不一样,需要后台生成。
|
||||||
|
|
||||||
|
支付返回结果,支付宝[返回结果参数说明](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/05b4dc3d87ea309b6b6153690faee508cd23e2bf/index.d.ts#L50-L74):
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"result": "{\"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\"}",
|
||||||
|
"resultStatus": "9000",
|
||||||
|
"memo": ""
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### `Alipay.authInfo` 登录授权
|
||||||
|
|
||||||
|
> `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-设置)的功能
|
||||||
|
- ⚠️ 支付宝 `管理中心-支付宝开放平台` 需要签约 [`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)
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import Alipay from 'react-native-uiwjs-alipay';
|
||||||
|
|
||||||
|
// 设置 支付宝 URL Schemes,要表述他是宇宙唯一性,可以使用 `bundle Identifier`
|
||||||
|
// scheme = `alipay` + `APPID`,`APPID` 为支付宝分配给开发者的应用ID
|
||||||
|
Alipay.setAlipayScheme(scheme);
|
||||||
|
|
||||||
|
async function authInfo() {
|
||||||
|
// 支付宝端授权验证
|
||||||
|
// authInfoStr 是后台拼接好的验证参数
|
||||||
|
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 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/05b4dc3d87ea309b6b6153690faee508cd23e2bf/index.d.ts#L89-L113):
|
||||||
|
|
||||||
|
```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"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### `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 设置
|
||||||
|
|
||||||
|
- ⚠️ Android 端不需要做任何设置。
|
||||||
|
- ⚠️ 如果用户从 `支付宝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/05b4dc3d87ea309b6b6153690faee508cd23e2bf/example/App.js#L7),下面实例 [`uiwjspay`](https://github.com/uiwjs/react-native-uiwjs-alipay/commit/f6d21b6b7ec7236b195c56281f971092f3c9bb08) 是定义的 `scheme`,你也可以定义为 `alipay` + `appid`,`appid` 为支付宝分配给开发者的应用ID,用来表述 `scheme` 唯一性。
|
||||||
|
|
||||||
|
```js
|
||||||
|
Alipay.setAlipayScheme('uiwjspay');
|
||||||
|
```
|
||||||
|
|
||||||
|
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
|
||||||
|
// payInfo 是后台拼接好的支付参数,这个参数必须包含 `return_url=uiwjspay://`
|
||||||
|
Alipay.alipay(payInfo, (res)=>console.log(res))
|
||||||
|
```
|
||||||
|
|
||||||
|
3. 用的 `URL Schemes` 列为白名单,在 [`ios/<应用名称>/Info.plist`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/05b4dc3d87ea309b6b6153690faee508cd23e2bf/example/ios/example/Info.plist#L23-L41) 中添加
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<key>LSApplicationQueriesSchemes</key>
|
||||||
|
<array>
|
||||||
|
<string>alipay</string>
|
||||||
|
</array>
|
||||||
|
<key>CFBundleURLTypes</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeRole</key>
|
||||||
|
<string>Editor</string>
|
||||||
|
<key>CFBundleURLName</key>
|
||||||
|
<string></string>
|
||||||
|
<key>CFBundleURLSchemes</key>
|
||||||
|
<array>
|
||||||
|
<string>uiwjspay</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
```
|
||||||
|
|
||||||
|
4. 修改 [`ios/<应用名称>/AppDelegate.m`](https://github.com/uiwjs/react-native-uiwjs-alipay/blob/05b4dc3d87ea309b6b6153690faee508cd23e2bf/example/ios/example/AppDelegate.m#L60-L70) 添加下列代码:
|
||||||
|
|
||||||
|
```objective-c
|
||||||
|
#import <React/RCTLinkingManager.h>
|
||||||
|
|
||||||
|
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
|
||||||
|
{
|
||||||
|
return [RCTLinkingManager application:application openURL:url
|
||||||
|
sourceApplication:sourceApplication annotation:annotation];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
|
||||||
|
{
|
||||||
|
return [RCTLinkingManager application:application openURL:url options:options];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**命令测试**
|
||||||
|
|
||||||
|
- iOS: `xcrun simctl openurl booted uiwjspay://`
|
||||||
|
- Android:`adb shell am start -W -a android.intent.action.VIEW -d "uiwjspay://test/router" com.uiwjspay`
|
||||||
|
|
||||||
|
## 错误处理
|
||||||
|
|
||||||
|
```bash
|
||||||
|
[NetworkInfo] Signal strength query returned error: Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied", descriptor: <CTServiceDescriptor 0x283317100, domain=1, instance=1>
|
||||||
|
```
|
||||||
|
|
||||||
|
在 `Product` -> `Scheme` -> `Edit Scheme` -> `Run` -> `Arguments` -> `Environment Variables` 添加 `OS_ACTIVITY_MODE` `disable`
|
||||||
|
|
||||||
|
## 其它
|
||||||
|
|
||||||
当前工程基于 [@brodybits/create-react-native-module](https://github.com/brodybits/create-react-native-module) 初始化。
|
当前工程基于 [@brodybits/create-react-native-module](https://github.com/brodybits/create-react-native-module) 初始化。
|
||||||
|
|
||||||
@@ -52,8 +206,12 @@ app_id=xxxxxxxxx&biz_content=%7B%22timeout_express%22%3A%2230m%22%2C%22product_c
|
|||||||
npx create-react-native-module --package-identifier com.uiwjs --generate-example Alipay --example-react-native-version 0.62.2 --module-name react-native-uiwjs-alipay --github-account uiwjs --author-name "Kenny Wong" --author-email "wowohoo@qq.com"
|
npx create-react-native-module --package-identifier com.uiwjs --generate-example Alipay --example-react-native-version 0.62.2 --module-name react-native-uiwjs-alipay --github-account uiwjs --author-name "Kenny Wong" --author-email "wowohoo@qq.com"
|
||||||
```
|
```
|
||||||
|
|
||||||
### 相关连接
|
## 相关连接
|
||||||
|
|
||||||
|
- [支付宝:生成秘钥指南](https://opendocs.alipay.com/open/291/105971)
|
||||||
|
- [支付宝:SDK 下载地址,当前使用的是 AlipaySDK 15.7.7](https://opendocs.alipay.com/open/54/104509)
|
||||||
|
- [支付宝:客户端调试工具及使用教程](https://openclub.alipay.com/club/history/read/7695)
|
||||||
|
- [支付宝:支付,接入前准备](https://opendocs.alipay.com/open/204/105297/)
|
||||||
|
- [支付宝:完整版授权 SDK 调用方法](https://opendocs.alipay.com/open/218/105325)
|
||||||
|
- [支付宝:异步通知错误码: IllRet](https://opensupport.alipay.com/support/problem.htm?ant_source=antsupport)
|
||||||
- [React-native 0.6版本集成支付宝-Alipay爬坑](https://segmentfault.com/a/1190000020758279)
|
- [React-native 0.6版本集成支付宝-Alipay爬坑](https://segmentfault.com/a/1190000020758279)
|
||||||
- [支付宝生成秘钥指南](https://opendocs.alipay.com/open/291/105971)
|
|
||||||
- [支付宝 SDK 下载地址](https://opendocs.alipay.com/open/54/104509)
|
|
@@ -4,6 +4,7 @@ import com.alipay.sdk.app.AuthTask;
|
|||||||
import com.alipay.sdk.app.PayTask;
|
import com.alipay.sdk.app.PayTask;
|
||||||
import com.alipay.sdk.app.EnvUtils;
|
import com.alipay.sdk.app.EnvUtils;
|
||||||
import com.facebook.react.bridge.Arguments;
|
import com.facebook.react.bridge.Arguments;
|
||||||
|
import com.facebook.react.bridge.Promise;
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
import com.facebook.react.bridge.ReactMethod;
|
import com.facebook.react.bridge.ReactMethod;
|
||||||
@@ -33,6 +34,20 @@ public class AlipayModule extends ReactContextBaseJavaModule {
|
|||||||
// callback.invoke("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument);
|
// callback.invoke("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void authInfo(final String infoStr, final Promise promise) {
|
||||||
|
Runnable runnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
AuthTask authTask = new AuthTask(getCurrentActivity());
|
||||||
|
Map<String, String> map = authTask.authV2(infoStr, true);
|
||||||
|
promise.resolve(getWritableMap(map));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Thread thread = new Thread(runnable);
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void setAlipaySandbox(Boolean isSandbox) {
|
public void setAlipaySandbox(Boolean isSandbox) {
|
||||||
if (isSandbox) {
|
if (isSandbox) {
|
||||||
@@ -42,17 +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);
|
||||||
WritableMap map = Arguments.createMap();
|
promise.resolve(getWritableMap(result));
|
||||||
map.putString("memo", result.get("memo"));
|
|
||||||
map.putString("result", result.get("result"));
|
|
||||||
map.putString("resultStatus", result.get("resultStatus"));
|
|
||||||
promise.invoke(map);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// 必须异步调用
|
// 必须异步调用
|
||||||
@@ -60,4 +71,17 @@ 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) {
|
||||||
|
WritableMap writableMap = Arguments.createMap();
|
||||||
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
|
writableMap.putString(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
return writableMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
3
android/src/main/res/values/strings.xml
Normal file
3
android/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">uiwjs</string>
|
||||||
|
</resources>
|
@@ -1,16 +1,33 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Button, StyleSheet, Text, View } from 'react-native';
|
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 {
|
||||||
componentDidMount() {
|
constructor(props) {
|
||||||
Alipay.setAlipayScheme('ap2021001172656340');
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
version: '',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
aliPay = () => {
|
componentDidMount() {
|
||||||
const payInfo = 'app_id=2021001172656340&biz_content=%7B%22timeout_express%22%3A%2230m%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%221%22%2C%22body%22%3A%22%E6%88%91%E6%98%AF%E6%B5%8B%E8%AF%95%E6%95%B0%E6%8D%AE%22%2C%22out_trade_no%22%3A%22IQJZSRC1YMQB5HU%22%7D&charset=utf-8&format=json&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2Fdomain.merchant.com%2Fpayment_notify&sign_type=RSA2×tamp=2016-08-25%2020%3A26%3A31&version=1.0&sign=cYmuUnKi5QdBsoZEAbMXVMmRWjsuUj%2By48A2DvWAVVBuYkiBj13CFDHu2vZQvmOfkjE0YqCUQE04kqm9Xg3tIX8tPeIGIFtsIyp%2FM45w1ZsDOiduBbduGfRo1XRsvAyVAv2hCrBLLrDI5Vi7uZZ77Lo5J0PpUUWwyQGt0M4cj8g%3D';
|
Alipay.setAlipayScheme('uiwjspay');
|
||||||
Alipay.alipay(payInfo, (resule) => {
|
}
|
||||||
console.log(resule)
|
aliPay = async () => {
|
||||||
});
|
// 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);
|
||||||
|
}
|
||||||
|
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 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);
|
||||||
|
}
|
||||||
|
getVersion = async () => {
|
||||||
|
const version = await Alipay.getVersion();
|
||||||
|
this.setState({ version });
|
||||||
|
console.log('version:', version);
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@@ -22,6 +39,18 @@ 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.authInfo}
|
||||||
|
title="登录验证"
|
||||||
|
color="#841584"
|
||||||
|
accessibilityLabel="Learn more about this purple button"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
onPress={this.getVersion}
|
||||||
|
title="获取 SDK 版本"
|
||||||
|
color="#841584"
|
||||||
|
/>
|
||||||
|
<Text>{this.state.version}</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,3 @@
|
|||||||
rootProject.name = 'example'
|
rootProject.name = 'example'
|
||||||
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
|
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
|
||||||
include ':app'
|
include ':app'
|
||||||
|
|
||||||
// 看上去可以自动的样子
|
|
||||||
// include ':react-native-uiwjs-alipay'
|
|
||||||
// project(':react-native-uiwjs-alipay').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-uiwjs-alipay/android')
|
|
||||||
|
@@ -681,7 +681,7 @@
|
|||||||
"-ObjC",
|
"-ObjC",
|
||||||
"-lc++",
|
"-lc++",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
|
PRODUCT_BUNDLE_IDENTIFIER = com.uiwjs;
|
||||||
PRODUCT_NAME = example;
|
PRODUCT_NAME = example;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
@@ -704,7 +704,7 @@
|
|||||||
"-ObjC",
|
"-ObjC",
|
||||||
"-lc++",
|
"-lc++",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
|
PRODUCT_BUNDLE_IDENTIFIER = com.uiwjs;
|
||||||
PRODUCT_NAME = example;
|
PRODUCT_NAME = example;
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
VERSIONING_SYSTEM = "apple-generic";
|
||||||
|
@@ -60,6 +60,13 @@
|
|||||||
ReferencedContainer = "container:example.xcodeproj">
|
ReferencedContainer = "container:example.xcodeproj">
|
||||||
</BuildableReference>
|
</BuildableReference>
|
||||||
</BuildableProductRunnable>
|
</BuildableProductRunnable>
|
||||||
|
<EnvironmentVariables>
|
||||||
|
<EnvironmentVariable
|
||||||
|
key = "OS_ACTIVITY_MODE"
|
||||||
|
value = "disable"
|
||||||
|
isEnabled = "YES">
|
||||||
|
</EnvironmentVariable>
|
||||||
|
</EnvironmentVariables>
|
||||||
</LaunchAction>
|
</LaunchAction>
|
||||||
<ProfileAction
|
<ProfileAction
|
||||||
buildConfiguration = "Release"
|
buildConfiguration = "Release"
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
#import <React/RCTBridge.h>
|
#import <React/RCTBridge.h>
|
||||||
#import <React/RCTBundleURLProvider.h>
|
#import <React/RCTBundleURLProvider.h>
|
||||||
#import <React/RCTRootView.h>
|
#import <React/RCTRootView.h>
|
||||||
|
#import <React/RCTLinkingManager.h>
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#import <FlipperKit/FlipperClient.h>
|
#import <FlipperKit/FlipperClient.h>
|
||||||
@@ -55,4 +56,16 @@ static void InitializeFlipper(UIApplication *application) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
|
||||||
|
{
|
||||||
|
return [RCTLinkingManager application:application openURL:url
|
||||||
|
sourceApplication:sourceApplication annotation:annotation];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
|
||||||
|
{
|
||||||
|
return [RCTLinkingManager application:application openURL:url options:options];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@@ -26,17 +26,21 @@
|
|||||||
<key>CFBundleTypeRole</key>
|
<key>CFBundleTypeRole</key>
|
||||||
<string>Editor</string>
|
<string>Editor</string>
|
||||||
<key>CFBundleURLName</key>
|
<key>CFBundleURLName</key>
|
||||||
<string>I</string>
|
<string></string>
|
||||||
|
<key>CFBundleURLSchemes</key>
|
||||||
|
<array>
|
||||||
|
<string>uiwjspay</string>
|
||||||
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1</string>
|
<string>1</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
|
||||||
<true/>
|
|
||||||
<key>LSApplicationQueriesSchemes</key>
|
<key>LSApplicationQueriesSchemes</key>
|
||||||
<array>
|
<array>
|
||||||
<string>alipay</string>
|
<string>alipay</string>
|
||||||
</array>
|
</array>
|
||||||
|
<key>LSRequiresIPhoneOS</key>
|
||||||
|
<true/>
|
||||||
<key>NSAppTransportSecurity</key>
|
<key>NSAppTransportSecurity</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSAllowsArbitraryLoads</key>
|
<key>NSAllowsArbitraryLoads</key>
|
||||||
|
139
index.d.ts
vendored
139
index.d.ts
vendored
@@ -4,56 +4,143 @@
|
|||||||
* 支付宝回调结果, 详情见 https://docs.open.alipay.com/204/105301
|
* 支付宝回调结果, 详情见 https://docs.open.alipay.com/204/105301
|
||||||
*/
|
*/
|
||||||
export interface AliOrderResult {
|
export interface AliOrderResult {
|
||||||
|
alipay_trade_app_pay_response: {
|
||||||
|
/**
|
||||||
|
* 长度:64,商户网站唯一订单号 70501111111S001111119
|
||||||
|
*/
|
||||||
|
out_trade_no: string;
|
||||||
|
/**
|
||||||
|
* 长度:64,该交易在支付宝系统中的交易流水号。最长64位。 2014112400001000340011111118
|
||||||
|
*/
|
||||||
|
trade_no: string;
|
||||||
|
/**
|
||||||
|
* 长度:32,支付宝分配给开发者的应用Id。 2014072300007148
|
||||||
|
*/
|
||||||
|
app_id: string;
|
||||||
|
/**
|
||||||
|
* 长度:9 ,该笔订单的资金总额,单位为RMB-Yuan。取值范围为[0.01,100000000.00],精确到小数点后两位。 9.00
|
||||||
|
*/
|
||||||
|
total_amount: number;
|
||||||
|
/**
|
||||||
|
* 长度:16,收款支付宝账号对应的支付宝唯一用户号。以2088开头的纯16位数字 20886894
|
||||||
|
*/
|
||||||
|
seller_id: string;
|
||||||
|
/**
|
||||||
|
* 长度:16,处理结果的描述,信息来自于code返回结果的描述 success
|
||||||
|
*/
|
||||||
|
msg: string;
|
||||||
|
/**
|
||||||
|
* 长度:16,编码格式 utf-8
|
||||||
|
*/
|
||||||
|
charset: string;
|
||||||
|
/**
|
||||||
|
* 长度:32,时间 2016-10-11 17:43:36
|
||||||
|
*/
|
||||||
|
timestamp: string;
|
||||||
|
/**
|
||||||
|
* 长度:16,结果码 具体见公共错误码
|
||||||
|
*/
|
||||||
|
code: string;
|
||||||
|
},
|
||||||
|
sign: string;
|
||||||
|
sign_type: 'RSA2' | 'RSA';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface OrderResult {
|
||||||
/**
|
/**
|
||||||
* 长度:64,商户网站唯一订单号 70501111111S001111119
|
* @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"}'
|
||||||
*/
|
*/
|
||||||
out_trade_no: string;
|
result?: string;
|
||||||
/**
|
/**
|
||||||
* 长度:64,该交易在支付宝系统中的交易流水号。最长64位。 2014112400001000340011111118
|
* 9000 订单支付成功
|
||||||
|
* 8000 正在处理中,支付结果未知(有可能已经支付成功),请查询商户订单列表中订单的支付状态
|
||||||
|
* 4000 订单支付失败
|
||||||
|
* 5000 重复请求
|
||||||
|
* 6001 用户中途取消
|
||||||
|
* 6002 网络连接出错
|
||||||
|
* 6004 支付结果未知(有可能已经支付成功),请查询商户订单列表中订单的支付状态
|
||||||
|
* 其它 其它支付错误
|
||||||
*/
|
*/
|
||||||
trade_no: string;
|
resultStatus?: '9000' | '8000' | '4000' | '5000' | '6001' | '6002' | '6004' | string;
|
||||||
/**
|
/**
|
||||||
* 长度:32,支付宝分配给开发者的应用Id。 2014072300007148
|
* "Error Domain=系统繁忙,请稍后再试 Code=1000 "(null)""
|
||||||
|
* 优惠券备注信息
|
||||||
*/
|
*/
|
||||||
app_id: string;
|
memo: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 错误返回
|
||||||
|
// {
|
||||||
|
// memo: "Error Domain=系统繁忙,请稍后再试 Code=1000 \"(null)\"",
|
||||||
|
// result: "",
|
||||||
|
// resultStatus: "4000",
|
||||||
|
// }
|
||||||
|
// 成功返回
|
||||||
|
// {
|
||||||
|
// result: '{"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"}',
|
||||||
|
// resultStatus: '9000',
|
||||||
|
// 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 {
|
||||||
/**
|
/**
|
||||||
* 长度:9 ,该笔订单的资金总额,单位为RMB-Yuan。取值范围为[0.01,100000000.00],精确到小数点后两位。 9.00
|
* 长度: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`
|
||||||
*/
|
*/
|
||||||
total_amount: number;
|
result: string;
|
||||||
/**
|
/**
|
||||||
* 长度:16,收款支付宝账号对应的支付宝唯一用户号。以2088开头的纯16位数字 20886894
|
* 长度:5,本次操作的状态返回值,标识本次调用的结果,参见“resultStatus状态代码”。
|
||||||
|
* - 9000 请求处理成功
|
||||||
|
* - 4000 系统异常
|
||||||
|
* - 6001 用户中途取消
|
||||||
|
* - 6002 网络连接出错
|
||||||
*/
|
*/
|
||||||
seller_id: string;
|
resultStatus: '9000' | '4000' | '6001' | '6002';
|
||||||
/**
|
/**
|
||||||
* 长度:16,处理结果的描述,信息来自于code返回结果的描述 success
|
* 长度:无,保留参数,一般无内容。 处理成功
|
||||||
*/
|
*/
|
||||||
msg: string;
|
memo: string;
|
||||||
/**
|
|
||||||
* 长度:16,编码格式 utf-8
|
|
||||||
*/
|
|
||||||
charset: string;
|
|
||||||
/**
|
|
||||||
* 长度:32,时间 2016-10-11 17:43:36
|
|
||||||
*/
|
|
||||||
timestamp: string;
|
|
||||||
/**
|
|
||||||
* 长度:16,结果码 具体见公共错误码
|
|
||||||
*/
|
|
||||||
code: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const Alipay: {
|
export const Alipay: {
|
||||||
/**
|
/**
|
||||||
|
* 支付
|
||||||
* @param payInfo 支付详情
|
* @param payInfo 支付详情
|
||||||
* @param result 支付宝回调结果
|
* @returns result 支付宝回调结果 https://docs.open.alipay.com/204/105301
|
||||||
*/
|
*/
|
||||||
alipay: (payInfo: string, callback?: (result: AliOrderResult) => void) => void;
|
alipay: (payInfo: string) => Promise<OrderResult>;
|
||||||
|
/**
|
||||||
|
* 快速登录授权
|
||||||
|
* @param authInfoStr 验证详情
|
||||||
|
* @returns result 支付宝回调结果 https://opendocs.alipay.com/open/218/105327
|
||||||
|
*/
|
||||||
|
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`
|
||||||
*/
|
*/
|
||||||
setAlipayScheme: (scheme: string) => void;
|
setAlipayScheme: (scheme: string) => void;
|
||||||
|
/**
|
||||||
|
* 设置支付宝沙箱环境,仅 Android
|
||||||
|
* @param isSandBox
|
||||||
|
*/
|
||||||
|
setAlipaySandbox: (isSandbox: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Alipay;
|
export default Alipay;
|
36
index.js
36
index.js
@@ -1,14 +1,30 @@
|
|||||||
import { NativeModules, Platform } from 'react-native';
|
import { NativeModules, Platform } from 'react-native';
|
||||||
|
|
||||||
export default class Alipay {
|
export default class Alipay {
|
||||||
|
/**
|
||||||
|
* 支付
|
||||||
|
* @param orderInfo 支付详情
|
||||||
|
* @returns result 支付宝回调结果 https://docs.open.alipay.com/204/105301
|
||||||
|
*/
|
||||||
|
static alipay(orderInfo) {
|
||||||
|
return NativeModules.Alipay.alipay(orderInfo);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付宝端支付
|
* 快速登录授权
|
||||||
* @param orderInfo 支付详情
|
* @param authInfoStr 验证详情
|
||||||
* @param callback 支付宝回调结果 详情见 https://docs.open.alipay.com/204/105301
|
* @returns result 支付宝回调结果 详情见 https://opendocs.alipay.com/open/218/105325
|
||||||
*/
|
*/
|
||||||
static alipay(orderInfo, callback) {
|
static authInfo(authInfoStr) {
|
||||||
NativeModules.Alipay.alipay(orderInfo, callback)
|
return NativeModules.Alipay.authInfo(authInfoStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前版本号
|
||||||
|
* @return 当前版本字符串
|
||||||
|
*/
|
||||||
|
static getVersion() {
|
||||||
|
return NativeModules.Alipay.getVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,4 +36,14 @@ export default class Alipay {
|
|||||||
NativeModules.Alipay.setAlipayScheme(scheme);
|
NativeModules.Alipay.setAlipayScheme(scheme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置支付宝沙箱环境,仅 Android
|
||||||
|
* @param isSandBox
|
||||||
|
*/
|
||||||
|
static setAlipaySandbox(isSandBox) {
|
||||||
|
if (Platform.OS === 'android') {
|
||||||
|
NativeModules.Alipay.setAlipaySandbox(isSandBox);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
69
ios/Alipay.m
69
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,18 +38,29 @@ 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) {
|
NSLog(@"result-->1 = %@", resultDic);
|
||||||
self->alipayCallBack([[NSArray alloc] initWithObjects:resultDic, nil]);
|
if (weakSelf.payOrderResolve) {
|
||||||
self->alipayCallBack = nil;
|
weakSelf.payOrderResolve(resultDic);
|
||||||
|
weakSelf.payOrderResolve = nil;
|
||||||
}
|
}
|
||||||
NSLog(@"result = %@",resultDic);
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// 授权跳转支付宝钱包进行支付,处理支付结果
|
/**
|
||||||
|
* 处理支付宝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 = %@",resultDic);
|
NSLog(@"result-->2 = %@", resultDic);
|
||||||
// 解析 auth code
|
// 解析 auth code
|
||||||
NSString *result = resultDic[@"result"];
|
NSString *result = resultDic[@"result"];
|
||||||
NSString *authCode = nil;
|
NSString *authCode = nil;
|
||||||
@@ -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?:@"");
|
||||||
@@ -63,19 +84,25 @@ RCT_EXPORT_MODULE()
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setAlipayScheme:(NSString *)scheme){
|
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) {
|
||||||
alipayCallBack = callback;
|
self.payOrderResolve = resolve;
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
[AlipaySDK.defaultService payOrder:info fromScheme: alipayScheme callback:^(NSDictionary *resultDic) {
|
||||||
[[AlipaySDK defaultService] payOrder:info fromScheme:alipayScheme callback:^(NSDictionary *resultDic) {
|
resolve(resultDic);
|
||||||
NSLog(@"alipay:callback");
|
}];
|
||||||
|
}
|
||||||
callback([[NSArray alloc] initWithObjects:resultDic, nil]);
|
|
||||||
}];
|
RCT_EXPORT_METHOD(authInfo:(NSString *)info resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
});
|
[AlipaySDK.defaultService auth_V2WithInfo:info fromScheme: alipayScheme callback:^(NSDictionary *resultDic) {
|
||||||
|
resolve(resultDic);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
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.0.0",
|
"version": "1.5.1",
|
||||||
"description": "基于 React Native 的宝支付插件",
|
"description": "基于 React Native 的宝支付插件",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
5
renovate.json
Normal file
5
renovate.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"config:base"
|
||||||
|
]
|
||||||
|
}
|
Reference in New Issue
Block a user