feat(android): 在Android 端实现支付。
This commit is contained in:
parent
98f50d4d5a
commit
24180c67d6
@ -73,6 +73,10 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
//noinspection GradleDynamicVersion
|
//noinspection GradleDynamicVersion
|
||||||
implementation 'com.facebook.react:react-native:+' // From node_modules
|
implementation 'com.facebook.react:react-native:+' // From node_modules
|
||||||
|
|
||||||
|
// 支付宝 SDK AAR 包所需的配置
|
||||||
|
// implementation (name: 'alipaySdk-15.7.7-20200702160044', ext: 'aar')
|
||||||
|
implementation fileTree(dir: "libs", include: ["*.aar"])
|
||||||
}
|
}
|
||||||
|
|
||||||
def configureReactNativePom(def pom) {
|
def configureReactNativePom(def pom) {
|
||||||
|
BIN
android/libs/alipaySdk-15.7.7-20200702160044.aar
Normal file
BIN
android/libs/alipaySdk-15.7.7-20200702160044.aar
Normal file
Binary file not shown.
@ -1,4 +1,7 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.uiwjs">
|
package="com.uiwjs">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
package com.uiwjs;
|
package com.uiwjs;
|
||||||
|
|
||||||
|
import com.alipay.sdk.app.AuthTask;
|
||||||
|
import com.alipay.sdk.app.PayTask;
|
||||||
|
import com.alipay.sdk.app.EnvUtils;
|
||||||
|
import com.facebook.react.bridge.Arguments;
|
||||||
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;
|
||||||
|
import com.facebook.react.bridge.ReadableMap;
|
||||||
|
import com.facebook.react.bridge.WritableMap;
|
||||||
import com.facebook.react.bridge.Callback;
|
import com.facebook.react.bridge.Callback;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class AlipayModule extends ReactContextBaseJavaModule {
|
public class AlipayModule extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
private final ReactApplicationContext reactContext;
|
private final ReactApplicationContext reactContext;
|
||||||
@ -19,9 +27,37 @@ public class AlipayModule extends ReactContextBaseJavaModule {
|
|||||||
return "Alipay";
|
return "Alipay";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ReactMethod
|
||||||
|
// public void sampleMethod(String stringArgument, int numberArgument, Callback callback) {
|
||||||
|
// // TODO: Implement some actually useful functionality
|
||||||
|
// callback.invoke("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument);
|
||||||
|
// }
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void sampleMethod(String stringArgument, int numberArgument, Callback callback) {
|
public void setAlipaySandbox(Boolean isSandbox) {
|
||||||
// TODO: Implement some actually useful functionality
|
if (isSandbox) {
|
||||||
callback.invoke("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument);
|
EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX);
|
||||||
|
} else {
|
||||||
|
EnvUtils.setEnv(EnvUtils.EnvEnum.ONLINE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ReactMethod
|
||||||
|
public void alipay(final String orderInfo, final Callback promise) {
|
||||||
|
Runnable payRunnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
PayTask alipay = new PayTask(getCurrentActivity());
|
||||||
|
Map<String, String> result = alipay.payV2(orderInfo, true);
|
||||||
|
WritableMap map = Arguments.createMap();
|
||||||
|
map.putString("memo", result.get("memo"));
|
||||||
|
map.putString("result", result.get("result"));
|
||||||
|
map.putString("resultStatus", result.get("resultStatus"));
|
||||||
|
promise.invoke(map);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// 必须异步调用
|
||||||
|
Thread payThread = new Thread(payRunnable);
|
||||||
|
payThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user