diff --git a/README.md b/README.md index 533bce5..4013abd 100644 --- a/README.md +++ b/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;` + +```js +import Alipay from 'react-native-uiwjs-alipay'; + +async function getVersion() { + const version = await Alipay.getVersion(); + console.log('version:', version); +} +``` + ## 支付宝返回应用 iOS 设置 - ⚠️ Android 端不需要做任何设置。 diff --git a/android/src/main/java/com/uiwjs/AlipayModule.java b/android/src/main/java/com/uiwjs/AlipayModule.java index f50b14a..f3c7bfe 100644 --- a/android/src/main/java/com/uiwjs/AlipayModule.java +++ b/android/src/main/java/com/uiwjs/AlipayModule.java @@ -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 map) { WritableMap writableMap = Arguments.createMap(); for (Map.Entry entry : map.entrySet()) { diff --git a/example/App.js b/example/App.js index f830055..60d4de0 100644 --- a/example/App.js +++ b/example/App.js @@ -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 ( @@ -34,6 +45,12 @@ export default class App extends Component { color="#841584" accessibilityLabel="Learn more about this purple button" /> +