|
| 1 | +# wx-java-channel-spring-boot-starter |
| 2 | + |
| 3 | +## 快速开始 |
| 4 | +1. 引入依赖 |
| 5 | + ```xml |
| 6 | + <dependencies> |
| 7 | + <dependency> |
| 8 | + <groupId>com.github.binarywang</groupId> |
| 9 | + <artifactId>wx-java-channel-multi-spring-boot-starter</artifactId> |
| 10 | + <version>${version}</version> |
| 11 | + </dependency> |
| 12 | + |
| 13 | + <!-- 配置存储方式为jedis 则引入jedis --> |
| 14 | + <dependency> |
| 15 | + <groupId>redis.clients</groupId> |
| 16 | + <artifactId>jedis</artifactId> |
| 17 | + <version>${jedis.version}</version> |
| 18 | + </dependency> |
| 19 | + |
| 20 | + <!-- 配置存储方式为redisson 则引入redisson --> |
| 21 | + <dependency> |
| 22 | + <groupId>org.redisson</groupId> |
| 23 | + <artifactId>redisson</artifactId> |
| 24 | + <version>${redisson.version}</version> |
| 25 | + </dependency> |
| 26 | + |
| 27 | + <!-- 配置存储方式为redis_template 则引入spring data redis --> |
| 28 | + <dependency> |
| 29 | + <groupId>org.springframework.boot</groupId> |
| 30 | + <artifactId>spring-boot-starter-data-redis</artifactId> |
| 31 | + </dependency> |
| 32 | + </dependencies> |
| 33 | + ``` |
| 34 | +2. 添加配置(application.properties) |
| 35 | + ```properties |
| 36 | + # 视频号配置(必填) |
| 37 | + ## 视频号小店的appId和secret |
| 38 | + wx.channel.app-id=@appId |
| 39 | + wx.channel.secret=@secret |
| 40 | + # 视频号配置 选填 |
| 41 | + ## 设置视频号小店消息服务器配置的token |
| 42 | + wx.channel.token=@token |
| 43 | + ## 设置视频号小店消息服务器配置的EncodingAESKey |
| 44 | + wx.channel.aes-key= |
| 45 | + ## 支持JSON或者XML格式,默认JSON |
| 46 | + wx.channel.msg-data-format=JSON |
| 47 | + ## 是否使用稳定版 Access Token |
| 48 | + wx.channel.use-stable-access-token=false |
| 49 | + |
| 50 | + |
| 51 | + # ConfigStorage 配置(选填) |
| 52 | + ## 配置类型: memory(默认), jedis, redisson, redis_template |
| 53 | + wx.channel.config-storage.type=memory |
| 54 | + ## 相关redis前缀配置: wx:channel(默认) |
| 55 | + wx.channel.config-storage.key-prefix=wx:channel |
| 56 | + wx.channel.config-storage.redis.host=127.0.0.1 |
| 57 | + wx.channel.config-storage.redis.port=6379 |
| 58 | + wx.channel.config-storage.redis.password=123456 |
| 59 | + |
| 60 | + # redis_template 方式使用spring data redis配置 |
| 61 | + spring.data.redis.database=0 |
| 62 | + spring.data.redis.host=127.0.0.1 |
| 63 | + spring.data.redis.password=123456 |
| 64 | + spring.data.redis.port=6379 |
| 65 | + |
| 66 | + # http 客户端配置(选填) |
| 67 | + ## # http客户端类型: http_client(默认) |
| 68 | + wx.channel.config-storage.http-client-type=http_client |
| 69 | + wx.channel.config-storage.http-proxy-host= |
| 70 | + wx.channel.config-storage.http-proxy-port= |
| 71 | + wx.channel.config-storage.http-proxy-username= |
| 72 | + wx.channel.config-storage.http-proxy-password= |
| 73 | + ## 最大重试次数,默认:5 次,如果小于 0,则为 0 |
| 74 | + wx.channel.config-storage.max-retry-times=5 |
| 75 | + ## 重试时间间隔步进,默认:1000 毫秒,如果小于 0,则为 1000 |
| 76 | + wx.channel.config-storage.retry-sleep-millis=1000 |
| 77 | + ``` |
| 78 | +3. 自动注入的类型 |
| 79 | +- `WxChannelService` |
| 80 | +- `WxChannelConfig` |
| 81 | +4. 使用样例 |
| 82 | +```java |
| 83 | +import me.chanjar.weixin.channel.api.WxChannelService; |
| 84 | +import me.chanjar.weixin.channel.bean.shop.ShopInfoResponse; |
| 85 | +import me.chanjar.weixin.channel.util.JsonUtils; |
| 86 | +import me.chanjar.weixin.common.error.WxErrorException; |
| 87 | +import org.springframework.beans.factory.annotation.Autowired; |
| 88 | +import org.springframework.stereotype.Service; |
| 89 | + |
| 90 | +@Service |
| 91 | +public class DemoService { |
| 92 | + @Autowired |
| 93 | + private WxChannelService wxChannelService; |
| 94 | + |
| 95 | + public String getShopInfo() throws WxErrorException { |
| 96 | + // 获取店铺基本信息 |
| 97 | + ShopInfoResponse response = wxChannelService.getBasicService().getShopInfo(); |
| 98 | + // 此处为演示,如果要返回response的结果,建议自己封装一个VO,避免直接返回response |
| 99 | + return JsonUtils.encode(response); |
| 100 | + } |
| 101 | +} |
| 102 | +``` |
| 103 | + |
0 commit comments