@gyjshow/react-native-alipay 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/android/build.gradle +14 -27
- package/android/src/main/java/com/gyj/alipay/RNAlipayModule.kt +55 -0
- package/android/src/main/java/com/gyj/alipay/RNAlipayPackage.kt +22 -0
- package/lib/index.js +4 -4
- package/package.json +40 -40
- package/react-native-alipay.podspec +3 -2
- package/android/src/main/java/com/gyj/alipay/RNAlipayModule.java +0 -67
- package/android/src/main/java/com/gyj/alipay/RNAlipayPackage.java +0 -24
package/README.md
ADDED
|
File without changes
|
package/android/build.gradle
CHANGED
|
@@ -1,46 +1,33 @@
|
|
|
1
1
|
buildscript {
|
|
2
|
+
def kotlinVersion = rootProject.ext.has('kotlinVersion')
|
|
3
|
+
? rootProject.ext.get('kotlinVersion')
|
|
4
|
+
: '2.1.20'
|
|
5
|
+
|
|
2
6
|
repositories {
|
|
3
7
|
google()
|
|
4
8
|
mavenCentral()
|
|
5
9
|
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
|
|
13
|
+
}
|
|
6
14
|
}
|
|
7
15
|
|
|
8
16
|
apply plugin: 'com.android.library'
|
|
17
|
+
apply plugin: 'kotlin-android'
|
|
9
18
|
|
|
10
19
|
android {
|
|
11
|
-
namespace "com.gyj.
|
|
12
|
-
|
|
13
|
-
compileSdkVersion 34
|
|
20
|
+
namespace "com.gyj.alipay"
|
|
21
|
+
compileSdkVersion rootProject.ext.compileSdkVersion
|
|
14
22
|
|
|
15
23
|
defaultConfig {
|
|
16
|
-
minSdkVersion
|
|
17
|
-
targetSdkVersion
|
|
18
|
-
versionCode 1
|
|
19
|
-
versionName "1.0"
|
|
20
|
-
consumerProguardFiles "consumer-rules.pro"
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
buildTypes {
|
|
24
|
-
release {
|
|
25
|
-
minifyEnabled false
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
compileOptions {
|
|
30
|
-
sourceCompatibility JavaVersion.VERSION_17
|
|
31
|
-
targetCompatibility JavaVersion.VERSION_17
|
|
24
|
+
minSdkVersion rootProject.ext.minSdkVersion
|
|
25
|
+
targetSdkVersion rootProject.ext.targetSdkVersion
|
|
32
26
|
}
|
|
33
27
|
}
|
|
34
28
|
|
|
35
|
-
repositories {
|
|
36
|
-
google()
|
|
37
|
-
mavenCentral()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
29
|
dependencies {
|
|
41
|
-
// React Native
|
|
42
30
|
implementation "com.facebook.react:react-android"
|
|
43
|
-
|
|
44
|
-
// 支付宝 Android SDK(自动下载)
|
|
31
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
|
45
32
|
api "com.alipay.sdk:alipaysdk-android:+@aar"
|
|
46
33
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package com.gyj.alipay
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.os.Handler
|
|
5
|
+
import android.os.Looper
|
|
6
|
+
import com.alipay.sdk.app.PayTask
|
|
7
|
+
import com.facebook.react.bridge.*
|
|
8
|
+
|
|
9
|
+
// # Kotlin 模块实现
|
|
10
|
+
class RNAlipayModule(
|
|
11
|
+
private val reactContext: ReactApplicationContext
|
|
12
|
+
) : ReactContextBaseJavaModule(reactContext) {
|
|
13
|
+
|
|
14
|
+
override fun getName(): String = "RNAlipay"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 发起支付
|
|
18
|
+
*/
|
|
19
|
+
@ReactMethod
|
|
20
|
+
fun pay(orderInfo: String, promise: Promise) {
|
|
21
|
+
val activity: Activity? = currentActivity
|
|
22
|
+
if (activity == null) {
|
|
23
|
+
promise.reject("NO_ACTIVITY", "Current activity is null")
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
Thread {
|
|
28
|
+
try {
|
|
29
|
+
val alipay = PayTask(activity)
|
|
30
|
+
val result: Map<String, String> = alipay.payV2(orderInfo, true)
|
|
31
|
+
|
|
32
|
+
Handler(Looper.getMainLooper()).post {
|
|
33
|
+
promise.resolve(Arguments.makeNativeMap(result))
|
|
34
|
+
}
|
|
35
|
+
} catch (e: Exception) {
|
|
36
|
+
promise.reject("ALIPAY_ERROR", e)
|
|
37
|
+
}
|
|
38
|
+
}.start()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 获取 SDK 版本
|
|
43
|
+
*/
|
|
44
|
+
@ReactMethod
|
|
45
|
+
fun getVersion(promise: Promise) {
|
|
46
|
+
val activity: Activity? = currentActivity
|
|
47
|
+
if (activity == null) {
|
|
48
|
+
promise.reject("NO_ACTIVITY", "Current activity is null")
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
val alipay = PayTask(activity)
|
|
53
|
+
promise.resolve(alipay.version)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package com.gyj.alipay
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
// # Kotlin 包实现
|
|
9
|
+
class RNAlipayPackage : ReactPackage {
|
|
10
|
+
|
|
11
|
+
override fun createNativeModules(
|
|
12
|
+
reactContext: ReactApplicationContext
|
|
13
|
+
): List<NativeModule> {
|
|
14
|
+
return listOf(RNAlipayModule(reactContext))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
override fun createViewManagers(
|
|
18
|
+
reactContext: ReactApplicationContext
|
|
19
|
+
): List<ViewManager<*, *>> {
|
|
20
|
+
return emptyList()
|
|
21
|
+
}
|
|
22
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { NativeModules } from 'react-native';
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
2
|
const { RNAlipay } = NativeModules;
|
|
3
3
|
const Alipay = {
|
|
4
4
|
//这是scheme
|
|
5
5
|
setAlipayScheme: (scheme) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
if (Platform.OS === 'ios') {
|
|
7
|
+
RNAlipay.setAlipayScheme(scheme);
|
|
8
|
+
}
|
|
9
9
|
},
|
|
10
10
|
//发起支付
|
|
11
11
|
alipay: (payInfo) => {
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@gyjshow/react-native-alipay",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "基于 React Native 的支付宝插件,支持 Android / iOS。",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib",
|
|
10
|
+
"ios",
|
|
11
|
+
"android",
|
|
12
|
+
"*.podspec"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/gyjshow/react-native-alipay.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"react",
|
|
24
|
+
"native",
|
|
25
|
+
"alipay",
|
|
26
|
+
"react-native-alipay"
|
|
27
|
+
],
|
|
28
|
+
"author": "Allen.ge",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"homepage": "https://github.com/gyjshow/react-native-alipay.git",
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": "*",
|
|
33
|
+
"react-native": ">=0.60.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/react": "^19.2.13",
|
|
37
|
+
"react-native": "^0.83.1",
|
|
38
|
+
"typescript": "^5.9.3"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -11,11 +11,12 @@ Pod::Spec.new do |s|
|
|
|
11
11
|
s.authors = package['author']
|
|
12
12
|
s.homepage = package['homepage']
|
|
13
13
|
s.platform = :ios, "9.0"
|
|
14
|
+
|
|
15
|
+
s.source = { :http => 'file://' + __dir__ }
|
|
14
16
|
|
|
15
|
-
s.source = { :git => "https://github.com/react-native-hero/alipay.git", :tag => "v#{s.version}" }
|
|
16
17
|
s.source_files = "ios/**/*.{h,m}"
|
|
17
18
|
|
|
18
|
-
s.dependency 'React'
|
|
19
|
+
s.dependency 'React-Core'
|
|
19
20
|
s.dependency 'AlipaySDK-iOS'
|
|
20
21
|
|
|
21
22
|
end
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
package com.gyj.reactnativealipay;
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
5
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
6
|
-
import com.facebook.react.bridge.Promise;
|
|
7
|
-
|
|
8
|
-
import android.app.Activity;
|
|
9
|
-
import android.content.Intent;
|
|
10
|
-
import android.net.Uri;
|
|
11
|
-
|
|
12
|
-
import com.alipay.sdk.app.PayTask;
|
|
13
|
-
|
|
14
|
-
import java.util.Map;
|
|
15
|
-
import java.util.HashMap;
|
|
16
|
-
|
|
17
|
-
public class RNAlipayModule extends ReactContextBaseJavaModule {
|
|
18
|
-
private ReactApplicationContext reactContext;
|
|
19
|
-
private String scheme = "";
|
|
20
|
-
|
|
21
|
-
public RNAlipayModule(ReactApplicationContext reactContext) {
|
|
22
|
-
super(reactContext);
|
|
23
|
-
this.reactContext = reactContext;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@Override
|
|
27
|
-
public String getName() {
|
|
28
|
-
return "RNAlipay";
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 设置 scheme
|
|
32
|
-
@ReactMethod
|
|
33
|
-
public void setAlipayScheme(String scheme) {
|
|
34
|
-
this.scheme = scheme;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 发起支付
|
|
38
|
-
@ReactMethod
|
|
39
|
-
public void alipay(String payInfo, Promise promise) {
|
|
40
|
-
Activity currentActivity = getCurrentActivity();
|
|
41
|
-
if (currentActivity == null) {
|
|
42
|
-
promise.reject("E_NO_ACTIVITY", "No current activity");
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
new Thread(() -> {
|
|
47
|
-
PayTask alipay = new PayTask(currentActivity);
|
|
48
|
-
Map<String, String> result = alipay.payV2(payInfo, true);
|
|
49
|
-
// 返回结果是 Map,转换成 JSON 字符串给 JS
|
|
50
|
-
promise.resolve(result.toString());
|
|
51
|
-
}).start();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 获取 SDK 版本
|
|
55
|
-
@ReactMethod
|
|
56
|
-
public void getVersion(Promise promise) {
|
|
57
|
-
Activity currentActivity = getCurrentActivity();
|
|
58
|
-
if (currentActivity == null) {
|
|
59
|
-
promise.reject("E_NO_ACTIVITY", "No current activity");
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
PayTask alipay = new PayTask(currentActivity);
|
|
64
|
-
String version = alipay.getVersion();
|
|
65
|
-
promise.resolve(version);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
package com.gyj.reactnativealipay;
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.ReactPackage;
|
|
4
|
-
import com.facebook.react.bridge.NativeModule;
|
|
5
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
-
import com.facebook.react.uimanager.ViewManager;
|
|
7
|
-
|
|
8
|
-
import java.util.ArrayList;
|
|
9
|
-
import java.util.Collections;
|
|
10
|
-
import java.util.List;
|
|
11
|
-
|
|
12
|
-
public class RNAlipayPackage implements ReactPackage {
|
|
13
|
-
@Override
|
|
14
|
-
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
15
|
-
List<NativeModule> modules = new ArrayList<>();
|
|
16
|
-
modules.add(new RNAlipayModule(reactContext));
|
|
17
|
-
return modules;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@Override
|
|
21
|
-
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
22
|
-
return Collections.emptyList();
|
|
23
|
-
}
|
|
24
|
-
}
|