File tree Expand file tree Collapse file tree 5 files changed +24
-5
lines changed
java/com/uiwjs/react/wechat Expand file tree Collapse file tree 5 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,10 @@ repositories {
73
73
dependencies {
74
74
// noinspection GradleDynamicVersion
75
75
implementation ' com.facebook.react:react-native:+' // From node_modules
76
+ // 微信SDK
77
+ // Android Studio环境下:已改用gradle形式,发布到jcenter,请开发者使用gradle来编译、更新微信SDK。
78
+ // 在build.gradle文件中,添加如下依赖即可:
79
+ implementation ' com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+'
76
80
}
77
81
78
82
def configureReactNativePom (def pom ) {
Original file line number Diff line number Diff line change 1
1
<manifest xmlns : android =" http://schemas.android.com/apk/res/android"
2
2
package =" com.uiwjs.react.wechat" >
3
-
3
+ <uses-permission android : name =" android.permission.INTERNET" />
4
+ <uses-permission android : name =" android.permission.ACCESS_NETWORK_STATE" />
5
+ <uses-permission android : name =" android.permission.ACCESS_WIFI_STATE" />
6
+ <uses-permission android : name =" android.permission.READ_PHONE_STATE" />
7
+ <uses-permission android : name =" android.permission.WRITE_EXTERNAL_STORAGE" />
4
8
</manifest >
Original file line number Diff line number Diff line change 4
4
import com .facebook .react .bridge .ReactContextBaseJavaModule ;
5
5
import com .facebook .react .bridge .ReactMethod ;
6
6
import com .facebook .react .bridge .Callback ;
7
+ import com .facebook .react .bridge .Promise ;
8
+ import com .tencent .mm .opensdk .openapi .WXAPIFactory ;
9
+ import com .tencent .mm .opensdk .openapi .IWXAPI ;
7
10
8
11
public class RNWechatModule extends ReactContextBaseJavaModule {
9
12
10
13
private final ReactApplicationContext reactContext ;
14
+ private String appId ;
15
+ private IWXAPI api = null ;
11
16
12
17
public RNWechatModule (ReactApplicationContext reactContext ) {
13
18
super (reactContext );
@@ -20,8 +25,13 @@ public String getName() {
20
25
}
21
26
22
27
@ ReactMethod
23
- public void sampleMethod (String stringArgument , int numberArgument , Callback callback ) {
24
- // TODO: Implement some actually useful functionality
25
- callback .invoke ("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument );
28
+ public void registerApp (String appid , Promise promise ) {
29
+ try {
30
+ this .appId = appid ;
31
+ api = WXAPIFactory .createWXAPI (reactContext .getApplicationContext (), appid , true );
32
+ promise .resolve (api .registerApp (appid ));
33
+ } catch (Exception e ) {
34
+ promise .reject ("-1" , e .getMessage ());
35
+ }
26
36
}
27
37
}
Original file line number Diff line number Diff line change 1
1
2
2
/**
3
3
* 向微信注册应用
4
+ * 必须先注册应用,在 Android 后面的调用才会起作用
4
5
* @param appid 通过微信开放平台,[获取appid](https://open.weixin.qq.com/)
5
6
* @param universalLink Universal Link(通用链接)是苹果在 iOS9 推出的,一种能够方便的通过传统 HTTPS 链接来启动 APP 的功能,可以使用相同的网址打开网址和 APP。
6
7
*/
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @uiw/react-native-wechat" ,
3
- "title" : " @uiw/react Native Wechat" ,
3
+ "title" : " React Native Wechat" ,
4
4
"version" : " 1.0.0" ,
5
5
"description" : " React Native 包使用微信分享、登录、收藏、支付等功能。" ,
6
6
"main" : " index.js" ,
You can’t perform that action at this time.
0 commit comments