diff --git a/android/build.gradle b/android/build.gradle index 402357b..feeb266 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -73,6 +73,10 @@ repositories { dependencies { //noinspection GradleDynamicVersion implementation 'com.facebook.react:react-native:+' // From node_modules + // 微信SDK + // Android Studio环境下:已改用gradle形式,发布到jcenter,请开发者使用gradle来编译、更新微信SDK。 + // 在build.gradle文件中,添加如下依赖即可: + implementation 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+' } def configureReactNativePom(def pom) { diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 6705325..492912c 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,4 +1,8 @@ - + + + + + diff --git a/android/src/main/java/com/uiwjs/react/wechat/RNWechatModule.java b/android/src/main/java/com/uiwjs/react/wechat/RNWechatModule.java index 8272007..4321dbb 100644 --- a/android/src/main/java/com/uiwjs/react/wechat/RNWechatModule.java +++ b/android/src/main/java/com/uiwjs/react/wechat/RNWechatModule.java @@ -4,10 +4,15 @@ import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.Callback; +import com.facebook.react.bridge.Promise; +import com.tencent.mm.opensdk.openapi.WXAPIFactory; +import com.tencent.mm.opensdk.openapi.IWXAPI; public class RNWechatModule extends ReactContextBaseJavaModule { private final ReactApplicationContext reactContext; + private String appId; + private IWXAPI api = null; public RNWechatModule(ReactApplicationContext reactContext) { super(reactContext); @@ -20,8 +25,13 @@ public class RNWechatModule extends ReactContextBaseJavaModule { } @ReactMethod - public void sampleMethod(String stringArgument, int numberArgument, Callback callback) { - // TODO: Implement some actually useful functionality - callback.invoke("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument); + public void registerApp(String appid, Promise promise) { + try { + this.appId = appid; + api = WXAPIFactory.createWXAPI(reactContext.getApplicationContext(), appid, true); + promise.resolve(api.registerApp(appid)); + } catch (Exception e) { + promise.reject("-1", e.getMessage()); + } } } diff --git a/index.d.ts b/index.d.ts index 76be257..e37e969 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,7 @@ /** * 向微信注册应用 + * 必须先注册应用,在 Android 后面的调用才会起作用 * @param appid 通过微信开放平台,[获取appid](https://open.weixin.qq.com/) * @param universalLink Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。 */ diff --git a/package.json b/package.json index f06de63..c0ca2c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uiw/react-native-wechat", - "title": "@uiw/react Native Wechat", + "title": "React Native Wechat", "version": "1.0.0", "description": "React Native 包使用微信分享、登录、收藏、支付等功能。", "main": "index.js",