Commit 44f357cea494f8046eef1ae8ed534fca1ce4a1ec

Authored by YunaiV
1 parent 3a77cc23

接入 weixin-mp-java ,编写相关示例。

yudao-dependencies/pom.xml
@@ -98,6 +98,11 @@ @@ -98,6 +98,11 @@
98 <artifactId>yudao-spring-boot-starter-biz-pay</artifactId> 98 <artifactId>yudao-spring-boot-starter-biz-pay</artifactId>
99 <version>${revision}</version> 99 <version>${revision}</version>
100 </dependency> 100 </dependency>
  101 + <dependency>
  102 + <groupId>cn.iocoder.boot</groupId>
  103 + <artifactId>yudao-spring-boot-starter-biz-weixin</artifactId>
  104 + <version>${revision}</version>
  105 + </dependency>
101 106
102 <!-- Spring 核心 --> 107 <!-- Spring 核心 -->
103 <dependency> 108 <dependency>
yudao-framework/pom.xml
@@ -28,8 +28,9 @@ @@ -28,8 +28,9 @@
28 <module>yudao-spring-boot-starter-biz-operatelog</module> 28 <module>yudao-spring-boot-starter-biz-operatelog</module>
29 <module>yudao-spring-boot-starter-biz-dict</module> 29 <module>yudao-spring-boot-starter-biz-dict</module>
30 <module>yudao-spring-boot-starter-biz-sms</module> 30 <module>yudao-spring-boot-starter-biz-sms</module>
31 - <module>yudao-spring-boot-starter-extension</module>  
32 <module>yudao-spring-boot-starter-biz-pay</module> 31 <module>yudao-spring-boot-starter-biz-pay</module>
  32 + <module>yudao-spring-boot-starter-biz-weixin</module>
  33 + <module>yudao-spring-boot-starter-extension</module>
33 </modules> 34 </modules>
34 35
35 <artifactId>yudao-framework</artifactId> 36 <artifactId>yudao-framework</artifactId>
yudao-framework/yudao-spring-boot-starter-biz-pay/pom.xml
@@ -72,4 +72,5 @@ @@ -72,4 +72,5 @@
72 <scope>test</scope> 72 <scope>test</scope>
73 </dependency> 73 </dependency>
74 </dependencies> 74 </dependencies>
  75 +
75 </project> 76 </project>
yudao-framework/yudao-spring-boot-starter-biz-sms/pom.xml
@@ -79,4 +79,5 @@ @@ -79,4 +79,5 @@
79 </dependency> 79 </dependency>
80 <!-- SMS SDK end --> 80 <!-- SMS SDK end -->
81 </dependencies> 81 </dependencies>
  82 +
82 </project> 83 </project>
yudao-framework/yudao-spring-boot-starter-biz-weixin/pom.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <parent>
  6 + <groupId>cn.iocoder.boot</groupId>
  7 + <artifactId>yudao-framework</artifactId>
  8 + <version>${revision}</version>
  9 + </parent>
  10 + <modelVersion>4.0.0</modelVersion>
  11 + <artifactId>yudao-spring-boot-starter-biz-weixin</artifactId>
  12 + <packaging>jar</packaging>
  13 +
  14 + <name>${artifactId}</name>
  15 + <description>微信拓展
  16 + 1. 基于 weixin-java-mp 库,对接微信公众号平台。目前主要解决微信公众号的支付场景。
  17 + </description>
  18 + <url>https://github.com/YunaiV/ruoyi-vue-pro</url>
  19 +
  20 + <dependencies>
  21 + <dependency>
  22 + <groupId>cn.iocoder.boot</groupId>
  23 + <artifactId>yudao-common</artifactId>
  24 + </dependency>
  25 +
  26 + <!-- Test 测试相关 -->
  27 + <dependency>
  28 + <groupId>cn.iocoder.boot</groupId>
  29 + <artifactId>yudao-spring-boot-starter-test</artifactId>
  30 + <scope>test</scope>
  31 + </dependency>
  32 +
  33 + <!-- 三方云服务相关 -->
  34 + <dependency>
  35 + <groupId>com.github.binarywang</groupId>
  36 +<!-- <artifactId>weixin-java-mp</artifactId>-->
  37 + <artifactId>wx-java-mp-spring-boot-starter</artifactId>
  38 + <version>4.1.9.B</version>
  39 + </dependency>
  40 + <!-- TODO 芋艿:清理 -->
  41 + </dependencies>
  42 +
  43 +</project>
yudao-framework/yudao-spring-boot-starter-biz-weixin/src/test-integration/java/cn/iocoder/yudao/framework/weixin/WxMpServiceTest.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.weixin;
  2 +
  3 +import me.chanjar.weixin.common.error.WxErrorException;
  4 +import me.chanjar.weixin.mp.api.WxMpService;
  5 +import org.junit.jupiter.api.Test;
  6 +import org.springframework.boot.autoconfigure.SpringBootApplication;
  7 +import org.springframework.boot.test.context.SpringBootTest;
  8 +
  9 +import javax.annotation.Resource;
  10 +
  11 +@SpringBootTest(classes = WxMpServiceTest.Application.class)
  12 +public class WxMpServiceTest {
  13 +
  14 + @Resource
  15 + private WxMpService wxMpService;
  16 +
  17 + @Test
  18 + public void testGetAccessToken() throws WxErrorException {
  19 + String accessToken = wxMpService.getAccessToken();
  20 + System.out.println(accessToken);
  21 + }
  22 +
  23 + @Test
  24 + public void testGet() throws WxErrorException {
  25 + String jsapiTicket = wxMpService.getJsapiTicket();
  26 + System.out.println(jsapiTicket);
  27 + }
  28 +
  29 + @SpringBootApplication
  30 + public static class Application {
  31 +
  32 + }
  33 +
  34 +}
yudao-framework/yudao-spring-boot-starter-biz-weixin/src/test-integration/resources/application.yml 0 → 100644
  1 +--- #################### 微信公众号相关配置 ####################
  2 +wx: # 参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档
  3 + mp:
  4 + # 公众号配置(必填)
  5 + app-id: wx041349c6f39b268b
  6 + secret: 5abee519483bc9f8cb37ce280e814bd0
  7 + # 存储配置,解决 AccessToken 的跨节点的共享
  8 +# config-storage:
  9 +# type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取
  10 +# key-prefix: wx # Redis Key 的前缀 TODO 芋艿:解决下 Redis key 管理的配置
  11 +# http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台
yudao-user-server/pom.xml
@@ -31,6 +31,10 @@ @@ -31,6 +31,10 @@
31 <groupId>cn.iocoder.boot</groupId> 31 <groupId>cn.iocoder.boot</groupId>
32 <artifactId>yudao-spring-boot-starter-biz-sms</artifactId> 32 <artifactId>yudao-spring-boot-starter-biz-sms</artifactId>
33 </dependency> 33 </dependency>
  34 + <dependency>
  35 + <groupId>cn.iocoder.boot</groupId>
  36 + <artifactId>yudao-spring-boot-starter-biz-weixin</artifactId>
  37 + </dependency>
34 38
35 <!-- Web 相关 --> 39 <!-- Web 相关 -->
36 <dependency> 40 <dependency>
yudao-user-server/src/main/resources/application-local.yaml
@@ -121,6 +121,18 @@ logging: @@ -121,6 +121,18 @@ logging:
121 file: 121 file:
122 name: ${user.home}/logs/${spring.application.name}.log # 日志文件名,全路径 122 name: ${user.home}/logs/${spring.application.name}.log # 日志文件名,全路径
123 123
  124 +--- #################### 微信公众号相关配置 ####################
  125 +wx: # 参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档
  126 + mp:
  127 + # 公众号配置(必填)
  128 + app-id: wx041349c6f39b268b
  129 + secret: 5abee519483bc9f8cb37ce280e814bd0
  130 + # 存储配置,解决 AccessToken 的跨节点的共享
  131 + config-storage:
  132 + type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取
  133 + key-prefix: wx # Redis Key 的前缀 TODO 芋艿:解决下 Redis key 管理的配置
  134 + http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台
  135 +
124 --- #################### 芋道相关配置 #################### 136 --- #################### 芋道相关配置 ####################
125 137
126 # 芋道配置项,设置当前项目所有自定义的配置 138 # 芋道配置项,设置当前项目所有自定义的配置
yudao-user-server/src/main/resources/static/pay.html 0 → 100644