From 44f357cea494f8046eef1ae8ed534fca1ce4a1ec Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 24 Oct 2021 11:53:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=20weixin-mp-java=20=EF=BC=8C?= =?UTF-8?q?=E7=BC=96=E5=86=99=E7=9B=B8=E5=85=B3=E7=A4=BA=E4=BE=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-dependencies/pom.xml | 5 +++ yudao-framework/pom.xml | 3 +- .../yudao-spring-boot-starter-biz-pay/pom.xml | 1 + .../yudao-spring-boot-starter-biz-sms/pom.xml | 1 + .../pom.xml | 43 +++++++++++++++++++ .../framework/weixin/WxMpServiceTest.java | 34 +++++++++++++++ .../resources/application.yml | 11 +++++ yudao-user-server/pom.xml | 4 ++ .../src/main/resources/application-local.yaml | 12 ++++++ .../src/main/resources/static/pay.html | 0 10 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-weixin/pom.xml create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-weixin/src/test-integration/java/cn/iocoder/yudao/framework/weixin/WxMpServiceTest.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-weixin/src/test-integration/resources/application.yml create mode 100644 yudao-user-server/src/main/resources/static/pay.html diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index 43dfea757..1be4a0c8f 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -98,6 +98,11 @@ yudao-spring-boot-starter-biz-pay ${revision} + + cn.iocoder.boot + yudao-spring-boot-starter-biz-weixin + ${revision} + diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index b5a2e4c93..f3927b3a3 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -28,8 +28,9 @@ yudao-spring-boot-starter-biz-operatelog yudao-spring-boot-starter-biz-dict yudao-spring-boot-starter-biz-sms - yudao-spring-boot-starter-extension yudao-spring-boot-starter-biz-pay + yudao-spring-boot-starter-biz-weixin + yudao-spring-boot-starter-extension yudao-framework diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-pay/pom.xml index f7be5c619..217aac56d 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/pom.xml @@ -72,4 +72,5 @@ test + diff --git a/yudao-framework/yudao-spring-boot-starter-biz-sms/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-sms/pom.xml index c72a63b30..bfed26a86 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-sms/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-biz-sms/pom.xml @@ -79,4 +79,5 @@ + diff --git a/yudao-framework/yudao-spring-boot-starter-biz-weixin/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-weixin/pom.xml new file mode 100644 index 000000000..fddab18a4 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-weixin/pom.xml @@ -0,0 +1,43 @@ + + + + cn.iocoder.boot + yudao-framework + ${revision} + + 4.0.0 + yudao-spring-boot-starter-biz-weixin + jar + + ${artifactId} + 微信拓展 + 1. 基于 weixin-java-mp 库,对接微信公众号平台。目前主要解决微信公众号的支付场景。 + + https://github.com/YunaiV/ruoyi-vue-pro + + + + cn.iocoder.boot + yudao-common + + + + + cn.iocoder.boot + yudao-spring-boot-starter-test + test + + + + + com.github.binarywang + + wx-java-mp-spring-boot-starter + 4.1.9.B + + + + + diff --git a/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/test-integration/java/cn/iocoder/yudao/framework/weixin/WxMpServiceTest.java b/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/test-integration/java/cn/iocoder/yudao/framework/weixin/WxMpServiceTest.java new file mode 100644 index 000000000..392e651c5 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/test-integration/java/cn/iocoder/yudao/framework/weixin/WxMpServiceTest.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.framework.weixin; + +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.annotation.Resource; + +@SpringBootTest(classes = WxMpServiceTest.Application.class) +public class WxMpServiceTest { + + @Resource + private WxMpService wxMpService; + + @Test + public void testGetAccessToken() throws WxErrorException { + String accessToken = wxMpService.getAccessToken(); + System.out.println(accessToken); + } + + @Test + public void testGet() throws WxErrorException { + String jsapiTicket = wxMpService.getJsapiTicket(); + System.out.println(jsapiTicket); + } + + @SpringBootApplication + public static class Application { + + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/test-integration/resources/application.yml b/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/test-integration/resources/application.yml new file mode 100644 index 000000000..9b30060a8 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-weixin/src/test-integration/resources/application.yml @@ -0,0 +1,11 @@ +--- #################### 微信公众号相关配置 #################### +wx: # 参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档 + mp: + # 公众号配置(必填) + app-id: wx041349c6f39b268b + secret: 5abee519483bc9f8cb37ce280e814bd0 + # 存储配置,解决 AccessToken 的跨节点的共享 +# config-storage: +# type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 +# key-prefix: wx # Redis Key 的前缀 TODO 芋艿:解决下 Redis key 管理的配置 +# http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台 diff --git a/yudao-user-server/pom.xml b/yudao-user-server/pom.xml index fe55b34f9..6822d5097 100644 --- a/yudao-user-server/pom.xml +++ b/yudao-user-server/pom.xml @@ -31,6 +31,10 @@ cn.iocoder.boot yudao-spring-boot-starter-biz-sms + + cn.iocoder.boot + yudao-spring-boot-starter-biz-weixin + diff --git a/yudao-user-server/src/main/resources/application-local.yaml b/yudao-user-server/src/main/resources/application-local.yaml index 506ee19f6..3e9fba818 100644 --- a/yudao-user-server/src/main/resources/application-local.yaml +++ b/yudao-user-server/src/main/resources/application-local.yaml @@ -121,6 +121,18 @@ logging: file: name: ${user.home}/logs/${spring.application.name}.log # 日志文件名,全路径 +--- #################### 微信公众号相关配置 #################### +wx: # 参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档 + mp: + # 公众号配置(必填) + app-id: wx041349c6f39b268b + secret: 5abee519483bc9f8cb37ce280e814bd0 + # 存储配置,解决 AccessToken 的跨节点的共享 + config-storage: + type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 + key-prefix: wx # Redis Key 的前缀 TODO 芋艿:解决下 Redis key 管理的配置 + http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台 + --- #################### 芋道相关配置 #################### # 芋道配置项,设置当前项目所有自定义的配置 diff --git a/yudao-user-server/src/main/resources/static/pay.html b/yudao-user-server/src/main/resources/static/pay.html new file mode 100644 index 000000000..e69de29bb