55import cn .binarywang .wx .miniapp .bean .WxMaKefuMessage ;
66import cn .binarywang .wx .miniapp .bean .WxMaSubscribeMessage ;
77import cn .binarywang .wx .miniapp .config .impl .WxMaDefaultConfigImpl ;
8+ import cn .binarywang .wx .miniapp .config .impl .WxMaRedisConfigImpl ;
89import cn .binarywang .wx .miniapp .message .WxMaMessageHandler ;
910import cn .binarywang .wx .miniapp .message .WxMaMessageRouter ;
1011import com .google .common .collect .Lists ;
1112import com .google .common .collect .Maps ;
13+ import lombok .extern .slf4j .Slf4j ;
1214import me .chanjar .weixin .common .bean .result .WxMediaUploadResult ;
1315import me .chanjar .weixin .common .error .WxErrorException ;
16+ import me .chanjar .weixin .common .error .WxRuntimeException ;
1417import org .springframework .beans .factory .annotation .Autowired ;
1518import org .springframework .boot .context .properties .EnableConfigurationProperties ;
1619import org .springframework .context .annotation .Configuration ;
20+ import redis .clients .jedis .JedisPool ;
1721
1822import javax .annotation .PostConstruct ;
1923import java .io .File ;
2428/**
2529 * @author <a href="https://github.com/binarywang">Binary Wang</a>
2630 */
31+ @ Slf4j
2732@ Configuration
2833@ EnableConfigurationProperties (WxMaProperties .class )
2934public class WxMaConfiguration {
30- private WxMaProperties properties ;
35+ private final WxMaProperties properties ;
3136
32- private static Map <String , WxMaMessageRouter > routers = Maps .newHashMap ();
33- private static Map <String , WxMaService > maServices = Maps . newHashMap () ;
37+ private static final Map <String , WxMaMessageRouter > routers = Maps .newHashMap ();
38+ private static Map <String , WxMaService > maServices ;
3439
3540 @ Autowired
3641 public WxMaConfiguration (WxMaProperties properties ) {
@@ -54,12 +59,13 @@ public static WxMaMessageRouter getRouter(String appid) {
5459 public void init () {
5560 List <WxMaProperties .Config > configs = this .properties .getConfigs ();
5661 if (configs == null ) {
57- throw new RuntimeException ("大哥,拜托先看下项目首页的说明(readme文件),添加下相关配置,注意别配错了!" );
62+ throw new WxRuntimeException ("大哥,拜托先看下项目首页的说明(readme文件),添加下相关配置,注意别配错了!" );
5863 }
5964
6065 maServices = configs .stream ()
6166 .map (a -> {
62- WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl ();
67+ // WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
68+ WxMaDefaultConfigImpl config = new WxMaRedisConfigImpl (new JedisPool ());
6369 config .setAppid (a .getAppid ());
6470 config .setSecret (a .getSecret ());
6571 config .setToken (a .getToken ());
@@ -95,7 +101,7 @@ private WxMaMessageRouter newRouter(WxMaService service) {
95101 };
96102
97103 private final WxMaMessageHandler logHandler = (wxMessage , context , service , sessionManager ) -> {
98- System . out . println ("收到消息:" + wxMessage .toString ());
104+ log . info ("收到消息:" + wxMessage .toString ());
99105 service .getMsgService ().sendKefuMsg (WxMaKefuMessage .newTextBuilder ().content ("收到信息为:" + wxMessage .toJson ())
100106 .toUser (wxMessage .getFromUser ()).build ());
101107 return null ;
0 commit comments