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