feat: 添加获取当前 SDK 版本 API。
This commit is contained in:
parent
fb9a44575d
commit
c16c1be2c0
15
README.md
15
README.md
@ -1,6 +1,8 @@
|
|||||||
react-native-uiwjs-alipay
|
react-native-uiwjs-alipay
|
||||||
===
|
===
|
||||||
|
|
||||||
|
[![NPM Version](https://img.shields.io/npm/v/react-native-uiwjs-alipay.svg)](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)
|
||||||
|
|
||||||
![](https://gw.alipayobjects.com/zos/skylark-tools/public/files/c0aa8379f5f57c55f1e5bf25e6f426d1.png)
|
![](https://gw.alipayobjects.com/zos/skylark-tools/public/files/c0aa8379f5f57c55f1e5bf25e6f426d1.png)
|
||||||
@ -113,6 +115,19 @@ async function authInfo() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `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 端不需要做任何设置。
|
||||||
|
@ -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,6 +3,12 @@ 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');
|
||||||
}
|
}
|
||||||
@ -18,6 +24,11 @@ export default class App extends Component {
|
|||||||
// 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 (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
@ -34,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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
5
index.d.ts
vendored
5
index.d.ts
vendored
@ -126,6 +126,11 @@ export const Alipay: {
|
|||||||
* @returns result 支付宝回调结果 https://opendocs.alipay.com/open/218/105327
|
* @returns result 支付宝回调结果 https://opendocs.alipay.com/open/218/105327
|
||||||
*/
|
*/
|
||||||
authInfo: (authInfoStr: string) => Promise<AuthResult>;
|
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`
|
||||||
|
23
index.js
23
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) {
|
static alipay(orderInfo) {
|
||||||
return NativeModules.Alipay.alipay(orderInfo);
|
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) {
|
static authInfo(authInfoStr) {
|
||||||
return NativeModules.Alipay.authInfo(infoStr)
|
return NativeModules.Alipay.authInfo(authInfoStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前版本号
|
||||||
|
* @return 当前版本字符串
|
||||||
|
*/
|
||||||
|
static getVersion() {
|
||||||
|
return NativeModules.Alipay.getVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
10
ios/Alipay.m
10
ios/Alipay.m
@ -20,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;
|
||||||
}
|
}
|
||||||
@ -80,7 +84,7 @@ RCT_EXPORT_MODULE()
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setAlipayScheme:(NSString *)scheme){
|
RCT_EXPORT_METHOD(setAlipayScheme:(NSString *)scheme) {
|
||||||
alipayScheme = scheme;
|
alipayScheme = scheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +101,10 @@ RCT_EXPORT_METHOD(authInfo:(NSString *)info resolver:(RCTPromiseResolveBlock)res
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RCT_EXPORT_METHOD(getVersion: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
|
resolve([[AlipaySDK defaultService] currentVersion]);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* [warn][tid:main][RCTModuleData.mm:68] Module Alipay requires main queue setup since it overrides `init` but doesn't implement `requiresMainQueueSetup`.
|
* [warn][tid:main][RCTModuleData.mm:68] Module Alipay requires main queue setup since it overrides `init` but doesn't implement `requiresMainQueueSetup`.
|
||||||
* In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of.
|
* In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of.
|
||||||
|
Loading…
Reference in New Issue
Block a user