---
url: >-
  https://www.dreamlu.net/blog/2019-03-17-spring-boot-starter-weixin-v1-3-4-release.md
description: >-
  把 jfinal-weixin 封装成 Spring Boot Starter，支持多公众号、支付、客服消息、卡券与小程序，v1.3.4
  修复了小程序消息推送配置校验问题。
---

## 简介

`spring-boot-starter-weixin` 是 `jfinal weixin` 的 `spring boot starter`，这个 `starter` 是为了方便 `Spring boot` 用户使用。具体demo请查看：[spring-boot-weixin-demo](https://gitee.com/596392912/spring-boot-starter-weixin/tree/master/spring-boot-weixin-demo) 和 [JFinal-weixin文档](https://gitee.com/jfinal/jfinal-weixin/wikis/pages?title=Home)。

## 功能

1. 支持多公众号
2. 提供公众号登录和用户相关接口
3. 支持多公众号数据统计
4. 支持公众号支付
5. 公众号客服vs消息接口
6. 公众号摇周边接口
7. 公众号卡券相关
8. 微信门店接口
9. 微信硬件
10. 小程序等

## Jar包依赖（最新）

```xml
<dependency>
    <groupId>net.dreamlu</groupId>
    <artifactId>spring-boot-starter-weixin</artifactId>
    <version>1.3.4</version>
</dependency>
```

## 使用

### 消息

#### 公众号

1. 继承`DreamMsgControllerAdapter`，实现需要重写的消息。
2. 类添加注解`@WxMsgController`，注解value为你的消息地址，使用/weixin/wx，已经组合\[@RequestMapping和@Controller]

#### 小程序

1. 继承`DreamWxaMsgController`，实现需要重写的消息。
2. 添加注解`@WxMsgController`，注解value为你的消息地址，使用/weixin/wxa，已经组合\[@RequestMapping和@Controller]

### Api接口

* 类添加`@WxApi`，注解value为你的消息地址，使用/weixin/api，已经组合\[@RequestMapping和@Controller]

### 配置

| 配置项 | 默认值 | 说明 |
| --- | --- | --- |
| dream.weixin.access-token-cache | dreamWeixinCache | 缓存名，需要开启spring cache |
| dream.weixin.app-id-key | appId | 多公众号参数名，如：/weixin/wx?appId=xxx |
| dream.weixin.dev-mode | false | 开发模式 |
| dream.weixin.url-patterns | /weixin/\* | weixin 消息处理spring拦截器url前缀 |
| dream.weixin.wx-configs | 公众号的配置 | 多公众号配置 |
| dream.weixin.wxa-config | 小程序配置 | 小程序配置 |

### 示例配置

demo 项目中的 `application.yml` 配置文件。

```yaml
dream:
  weixin:
    dev-mode: true
    wx-configs:
      - appId: wx9803d1188fa5fbda
        appSecret: db859c968763c582794e7c3d003c3d87
      - appId: wxc03edcd008ad1e70
        appSecret: 11ed9e2b8e3e3c131e7be320a42b2b5a
        token: 123456
    wxa-config:
      app-id: wx4f53594f9a6b3dcb
      app-secret: eec6482ba3804df05bd10895bace0579
```

* cache使用spring的cache，需要`@EnableCaching`开启。
* `access-token-cache` 建议配置有效时间7100秒。

## 更新说明

> ### 2019-03-17 v1.3.4
>
> 解决小程序，启用并设置消息推送配置校验不通过的问题。

### 2019-03-07 v1.3.3

> 升级到 `gradle 5.2.1`。
> 升级 `JFinal` 到 `3.6`。
> 升级 `JFinal Weixin` 到 `2.3`。
> 使用 `mica-auto` 生成 `spring.factories`、`devtools` 配置。
> `InMsg` 消息对象采用 `request` 存储，去掉 `@WxMsgController` 中的 Scope 配置，将消息控制器还原为单例。

### 2018-12-23 v1.3.2

> 修复 `SpringAccessTokenCache` 没有配置的问题，感谢 qq:`A梦的小C` 反馈。

### 2018-12-23 v1.3.1

> `WeixinAppConfig` 改为实现 `SmartInitializingSingleton`。

### 2018-05-03 v1.3.0

> 弃用`@EnableDreamWeixin`，导入jar包即可享用。
> 将消息路由改为spring接管。

## 开源推荐

* Spring boot 微服务高效开发 `mica` 工具集：<https://gitee.com/596392912/mica>
* `Avue` 一款基于vue可配置化的神奇框架：<https://gitee.com/smallweigit/avue>
* `pig` 宇宙最强微服务（架构师必备）：<https://gitee.com/log4j/pig>
* `SpringBlade` 完整的线上解决方案（企业开发必备）：<https://gitee.com/smallc/SpringBlade>
* `IJPay` 支付SDK让支付触手可及：<https://gitee.com/javen205/IJPay>
* 加入【如梦技术】Spring QQ群：479710041，了解更多。

## 微信公众号

![如梦技术](/img/dreamlu-weixin.jpg)

精彩内容每日推荐！！！
