File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ ## 如何使用` WxJava ` 进行小程序云开发
4
+
5
+ [ 云开发-一站式后端云服务] ( https://tencentcloudbase.github.io/ )
6
+
7
+ ### 一、 引入maven依赖
8
+
9
+ ```
10
+ <dependency>
11
+ <groupId>com.github.binarywang</groupId>
12
+ <artifactId>weixin-java-miniapp</artifactId>
13
+ <version>3.7.1.B</version>
14
+ </dependency>
15
+ ```
16
+
17
+
18
+ ### 二、 构造配置类,填入相关参数
19
+
20
+ ```
21
+ WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
22
+ config.setAppid(...); // 微信小程序的appid
23
+ config.setSecret(...); // 微信小程序的Secret
24
+ config.setToken(...); // 微信小程序消息服务器配置的token,如果程序不涉及相关功能,可以忽略
25
+ config.setAesKey(...); // 微信小程序消息服务器配置的EncodingAESKey,同上,如果不涉及,可以忽略
26
+ config.setMsgDataFormat(...); // 消息数据格式,可以为XML或者JSON
27
+ ```
28
+
29
+
30
+ ### 三、 构造service类,关联上述配置
31
+
32
+ ```
33
+ WxMaService wxMaService= new WxMaServiceImpl();
34
+
35
+ wxMaService.setWxMaConfig(config);
36
+ ```
37
+
38
+ ### 四、 根据小程序前端需要调用相应的方法:
39
+
40
+ 目前WxJava 已支持当前所有接口(当然如果官方后续加入新接口,则还未在最新版本中实现,会考虑在之后版本中加入),所有以支持接口可以参考JavaDoc在线版本:http://binary.ac.cn/weixin-java-miniapp-javadoc/cn/binarywang/wx/miniapp/api/WxMaCloudService.html
41
+
42
+
43
+ 以触发云函数接口为例,可以采用如下方式调用invokeCloudFunction方法:
44
+
45
+
46
+ ```
47
+ String result = wxMaService.getCloudService().invokeCloudFunction("rcn", "login", "{}"); // 拿到resule之后,可以在后续加入自己的处理逻辑代码
48
+ ```
49
+
50
+
51
+ 更多方法调用实例可以参考WxJava源码中的单元测试类:` cn.binarywang.wx.miniapp.api.impl.WxMaCloudServiceImplTest `
52
+
53
+ ### 五、 Spring框架整合:
54
+
55
+ 可以参考https://github.com/binarywang/weixin-java-miniapp-demo 此项目整合Spring开发。
56
+ 此项目基于spring boot,如果需要支持Spring MVC项目,适当改造即可。
You can’t perform that action at this time.
0 commit comments