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
|
||||
===
|
||||
|
||||
[![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)
|
||||
|
||||
![](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 设置
|
||||
|
||||
- ⚠️ Android 端不需要做任何设置。
|
||||
|
@ -71,6 +71,12 @@ public class AlipayModule extends ReactContextBaseJavaModule {
|
||||
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()) {
|
||||
|
@ -3,6 +3,12 @@ import { Button, StyleSheet, Text, View, Linking, AppState } from 'react-native'
|
||||
import Alipay from 'react-native-uiwjs-alipay';
|
||||
|
||||
export default class App extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
version: '',
|
||||
}
|
||||
}
|
||||
componentDidMount() {
|
||||
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
|
||||
console.log('authInfo:resule-->>>', resule);
|
||||
}
|
||||
getVersion = async () => {
|
||||
const version = await Alipay.getVersion();
|
||||
this.setState({ version });
|
||||
console.log('version:', version);
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
@ -34,6 +45,12 @@ export default class App extends Component {
|
||||
color="#841584"
|
||||
accessibilityLabel="Learn more about this purple button"
|
||||
/>
|
||||
<Button
|
||||
onPress={this.getVersion}
|
||||
title="获取 SDK 版本"
|
||||
color="#841584"
|
||||
/>
|
||||
<Text>{this.state.version}</Text>
|
||||
</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
|
||||
*/
|
||||
authInfo: (authInfoStr: string) => Promise<AuthResult>;
|
||||
/**
|
||||
* 获取当前 SDK 版本号
|
||||
* @return 当前 SDK 版本字符串
|
||||
*/
|
||||
getVersion: () => Promise<string>;
|
||||
/**
|
||||
* 设置支付宝跳转Scheme,仅 iOS
|
||||
* @param scheme scheme = `ap` + `APPID`
|
||||
|
23
index.js
23
index.js
@ -1,23 +1,30 @@
|
||||
import { NativeModules, Platform } from 'react-native';
|
||||
|
||||
export default class Alipay {
|
||||
|
||||
/**
|
||||
* 支付宝端支付
|
||||
* 支付
|
||||
* @param orderInfo 支付详情
|
||||
* @param callback 支付宝回调结果 详情见 https://docs.open.alipay.com/204/105301
|
||||
* @returns result 支付宝回调结果 https://docs.open.alipay.com/204/105301
|
||||
*/
|
||||
static alipay(orderInfo) {
|
||||
return NativeModules.Alipay.alipay(orderInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝授权请求信息
|
||||
* @param infoStr 授权请求信息字串
|
||||
* @param callback 授权结果回调 详情见 https://opendocs.alipay.com/open/218/105325
|
||||
* 快速登录授权
|
||||
* @param authInfoStr 验证详情
|
||||
* @returns result 支付宝回调结果 详情见 https://opendocs.alipay.com/open/218/105325
|
||||
*/
|
||||
static authInfo(infoStr) {
|
||||
return NativeModules.Alipay.authInfo(infoStr)
|
||||
static authInfo(authInfoStr) {
|
||||
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];
|
||||
if (self) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:@"RCTOpenURLNotification" object:nil];
|
||||
// 反注释下面代码,可以输出支付宝 SDK 调试信息,便于诊断问题
|
||||
// [AlipaySDK startLogWithBlock:^(NSString* log){
|
||||
// NSLog(@"%@", log);
|
||||
// }];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -80,7 +84,7 @@ RCT_EXPORT_MODULE()
|
||||
return NO;
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(setAlipayScheme:(NSString *)scheme){
|
||||
RCT_EXPORT_METHOD(setAlipayScheme:(NSString *)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`.
|
||||
* 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