From 9fcf20f63a468d28ea45e0bf26f5f3350004f629 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Tue, 9 Apr 2019 10:49:27 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=AE=E4=BF=A1=E5=BC=80=E6=94=BE=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0][=E4=BF=AE=E6=94=B9]:accessToken=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=90=AF=E7=94=A8=E5=BE=AE=E4=BF=A1=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E5=BC=80=E6=94=BE=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/iformall/UserApplication.java | 20 +- .../controller/WxAppinfoController.java | 14 - .../src/main/resources/application-dev.yml | 23 +- .../src/main/resources/application-prod.yml | 35 ++- .../src/main/resources/application-test.yml | 21 ++ .../main/java/com/iformall/BApplication.java | 8 + .../iformall/controller/BaseController.java | 23 +- .../iformall/controller/WxInfoController.java | 48 ++-- .../src/main/resources/application-dev.yml | 24 +- .../src/main/resources/application-prod.yml | 23 ++ .../src/main/resources/application-test.yml | 23 ++ .../main/java/com/iformall/CApplication.java | 8 + .../iformall/controller/BaseController.java | 29 +- .../controller/WxUserGrantController.java | 29 +- .../src/main/resources/application-dev.yml | 22 ++ .../src/main/resources/application-prod.yml | 23 +- .../src/main/resources/application-test.yml | 23 ++ .../com/iformall/ConsumerApplication.java | 20 +- .../src/main/resources/application-dev.yml | 22 ++ .../src/main/resources/application-prod.yml | 23 +- .../src/main/resources/application-test.yml | 23 ++ .../com/iformall/ScheduleApplication.java | 20 +- .../schedule/WeChatAccessTokenSchedule.java | 13 +- .../iformall/schedule/WxAppVisitSchedule.java | 22 +- .../src/main/resources/application-dev.yml | 22 ++ .../src/main/resources/application-prod.yml | 23 +- .../src/main/resources/application-test.yml | 23 ++ .../iformall/config/WechatOpenProperties.java | 69 +++++ .../iformall/config/WechatRedisProperies.java | 124 +++++++++ .../mapper/WxAuthorizerInfoMapper.java | 12 +- .../mapper/WxComponentVerifyTicketMapper.java | 6 +- .../iformall/service/WxAppinfoService.java | 7 - .../impl/SendSmartAppMsgServiceImpl.java | 15 +- .../service/impl/WxAppinfoServiceImpl.java | 37 --- .../service/impl/WxScreenAdServiceImpl.java | 16 +- .../wechat/FmOpenInRedisDBConfigStorage.java | 253 ++++++++++++++++++ .../service/wechat/FmOpenService.java | 73 +++++ .../mapper/WxAuthorizerInfoMapper.xml | 8 + .../com/iformall/SocketServerApplication.java | 20 +- .../iformall/controller/BaseController.java | 28 +- .../src/main/resources/application-dev.yml | 22 ++ .../src/main/resources/application-prod.yml | 23 +- .../src/main/resources/application-test.yml | 23 ++ pom.xml | 7 + 44 files changed, 1190 insertions(+), 160 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/config/WechatOpenProperties.java create mode 100644 mallinkService/src/main/java/com/iformall/config/WechatRedisProperies.java create mode 100644 mallinkService/src/main/java/com/iformall/service/wechat/FmOpenInRedisDBConfigStorage.java create mode 100644 mallinkService/src/main/java/com/iformall/service/wechat/FmOpenService.java diff --git a/mallinkAdmin/src/main/java/com/iformall/UserApplication.java b/mallinkAdmin/src/main/java/com/iformall/UserApplication.java index f72f27524..668c20847 100644 --- a/mallinkAdmin/src/main/java/com/iformall/UserApplication.java +++ b/mallinkAdmin/src/main/java/com/iformall/UserApplication.java @@ -22,13 +22,21 @@ import tk.mybatis.spring.annotation.MapperScan; @EnableRocketMQ public class UserApplication { - @Value("${fm.exception}") - private boolean fmException; + @Value("${fm.exception}") + private boolean fmException; - @Bean - public boolean isFmException() { - return fmException; - } + @Value("${fm.open}") + private boolean fmOpen; + + @Bean + public boolean isFmException() { + return fmException; + } + + @Bean + public boolean isFmOpen() { + return fmOpen; + } public static void main(String[] args) { SpringApplication.run(UserApplication.class, args); diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxAppinfoController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxAppinfoController.java index d935fdbdb..edbeadb87 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxAppinfoController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxAppinfoController.java @@ -74,20 +74,6 @@ public class WxAppinfoController extends BaseController { return new ResultData(Result.SUCCESS, "查询成功", wxAppinfoService.getById(id)); } - - @ApiOperation("C端更新AccessToken, 无限制二维码生成需要更新token") - @GetMapping("/accessTokenUpdate") - public ResultData ctokenUpdate() { - logger.debug("[" + getIpAddr() + "] WxAppinfoController::ctokenUpdate"); - try { - wxAppinfoService.ctokenUpdate(getTenantId()); - } catch (Exception e) { - logger.error(e.getMessage()); - } - - return new ResultData(); - } - @ApiOperation(value = "下载二维码", notes = "参数{\"pageUrl\":\"String\", \"sceneParam\":\"二维码参数\", \"type\":0:有限二维码,1:无限二维码,\"withText\":int(0:不带字, 1:加一行字,2:加两行字),\"text1\":\"String\",\"text2\":\"String\"}") @PostMapping("/downQrCode") public ResultData downQrCode(HttpServletRequest request, HttpServletResponse response, @RequestBody Map params) { diff --git a/mallinkAdmin/src/main/resources/application-dev.yml b/mallinkAdmin/src/main/resources/application-dev.yml index 5bfd19ec2..4011c29c5 100644 --- a/mallinkAdmin/src/main/resources/application-dev.yml +++ b/mallinkAdmin/src/main/resources/application-dev.yml @@ -22,7 +22,7 @@ spring: poolPreparedStatements: true maxOpenPreparedStatements: 20 connectionProperties: "druid.stat.mergeSql=true;druid.stat.slowSqlMillis=6000" - #jackson: + #jackson: #date-format: yyyy-MM-dd HH:mm:ss # REDIS redis: @@ -85,6 +85,25 @@ wechat: appId: "wxe31beafbfd8295ba" secret: "c689fabf3c4c9f5b6424ff2a36a26727" url: "https://mall.youlane.cn" + open: + componentAppId: "wx897e4673286c915d" + componentSecret: "cdfdfda65c45689beb6766c4c427eed2" + componentToken: "formall2018" + componentAesKey: "htKq8EjBMPNndfZQK9JiFojFaqFwFpw42VfeWFtx7HN" + redis: + host: 202.165.179.86 + port: 6379 + password: ENC(aYJ3Wr2UWtkORRQjjrWWpz2ZeTISsHOA) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 500 + max-wait: -1 + min-idle: 10 jasypt: encryptor: @@ -92,6 +111,8 @@ jasypt: fm: exception: false + deploy: 1 + open: false ueditor: config: config.json diff --git a/mallinkAdmin/src/main/resources/application-prod.yml b/mallinkAdmin/src/main/resources/application-prod.yml index 99f82a91a..85b34da23 100644 --- a/mallinkAdmin/src/main/resources/application-prod.yml +++ b/mallinkAdmin/src/main/resources/application-prod.yml @@ -44,13 +44,13 @@ spring: password: ENC(APQMO9XQRzMKd0eap+oSSOYH9MQe/r5K0YFF9A9mizU=) # 授权密码 properties: mail: - smtp: - auth: true - starttls: - enable: true - socketFactory: - port: 465 - class: javax.net.ssl.SSLSocketFactory + smtp: + auth: true + starttls: + enable: true + socketFactory: + port: 465 + class: javax.net.ssl.SSLSocketFactory # RABBITMQ rabbitmq: host: localhost @@ -73,9 +73,30 @@ wechat: appId: "wx9cc4ca09eb20fe03" secret: "af1d7f7a1268022a73cb4ce0b9cf0985" url: "https://admin.malls.iformall.com" + open: + componentAppId: ENC(b3JG0MUZgQfz5Zj+DC2ZM1zDeLOiGTmmeokfe2O8kaM=) + componentSecret: ENC(QVyc4BPGdnSjXGs2ivgpDBE1v8wPWHLLRMYI7Vv8uYwC0SiZHQz0QpyyQV/b48Pb) + componentToken: ENC(rkxj0733WxFFDLgA9x01m2s5Fi2L+0PC) + componentAesKey: ENC(EIbJUBpbYOrLb4YQ/HXLQmxlxgAqIp2ZmpnGICC8pu5xiTz3Cqfkbwd2S8raCcK/IvYcX2GmedI=) + redis: + host: 127.0.0.1 + port: 6379 + password: ENC(8gYU47Fu93NUJPhwPCiPbAT+6VFA1YDx1egK4Z0Nl6w=) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 100 + max-wait: -1 + min-idle: 10 fm: exception: true + deploy: 3 + open: true ueditor: config: config.json diff --git a/mallinkAdmin/src/main/resources/application-test.yml b/mallinkAdmin/src/main/resources/application-test.yml index 8302e5688..2178ea199 100644 --- a/mallinkAdmin/src/main/resources/application-test.yml +++ b/mallinkAdmin/src/main/resources/application-test.yml @@ -73,9 +73,30 @@ wechat: appId: "wx091907dd0bfd3f6b" secret: "2a2ca10738998b9ef92c1fe8a4d366a6" url: "https://admintest.malls.iformall.com" + open: + componentAppId: ENC(hnH31XdNzArfMfikKgBFpqQuJUl6rVOPFFcAVyb595o=) + componentSecret: ENC(t/GUVX5L+U7LCwSvZ5WmxAnmTMrc/Uy1nljsrokuzzsBL2j6BEVnrS/n7DCdGc/G) + componentToken: ENC(gUF1m0YgCCI2IY54fX6sGLZVlCswA8tG) + componentAesKey: ENC(TYHcrIkICtfrCfGq4HW6s1b/pHf7OD2uyPN11SzJNB0acqJ/4JVX1nuljo/cAtgMG4O05TImLQc=) + redis: + host: 127.0.0.1 + port: 6379 + password: ENC(QFwqv3NshvvGhFPiP8rwhvbnxk+rFSqhJi8Pw6TogSg=) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 100 + max-wait: -1 + min-idle: 10 fm: exception: true + deploy: 2 + open: true ueditor: config: config.json diff --git a/mallinkBApi/src/main/java/com/iformall/BApplication.java b/mallinkBApi/src/main/java/com/iformall/BApplication.java index 0dabd6ccc..8ab96db8a 100644 --- a/mallinkBApi/src/main/java/com/iformall/BApplication.java +++ b/mallinkBApi/src/main/java/com/iformall/BApplication.java @@ -21,11 +21,19 @@ public class BApplication { @Value("${fm.exception}") private boolean fmException; + @Value("${fm.open}") + private boolean fmOpen; + @Bean public boolean isFmException() { return fmException; } + @Bean + public boolean isFmOpen() { + return fmOpen; + } + public static void main(String[] args) { SpringApplication.run(BApplication.class, args); diff --git a/mallinkBApi/src/main/java/com/iformall/controller/BaseController.java b/mallinkBApi/src/main/java/com/iformall/controller/BaseController.java index 75e565418..89249f077 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/BaseController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/BaseController.java @@ -12,6 +12,7 @@ import com.iformall.domain.po.WxMerchantBUser; import com.iformall.exception.MallinkException; import com.iformall.service.WxAppinfoService; import com.iformall.service.WxMerchantBUserService; +import com.iformall.service.wechat.FmOpenService; import com.iformall.utils.Constant; import com.iformall.utils.IPUtil; import com.iformall.utils.MaUtil; @@ -26,12 +27,17 @@ import javax.servlet.http.HttpServletRequest; @RestController public class BaseController { + @Autowired + private boolean isFmOpen; @Autowired private WxMerchantBUserService wxMerchantBUserService; @Autowired private WxAppinfoService wxAppinfoService; + @Autowired + private FmOpenService openService; + @InitBinder public void InitBinder(WebDataBinder dataBinder) { dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() { @@ -79,14 +85,21 @@ public class BaseController { } public WxMaService getWeappService(String appId) { - WxAppinfo appinfo = wxAppinfoService.getByAppId(appId); - WxMaService service = MaUtil.getWeappService(appinfo); - return service; + if(isFmOpen) { + return openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); + } else { + WxAppinfo appinfo = wxAppinfoService.getByAppId(appId); + WxMaService service = MaUtil.getWeappService(appinfo); + return service; + } } public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { - WxMaService service = MaUtil.getWeappService(appinfo); - return service; + if(!isFmOpen) { + WxMaService service = MaUtil.getWeappService(appinfo); + return service; + } + return null; } public String getIpAddr() { diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxInfoController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxInfoController.java index 967a11f78..b553347b6 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxInfoController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxInfoController.java @@ -41,6 +41,9 @@ import java.util.Map; public class WxInfoController extends BaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + @Autowired + private boolean isFmOpen; + @Autowired WxAppinfoService wxAppinfoService; @@ -115,28 +118,14 @@ public class WxInfoController extends BaseController { private Map getOpenIdInfo(String appId, String code) { WxAppinfo wxAppinfo = getAppInfo(appId); - WxMaService wxMaService = getWeappServiceByAppInfo(wxAppinfo); - - if(StringUtils.isBlank(wxAppinfo.getAccessToken())) { - // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 - try { - String accessToken = wxMaService.getAccessToken(true); - wxAppinfo.setAccessToken(accessToken); - wxAppinfo.setLastTokenTime(new Date()); - wxAppinfo.setExpiresIn(7200); - wxAppinfoService.saveOrUpdate(wxAppinfo); - } catch (WxErrorException e) { - logger.error(e.getMessage()); - } catch (Exception e) { - logger.error(e.getMessage()); - } - - wxMaService = getWeappServiceByAppInfo(wxAppinfo); + WxMaService wxMaService = null; + if(isFmOpen) { + wxMaService = getWeappService(appId); } else { - // 检查token是否已过期, 小时就重新获取 - Date curDate = new Date(); - if(curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.C_EXPIRE) { + wxMaService = getWeappServiceByAppInfo(wxAppinfo); + if(StringUtils.isBlank(wxAppinfo.getAccessToken())) { + // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 try { String accessToken = wxMaService.getAccessToken(true); wxAppinfo.setAccessToken(accessToken); @@ -148,7 +137,26 @@ public class WxInfoController extends BaseController { } catch (Exception e) { logger.error(e.getMessage()); } + wxMaService = getWeappServiceByAppInfo(wxAppinfo); + + } else { + // 检查token是否已过期, 小时就重新获取 + Date curDate = new Date(); + if(curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.C_EXPIRE) { + try { + String accessToken = wxMaService.getAccessToken(true); + wxAppinfo.setAccessToken(accessToken); + wxAppinfo.setLastTokenTime(new Date()); + wxAppinfo.setExpiresIn(7200); + wxAppinfoService.saveOrUpdate(wxAppinfo); + } catch (WxErrorException e) { + logger.error(e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + } + wxMaService = getWeappServiceByAppInfo(wxAppinfo); + } } } diff --git a/mallinkBApi/src/main/resources/application-dev.yml b/mallinkBApi/src/main/resources/application-dev.yml index d43000b27..57b7e3746 100644 --- a/mallinkBApi/src/main/resources/application-dev.yml +++ b/mallinkBApi/src/main/resources/application-dev.yml @@ -23,7 +23,6 @@ spring: maxOpenPreparedStatements: 20 #jackson: #date-format: yyyy-MM-dd HH:mm:ss - # REDIS redis: host: 202.165.179.86 @@ -63,8 +62,31 @@ jasypt: encryptor: password: oRqdnDbK5pj3eMmB +wechat: + open: + componentAppId: "wx897e4673286c915d" + componentSecret: "cdfdfda65c45689beb6766c4c427eed2" + componentToken: "formall2018" + componentAesKey: "htKq8EjBMPNndfZQK9JiFojFaqFwFpw42VfeWFtx7HN" + redis: + host: 202.165.179.86 + port: 6379 + password: ENC(aYJ3Wr2UWtkORRQjjrWWpz2ZeTISsHOA) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 500 + max-wait: -1 + min-idle: 10 + fm: exception: false + deploy: 1 + open: false logging: level: diff --git a/mallinkBApi/src/main/resources/application-prod.yml b/mallinkBApi/src/main/resources/application-prod.yml index 69cbb6e34..232cbb284 100644 --- a/mallinkBApi/src/main/resources/application-prod.yml +++ b/mallinkBApi/src/main/resources/application-prod.yml @@ -65,8 +65,31 @@ aws: access: ENC(a6SN1sZ1enNL49ypiOXkg/pPPAnZD8H4buQFTTKN08s=) secret: ENC(5P5ff4bTMJUbXVR4ZsM03UHzOKZ4+Zg5Iutcdkyp/Quny/oXg+A4KpfwEyGarlLu3vQMJahGP5M=) +wechat: + open: + componentAppId: ENC(b3JG0MUZgQfz5Zj+DC2ZM1zDeLOiGTmmeokfe2O8kaM=) + componentSecret: ENC(QVyc4BPGdnSjXGs2ivgpDBE1v8wPWHLLRMYI7Vv8uYwC0SiZHQz0QpyyQV/b48Pb) + componentToken: ENC(rkxj0733WxFFDLgA9x01m2s5Fi2L+0PC) + componentAesKey: ENC(EIbJUBpbYOrLb4YQ/HXLQmxlxgAqIp2ZmpnGICC8pu5xiTz3Cqfkbwd2S8raCcK/IvYcX2GmedI=) + redis: + host: 127.0.0.1 + port: 6379 + password: ENC(8gYU47Fu93NUJPhwPCiPbAT+6VFA1YDx1egK4Z0Nl6w=) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 100 + max-wait: -1 + min-idle: 10 + fm: exception: true + deploy: 3 + open: true logging: level: diff --git a/mallinkBApi/src/main/resources/application-test.yml b/mallinkBApi/src/main/resources/application-test.yml index 4141683a9..51ba81bc2 100644 --- a/mallinkBApi/src/main/resources/application-test.yml +++ b/mallinkBApi/src/main/resources/application-test.yml @@ -65,8 +65,31 @@ aws: access: ENC(NCLcmjwKpAWdn/abD17OKIY7yKepVLWzEpqRYUlURCw=) secret: ENC(TRcZqql0Rq5PExlMeH/4WiZ/i02b8FXKmLTBChJmbluTa1uoLS9LrHyNEMrqe1DK+QgOAdvqGBo=) +wechat: + open: + componentAppId: ENC(hnH31XdNzArfMfikKgBFpqQuJUl6rVOPFFcAVyb595o=) + componentSecret: ENC(t/GUVX5L+U7LCwSvZ5WmxAnmTMrc/Uy1nljsrokuzzsBL2j6BEVnrS/n7DCdGc/G) + componentToken: ENC(gUF1m0YgCCI2IY54fX6sGLZVlCswA8tG) + componentAesKey: ENC(TYHcrIkICtfrCfGq4HW6s1b/pHf7OD2uyPN11SzJNB0acqJ/4JVX1nuljo/cAtgMG4O05TImLQc=) + redis: + host: 127.0.0.1 + port: 6379 + password: ENC(QFwqv3NshvvGhFPiP8rwhvbnxk+rFSqhJi8Pw6TogSg=) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 100 + max-wait: -1 + min-idle: 10 + fm: exception: true + deploy: 2 + open: true logging: level: diff --git a/mallinkCApi/src/main/java/com/iformall/CApplication.java b/mallinkCApi/src/main/java/com/iformall/CApplication.java index d2717e841..c3d60da7e 100644 --- a/mallinkCApi/src/main/java/com/iformall/CApplication.java +++ b/mallinkCApi/src/main/java/com/iformall/CApplication.java @@ -21,11 +21,19 @@ public class CApplication { @Value("${fm.exception}") private boolean fmException; + @Value("${fm.open}") + private boolean fmOpen; + @Bean public boolean isFmException() { return fmException; } + @Bean + public boolean isFmOpen() { + return fmOpen; + } + public static void main(String[] args) { SpringApplication.run(CApplication.class, args); diff --git a/mallinkCApi/src/main/java/com/iformall/controller/BaseController.java b/mallinkCApi/src/main/java/com/iformall/controller/BaseController.java index c2a168b7f..bb4a0896f 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/BaseController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/BaseController.java @@ -9,6 +9,7 @@ import com.iformall.exception.MallinkException; import com.iformall.service.WxAppinfoService; import com.iformall.service.WxCUserBasicInfoService; import com.iformall.service.WxCUserService; +import com.iformall.service.wechat.FmOpenService; import com.iformall.utils.Constant; import com.iformall.utils.IPUtil; import com.iformall.utils.MaUtil; @@ -29,12 +30,18 @@ import java.util.List; @RestController public class BaseController { + @Autowired + private boolean isFmOpen; + @Autowired private WxCUserService wxCUserService; @Autowired private WxAppinfoService wxAppinfoService; + @Autowired + private FmOpenService openService; + @Autowired private WxCUserBasicInfoService wxCUserBasicInfoService; @@ -88,17 +95,25 @@ public class BaseController { } public WxMaService getWeappService(String appId) { - WxAppinfo appinfo = wxAppinfoService.getByAppId(appId); - if (appinfo == null) { - return null; + if(isFmOpen) { + return openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); + } else { + WxAppinfo appinfo = wxAppinfoService.getByAppId(appId); + if (appinfo == null) { + return null; + } + WxMaService service = MaUtil.getWeappService(appinfo); + return service; } - WxMaService service = MaUtil.getWeappService(appinfo); - return service; + } public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { - WxMaService service = MaUtil.getWeappService(appinfo); - return service; + if(!isFmOpen) { + WxMaService service = MaUtil.getWeappService(appinfo); + return service; + } + return null; } diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxUserGrantController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxUserGrantController.java index 484832a74..782ce710c 100755 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxUserGrantController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxUserGrantController.java @@ -18,6 +18,7 @@ import com.iformall.enums.EnumAssignTagsTrigger; import com.iformall.enums.EnumLevelConfigDiscountStatus; import com.iformall.enums.EnumScoreType; import com.iformall.service.*; +import com.iformall.service.wechat.FmOpenService; import com.iformall.utils.Constant; import com.iformall.utils.IPUtil; import io.swagger.annotations.Api; @@ -47,6 +48,9 @@ import java.util.Map; public class WxUserGrantController extends BaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + @Autowired + private boolean isFmOpen; + @Autowired private WxCUserTokenService userTokenService; @@ -71,6 +75,9 @@ public class WxUserGrantController extends BaseController { @Autowired WxAppinfoService wxAppinfoService; + @Autowired + private FmOpenService openService; + @Autowired WxMerchantService wxMerchantService; @@ -108,19 +115,25 @@ public class WxUserGrantController extends BaseController { if(wxAppinfo == null) { return new ResultData(ErrorCode.APP_ID_NOT_FOUND); } - WxMaService wxMaService = getWeappServiceByAppInfo(wxAppinfo); + WxMaService wxMaService = null; - if(StringUtils.isBlank(wxAppinfo.getAccessToken())) { - // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 - updateAppAccessToken(wxAppinfo, wxMaService); + if(isFmOpen) { + wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); + } else { wxMaService = getWeappServiceByAppInfo(wxAppinfo); - } else { - // 检查token是否已过期, 1小时就重新获取 - Date curDate = new Date(); - if(curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.C_EXPIRE) { + if(StringUtils.isBlank(wxAppinfo.getAccessToken())) { + // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 updateAppAccessToken(wxAppinfo, wxMaService); wxMaService = getWeappServiceByAppInfo(wxAppinfo); + + } else { + // 检查token是否已过期, 1小时就重新获取 + Date curDate = new Date(); + if(curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.C_EXPIRE) { + updateAppAccessToken(wxAppinfo, wxMaService); + wxMaService = getWeappServiceByAppInfo(wxAppinfo); + } } } diff --git a/mallinkCApi/src/main/resources/application-dev.yml b/mallinkCApi/src/main/resources/application-dev.yml index a412f6cab..e38fa70ce 100644 --- a/mallinkCApi/src/main/resources/application-dev.yml +++ b/mallinkCApi/src/main/resources/application-dev.yml @@ -58,6 +58,26 @@ aws: access: ENC(3gx5ghDFBqGrEhO3Wf8aYmXsnwHO7Cj3HNKJGOeUj0o=) secret: ENC(HVKIJwCJKVXLlUpGlQPwNqJOlnpxn4xYuy91SH0seTSm2uAttIQHvA49fXWWax90v5wloIk0QuU=) +wechat: + open: + componentAppId: "wx897e4673286c915d" + componentSecret: "cdfdfda65c45689beb6766c4c427eed2" + componentToken: "formall2018" + componentAesKey: "htKq8EjBMPNndfZQK9JiFojFaqFwFpw42VfeWFtx7HN" + redis: + host: 202.165.179.86 + port: 6379 + password: ENC(aYJ3Wr2UWtkORRQjjrWWpz2ZeTISsHOA) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 500 + max-wait: -1 + min-idle: 10 jasypt: encryptor: @@ -65,6 +85,8 @@ jasypt: fm: exception: false + deploy: 1 + open: true logging: level: diff --git a/mallinkCApi/src/main/resources/application-prod.yml b/mallinkCApi/src/main/resources/application-prod.yml index ccb70a731..8fed514f7 100644 --- a/mallinkCApi/src/main/resources/application-prod.yml +++ b/mallinkCApi/src/main/resources/application-prod.yml @@ -65,10 +65,31 @@ aws: access: ENC(a6SN1sZ1enNL49ypiOXkg/pPPAnZD8H4buQFTTKN08s=) secret: ENC(5P5ff4bTMJUbXVR4ZsM03UHzOKZ4+Zg5Iutcdkyp/Quny/oXg+A4KpfwEyGarlLu3vQMJahGP5M=) - +wechat: + open: + componentAppId: ENC(b3JG0MUZgQfz5Zj+DC2ZM1zDeLOiGTmmeokfe2O8kaM=) + componentSecret: ENC(QVyc4BPGdnSjXGs2ivgpDBE1v8wPWHLLRMYI7Vv8uYwC0SiZHQz0QpyyQV/b48Pb) + componentToken: ENC(rkxj0733WxFFDLgA9x01m2s5Fi2L+0PC) + componentAesKey: ENC(EIbJUBpbYOrLb4YQ/HXLQmxlxgAqIp2ZmpnGICC8pu5xiTz3Cqfkbwd2S8raCcK/IvYcX2GmedI=) + redis: + host: 127.0.0.1 + port: 6379 + password: ENC(8gYU47Fu93NUJPhwPCiPbAT+6VFA1YDx1egK4Z0Nl6w=) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 100 + max-wait: -1 + min-idle: 10 fm: exception: true + deploy: 3 + open: true logging: level: diff --git a/mallinkCApi/src/main/resources/application-test.yml b/mallinkCApi/src/main/resources/application-test.yml index 9a8511358..c1a7c0ef6 100644 --- a/mallinkCApi/src/main/resources/application-test.yml +++ b/mallinkCApi/src/main/resources/application-test.yml @@ -65,8 +65,31 @@ aws: access: ENC(NCLcmjwKpAWdn/abD17OKIY7yKepVLWzEpqRYUlURCw=) secret: ENC(TRcZqql0Rq5PExlMeH/4WiZ/i02b8FXKmLTBChJmbluTa1uoLS9LrHyNEMrqe1DK+QgOAdvqGBo=) +wechat: + open: + componentAppId: ENC(hnH31XdNzArfMfikKgBFpqQuJUl6rVOPFFcAVyb595o=) + componentSecret: ENC(t/GUVX5L+U7LCwSvZ5WmxAnmTMrc/Uy1nljsrokuzzsBL2j6BEVnrS/n7DCdGc/G) + componentToken: ENC(gUF1m0YgCCI2IY54fX6sGLZVlCswA8tG) + componentAesKey: ENC(TYHcrIkICtfrCfGq4HW6s1b/pHf7OD2uyPN11SzJNB0acqJ/4JVX1nuljo/cAtgMG4O05TImLQc=) + redis: + host: 127.0.0.1 + port: 6379 + password: ENC(QFwqv3NshvvGhFPiP8rwhvbnxk+rFSqhJi8Pw6TogSg=) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 100 + max-wait: -1 + min-idle: 10 + fm: exception: true + deploy: 2 + open: true logging: level: diff --git a/mallinkMQConsumer/src/main/java/com/iformall/ConsumerApplication.java b/mallinkMQConsumer/src/main/java/com/iformall/ConsumerApplication.java index a341691ce..c4eb13fb2 100644 --- a/mallinkMQConsumer/src/main/java/com/iformall/ConsumerApplication.java +++ b/mallinkMQConsumer/src/main/java/com/iformall/ConsumerApplication.java @@ -20,13 +20,21 @@ import tk.mybatis.spring.annotation.MapperScan; @EnableEncryptableProperties public class ConsumerApplication { - @Value("${fm.exception}") - private boolean fmException; + @Value("${fm.exception}") + private boolean fmException; - @Bean - public boolean isFmException() { - return fmException; - } + @Value("${fm.open}") + private boolean fmOpen; + + @Bean + public boolean isFmException() { + return fmException; + } + + @Bean + public boolean isFmOpen() { + return fmOpen; + } public static void main(String[] args) { diff --git a/mallinkMQConsumer/src/main/resources/application-dev.yml b/mallinkMQConsumer/src/main/resources/application-dev.yml index 554af1227..ec10f5a5b 100644 --- a/mallinkMQConsumer/src/main/resources/application-dev.yml +++ b/mallinkMQConsumer/src/main/resources/application-dev.yml @@ -77,6 +77,26 @@ aws: access: ENC(3gx5ghDFBqGrEhO3Wf8aYmXsnwHO7Cj3HNKJGOeUj0o=) secret: ENC(HVKIJwCJKVXLlUpGlQPwNqJOlnpxn4xYuy91SH0seTSm2uAttIQHvA49fXWWax90v5wloIk0QuU=) +wechat: + open: + componentAppId: "wx897e4673286c915d" + componentSecret: "cdfdfda65c45689beb6766c4c427eed2" + componentToken: "formall2018" + componentAesKey: "htKq8EjBMPNndfZQK9JiFojFaqFwFpw42VfeWFtx7HN" + redis: + host: 202.165.179.86 + port: 6379 + password: ENC(aYJ3Wr2UWtkORRQjjrWWpz2ZeTISsHOA) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 500 + max-wait: -1 + min-idle: 10 jasypt: encryptor: @@ -84,6 +104,8 @@ jasypt: fm: exception: false + deploy: 1 + open: false logging: level: diff --git a/mallinkMQConsumer/src/main/resources/application-prod.yml b/mallinkMQConsumer/src/main/resources/application-prod.yml index 2f0b29d9b..5010adb19 100644 --- a/mallinkMQConsumer/src/main/resources/application-prod.yml +++ b/mallinkMQConsumer/src/main/resources/application-prod.yml @@ -66,10 +66,31 @@ aws: access: ENC(a6SN1sZ1enNL49ypiOXkg/pPPAnZD8H4buQFTTKN08s=) secret: ENC(5P5ff4bTMJUbXVR4ZsM03UHzOKZ4+Zg5Iutcdkyp/Quny/oXg+A4KpfwEyGarlLu3vQMJahGP5M=) - +wechat: + open: + componentAppId: ENC(b3JG0MUZgQfz5Zj+DC2ZM1zDeLOiGTmmeokfe2O8kaM=) + componentSecret: ENC(QVyc4BPGdnSjXGs2ivgpDBE1v8wPWHLLRMYI7Vv8uYwC0SiZHQz0QpyyQV/b48Pb) + componentToken: ENC(rkxj0733WxFFDLgA9x01m2s5Fi2L+0PC) + componentAesKey: ENC(EIbJUBpbYOrLb4YQ/HXLQmxlxgAqIp2ZmpnGICC8pu5xiTz3Cqfkbwd2S8raCcK/IvYcX2GmedI=) + redis: + host: 127.0.0.1 + port: 6379 + password: ENC(8gYU47Fu93NUJPhwPCiPbAT+6VFA1YDx1egK4Z0Nl6w=) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 100 + max-wait: -1 + min-idle: 10 fm: exception: true + deploy: 3 + open: true logging: level: diff --git a/mallinkMQConsumer/src/main/resources/application-test.yml b/mallinkMQConsumer/src/main/resources/application-test.yml index f3c9256e4..e1c673b7a 100644 --- a/mallinkMQConsumer/src/main/resources/application-test.yml +++ b/mallinkMQConsumer/src/main/resources/application-test.yml @@ -66,8 +66,31 @@ aws: access: ENC(NCLcmjwKpAWdn/abD17OKIY7yKepVLWzEpqRYUlURCw=) secret: ENC(TRcZqql0Rq5PExlMeH/4WiZ/i02b8FXKmLTBChJmbluTa1uoLS9LrHyNEMrqe1DK+QgOAdvqGBo=) +wechat: + open: + componentAppId: ENC(hnH31XdNzArfMfikKgBFpqQuJUl6rVOPFFcAVyb595o=) + componentSecret: ENC(t/GUVX5L+U7LCwSvZ5WmxAnmTMrc/Uy1nljsrokuzzsBL2j6BEVnrS/n7DCdGc/G) + componentToken: ENC(gUF1m0YgCCI2IY54fX6sGLZVlCswA8tG) + componentAesKey: ENC(TYHcrIkICtfrCfGq4HW6s1b/pHf7OD2uyPN11SzJNB0acqJ/4JVX1nuljo/cAtgMG4O05TImLQc=) + redis: + host: 127.0.0.1 + port: 6379 + password: ENC(QFwqv3NshvvGhFPiP8rwhvbnxk+rFSqhJi8Pw6TogSg=) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 100 + max-wait: -1 + min-idle: 10 + fm: exception: true + deploy: 2 + open: true logging: level: diff --git a/mallinkSchedule/src/main/java/com/iformall/ScheduleApplication.java b/mallinkSchedule/src/main/java/com/iformall/ScheduleApplication.java index b9396d4e2..9ad8515f7 100644 --- a/mallinkSchedule/src/main/java/com/iformall/ScheduleApplication.java +++ b/mallinkSchedule/src/main/java/com/iformall/ScheduleApplication.java @@ -20,13 +20,21 @@ import tk.mybatis.spring.annotation.MapperScan; @EnableEncryptableProperties public class ScheduleApplication { - @Value("${fm.exception}") - private boolean fmException; + @Value("${fm.exception}") + private boolean fmException; - @Bean - public boolean isFmException() { - return fmException; - } + @Value("${fm.open}") + private boolean fmOpen; + + @Bean + public boolean isFmException() { + return fmException; + } + + @Bean + public boolean isFmOpen() { + return fmOpen; + } public static void main(String[] args) { diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/WeChatAccessTokenSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/WeChatAccessTokenSchedule.java index 1692671e1..c54cf27c8 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/WeChatAccessTokenSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/WeChatAccessTokenSchedule.java @@ -19,6 +19,9 @@ public class WeChatAccessTokenSchedule { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + @Autowired + private boolean isFmOpen; + @Autowired WxAppinfoMapper wxAppinfoMapper; @@ -27,12 +30,14 @@ public class WeChatAccessTokenSchedule { public void getAccessTokens() { logger.info("微信访问AccessToken获取定时任务启动"); + if(!isFmOpen) { - WxAppinfo appinfoQ = new WxAppinfo(); - List appList = wxAppinfoMapper.findList(appinfoQ); + WxAppinfo appinfoQ = new WxAppinfo(); + List appList = wxAppinfoMapper.findList(appinfoQ); - for (WxAppinfo appinfo : appList) { - resetAccessToken(appinfo); + for (WxAppinfo appinfo : appList) { + resetAccessToken(appinfo); + } } logger.info("微信访问AccessToken获取定时任务结束"); diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/WxAppVisitSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/WxAppVisitSchedule.java index 7c4f1a442..a8bd3762a 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/WxAppVisitSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/WxAppVisitSchedule.java @@ -5,6 +5,7 @@ import java.util.*; import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitTrend; +import com.iformall.service.wechat.FmOpenService; import com.iformall.utils.MaUtil; import me.chanjar.weixin.common.error.WxErrorException; import org.apache.commons.lang3.StringUtils; @@ -24,12 +25,18 @@ import com.iformall.service.WxUserVisitService; @Component public class WxAppVisitSchedule { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private boolean isFmOpen; - @Autowired - private WxUserVisitService wxUserVisitService; + @Autowired + private WxUserVisitService wxUserVisitService; - @Autowired - private WxAppinfoService WxAppinfoService; + @Autowired + private WxAppinfoService WxAppinfoService; + + @Autowired + private FmOpenService openService; @Scheduled(cron = "0 0 9 * * ? ") //早晨9点做一次,获取前一日,微信时间为GMT @@ -96,7 +103,12 @@ public class WxAppVisitSchedule { } private void getData(Date lastDate,WxAppinfo appInfo) throws Exception { - WxMaService wxMaService = MaUtil.getWeappService(appInfo); + WxMaService wxMaService = null; + if(isFmOpen) { + wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appInfo.getAppId()); + } else { + wxMaService = MaUtil.getWeappService(appInfo); + } try { List vtList = wxMaService.getAnalysisService().getDailyVisitTrend(lastDate, lastDate); logger.info(vtList.toString()); diff --git a/mallinkSchedule/src/main/resources/application-dev.yml b/mallinkSchedule/src/main/resources/application-dev.yml index fd0290da1..604233da8 100644 --- a/mallinkSchedule/src/main/resources/application-dev.yml +++ b/mallinkSchedule/src/main/resources/application-dev.yml @@ -60,6 +60,26 @@ aws: access: ENC(3gx5ghDFBqGrEhO3Wf8aYmXsnwHO7Cj3HNKJGOeUj0o=) secret: ENC(HVKIJwCJKVXLlUpGlQPwNqJOlnpxn4xYuy91SH0seTSm2uAttIQHvA49fXWWax90v5wloIk0QuU=) +wechat: + open: + componentAppId: "wx897e4673286c915d" + componentSecret: "cdfdfda65c45689beb6766c4c427eed2" + componentToken: "formall2018" + componentAesKey: "htKq8EjBMPNndfZQK9JiFojFaqFwFpw42VfeWFtx7HN" + redis: + host: 202.165.179.86 + port: 6379 + password: ENC(aYJ3Wr2UWtkORRQjjrWWpz2ZeTISsHOA) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 500 + max-wait: -1 + min-idle: 10 jasypt: encryptor: @@ -67,6 +87,8 @@ jasypt: fm: exception: false + deploy: 1 + open: false logging: level: diff --git a/mallinkSchedule/src/main/resources/application-prod.yml b/mallinkSchedule/src/main/resources/application-prod.yml index 65fa94c2b..4bec7fa2c 100644 --- a/mallinkSchedule/src/main/resources/application-prod.yml +++ b/mallinkSchedule/src/main/resources/application-prod.yml @@ -66,10 +66,31 @@ aws: access: ENC(a6SN1sZ1enNL49ypiOXkg/pPPAnZD8H4buQFTTKN08s=) secret: ENC(5P5ff4bTMJUbXVR4ZsM03UHzOKZ4+Zg5Iutcdkyp/Quny/oXg+A4KpfwEyGarlLu3vQMJahGP5M=) - +wechat: + open: + componentAppId: ENC(b3JG0MUZgQfz5Zj+DC2ZM1zDeLOiGTmmeokfe2O8kaM=) + componentSecret: ENC(QVyc4BPGdnSjXGs2ivgpDBE1v8wPWHLLRMYI7Vv8uYwC0SiZHQz0QpyyQV/b48Pb) + componentToken: ENC(rkxj0733WxFFDLgA9x01m2s5Fi2L+0PC) + componentAesKey: ENC(EIbJUBpbYOrLb4YQ/HXLQmxlxgAqIp2ZmpnGICC8pu5xiTz3Cqfkbwd2S8raCcK/IvYcX2GmedI=) + redis: + host: 127.0.0.1 + port: 6379 + password: ENC(8gYU47Fu93NUJPhwPCiPbAT+6VFA1YDx1egK4Z0Nl6w=) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 100 + max-wait: -1 + min-idle: 10 fm: exception: true + deploy: 3 + open: true logging: level: diff --git a/mallinkSchedule/src/main/resources/application-test.yml b/mallinkSchedule/src/main/resources/application-test.yml index 4965fb3df..4b3f13e67 100644 --- a/mallinkSchedule/src/main/resources/application-test.yml +++ b/mallinkSchedule/src/main/resources/application-test.yml @@ -66,8 +66,31 @@ aws: access: ENC(NCLcmjwKpAWdn/abD17OKIY7yKepVLWzEpqRYUlURCw=) secret: ENC(TRcZqql0Rq5PExlMeH/4WiZ/i02b8FXKmLTBChJmbluTa1uoLS9LrHyNEMrqe1DK+QgOAdvqGBo=) +wechat: + open: + componentAppId: ENC(hnH31XdNzArfMfikKgBFpqQuJUl6rVOPFFcAVyb595o=) + componentSecret: ENC(t/GUVX5L+U7LCwSvZ5WmxAnmTMrc/Uy1nljsrokuzzsBL2j6BEVnrS/n7DCdGc/G) + componentToken: ENC(gUF1m0YgCCI2IY54fX6sGLZVlCswA8tG) + componentAesKey: ENC(TYHcrIkICtfrCfGq4HW6s1b/pHf7OD2uyPN11SzJNB0acqJ/4JVX1nuljo/cAtgMG4O05TImLQc=) + redis: + host: 127.0.0.1 + port: 6379 + password: ENC(QFwqv3NshvvGhFPiP8rwhvbnxk+rFSqhJi8Pw6TogSg=) + timeout: 3600 + expire: 1800 #30分钟 + database: 2 + defaultExpiration: 2592000 # 默认生命周期30天 + jedis: + pool: + max-active: 100 + max-idle: 100 + max-wait: -1 + min-idle: 10 + fm: exception: true + deploy: 2 + open: true logging: level: diff --git a/mallinkService/src/main/java/com/iformall/config/WechatOpenProperties.java b/mallinkService/src/main/java/com/iformall/config/WechatOpenProperties.java new file mode 100644 index 000000000..e19dfc4eb --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/config/WechatOpenProperties.java @@ -0,0 +1,69 @@ +package com.iformall.config; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Stormeye + */ +@ConfigurationProperties(prefix = "wechat.open") +public class WechatOpenProperties { + /** + * 设置微信三方平台的appid + */ + private String componentAppId; + + /** + * 设置微信三方平台的app secret + */ + private String componentSecret; + + /** + * 设置微信三方平台的token + */ + private String componentToken; + + /** + * 设置微信三方平台的EncodingAESKey + */ + private String componentAesKey; + + public String getComponentAppId() { + return componentAppId; + } + + public void setComponentAppId(String componentAppId) { + this.componentAppId = componentAppId; + } + + public String getComponentSecret() { + return componentSecret; + } + + public void setComponentSecret(String componentSecret) { + this.componentSecret = componentSecret; + } + + public String getComponentToken() { + return componentToken; + } + + public void setComponentToken(String componentToken) { + this.componentToken = componentToken; + } + + public String getComponentAesKey() { + return componentAesKey; + } + + public void setComponentAesKey(String componentAesKey) { + this.componentAesKey = componentAesKey; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, + ToStringStyle.MULTI_LINE_STYLE); + } +} diff --git a/mallinkService/src/main/java/com/iformall/config/WechatRedisProperies.java b/mallinkService/src/main/java/com/iformall/config/WechatRedisProperies.java new file mode 100644 index 000000000..1a84a3482 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/config/WechatRedisProperies.java @@ -0,0 +1,124 @@ +package com.iformall.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import redis.clients.jedis.JedisPoolConfig; +import redis.clients.jedis.Protocol; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLParameters; +import javax.net.ssl.SSLSocketFactory; + +/** + * Stormeye + */ +@ConfigurationProperties(prefix = "wechat.redis") +public class WechatRedisProperies extends JedisPoolConfig { + private String host = Protocol.DEFAULT_HOST; + private int port = Protocol.DEFAULT_PORT; + private String password; + private int database = 1; + private int connectionTimeout = Protocol.DEFAULT_TIMEOUT; + private int soTimeout = Protocol.DEFAULT_TIMEOUT; + private String clientName; + private boolean ssl; + private SSLSocketFactory sslSocketFactory; + private SSLParameters sslParameters; + private HostnameVerifier hostnameVerifier; + + public boolean isSsl() { + return ssl; + } + + public void setSsl(boolean ssl) { + this.ssl = ssl; + } + + public SSLSocketFactory getSslSocketFactory() { + return sslSocketFactory; + } + + public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) { + this.sslSocketFactory = sslSocketFactory; + } + + public SSLParameters getSslParameters() { + return sslParameters; + } + + public void setSslParameters(SSLParameters sslParameters) { + this.sslParameters = sslParameters; + } + + public HostnameVerifier getHostnameVerifier() { + return hostnameVerifier; + } + + public void setHostnameVerifier(HostnameVerifier hostnameVerifier) { + this.hostnameVerifier = hostnameVerifier; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + if (host == null || "".equals(host)) { + host = Protocol.DEFAULT_HOST; + } + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + if ("".equals(password)) { + password = null; + } + this.password = password; + } + + public int getDatabase() { + return database; + } + + public void setDatabase(int database) { + this.database = database; + } + + public String getClientName() { + return clientName; + } + + public void setClientName(String clientName) { + if ("".equals(clientName)) { + clientName = null; + } + this.clientName = clientName; + } + + public int getConnectionTimeout() { + return connectionTimeout; + } + + public void setConnectionTimeout(int connectionTimeout) { + this.connectionTimeout = connectionTimeout; + } + + public int getSoTimeout() { + return soTimeout; + } + + public void setSoTimeout(int soTimeout) { + this.soTimeout = soTimeout; + } +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxAuthorizerInfoMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxAuthorizerInfoMapper.java index ddd61732d..51df5195e 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxAuthorizerInfoMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxAuthorizerInfoMapper.java @@ -9,9 +9,19 @@ public interface WxAuthorizerInfoMapper extends CommonMapper findList(WxAuthorizerInfo wxAuthorizerInfo); + List findWeappList(); + + List findWxMpList(); + List findVoList(WxWeappInfo wxWeappInfo); - void updateReleaseInfo(WxAuthorizerInfo wxAuthorizerInfo); + WxWeappInfo findVo(WxWeappInfo wxWeappInfo); + + int updateReleaseInfo(WxAuthorizerInfo wxAuthorizerInfo); + + int updateRefreshToken(WxAuthorizerInfo wxAuthorizerInfo); + + int updateAccessToken(WxAuthorizerInfo wxAuthorizerInfo); diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxComponentVerifyTicketMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxComponentVerifyTicketMapper.java index 72d6514de..db9f2055f 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxComponentVerifyTicketMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxComponentVerifyTicketMapper.java @@ -7,10 +7,8 @@ import com.iformall.domain.po.WxComponentVerifyTicket; public interface WxComponentVerifyTicketMapper extends CommonMapper { List findList(WxComponentVerifyTicket wxComponentVerifyTicket); - - - - + int updateAccessToken(WxComponentVerifyTicket wxComponentVerifyTicket); + } diff --git a/mallinkService/src/main/java/com/iformall/service/WxAppinfoService.java b/mallinkService/src/main/java/com/iformall/service/WxAppinfoService.java index de26477ef..1ee68a763 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxAppinfoService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxAppinfoService.java @@ -63,13 +63,6 @@ public interface WxAppinfoService { */ void deleteById(Long id); - - /** - * 更新accessToken - * @param appId - */ - void ctokenUpdate(String appId); - /** * 位置码/导购码生成 */ diff --git a/mallinkService/src/main/java/com/iformall/service/impl/SendSmartAppMsgServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/SendSmartAppMsgServiceImpl.java index 6c22ef120..4c5a02b41 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/SendSmartAppMsgServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/SendSmartAppMsgServiceImpl.java @@ -8,6 +8,7 @@ import com.iformall.exception.MallinkException; import com.iformall.mapper.WxTemplateMsgMapper; import com.iformall.service.MsgSendService; import com.iformall.service.WxAppinfoService; +import com.iformall.service.wechat.FmOpenService; import com.iformall.utils.MaUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,18 +25,28 @@ import java.util.List; public class SendSmartAppMsgServiceImpl implements MsgSendService { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired + private boolean isFmOpen; + @Autowired private WxTemplateMsgMapper wxTemplateMsgMapper; @Autowired private WxAppinfoService wxAppinfoService; + @Autowired + private FmOpenService openService; + @Override public void send(BaseMsg baseMsg) throws Exception{ SmartAppMsg smartAppMsg = (SmartAppMsg)baseMsg; WxTemplateMsg msg = null; WxMaTemplateMessage templateMessage; - WxAppinfo appInfo = wxAppinfoService.getByAppId(smartAppMsg.getAppId()); - WxMaService wxMaService = MaUtil.getWeappService(appInfo); + WxMaService wxMaService = null; + if(isFmOpen) { + wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(smartAppMsg.getAppId()); + } else { + WxAppinfo appInfo = wxAppinfoService.getByAppId(smartAppMsg.getAppId()); + wxMaService = MaUtil.getWeappService(appInfo); + } //查询信息模板 WxTemplateMsg msgQ = new WxTemplateMsg(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java index ea0e7b226..cd231cafb 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java @@ -87,43 +87,6 @@ public class WxAppinfoServiceImpl implements WxAppinfoService { wxAppinfoMapper.deleteByPrimaryKey(id); } - - /** - * 租户c端小程序更新token - * @param tenantId - */ - @Override - public void ctokenUpdate(String tenantId) { - WxAppinfo appQ = new WxAppinfo(); - appQ.setTenantId(tenantId); - appQ.setType(EnumAppType.C.getCode()); - List appList = wxAppinfoMapper.findList(appQ); - if (appList.size() <= 0) { - return; - } - WxAppinfo appinfo = appList.get(0); - if(appinfo == null) { - return; - } - // get access_token - WxMaService wxMaService = MaUtil.getWeappService(appinfo); - if(wxMaService == null) { - return; - } - - String access_token = ""; - try{ - access_token = wxMaService.getAccessToken(); - } catch (Exception e) { - logger.error(e.getMessage()); - } - Date date = new Date(); - // update db - appinfo.setAccessToken(access_token); - appinfo.setLastTokenTime(date); - wxAppinfoMapper.updateByPrimaryKeySelective(appinfo); - } - private void downFile(String filePath, String filename, HttpServletResponse response, HttpServletRequest req) throws IOException { try { response.reset(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java index dda1a7aa3..c70dd7076 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java @@ -13,13 +13,13 @@ import com.iformall.domain.po.WxCouponChannel; import com.iformall.domain.po.WxScreenAd; import com.iformall.domain.vo.WxCouponCVo; import com.iformall.enums.EnumCouponChannelType; -import com.iformall.enums.EnumCouponType; import com.iformall.enums.EnumScreenAdType; import com.iformall.mapper.WxCampaignMapper; import com.iformall.mapper.WxCouponChannelMapper; import com.iformall.mapper.WxScreenAdMapper; import com.iformall.service.WxAppinfoService; import com.iformall.service.WxScreenAdService; +import com.iformall.service.wechat.FmOpenService; import com.iformall.utils.MaUtil; import me.chanjar.weixin.common.error.WxErrorException; import org.slf4j.Logger; @@ -33,6 +33,9 @@ import java.util.List; @Service public class WxScreenAdServiceImpl implements WxScreenAdService { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private boolean isFmOpen; @Autowired WxScreenAdMapper wxScreenAdMapper; @@ -40,6 +43,9 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { @Autowired WxAppinfoService wxAppinfoService; + @Autowired + private FmOpenService openService; + @Autowired WxCouponChannelMapper wxCouponChannelMapper; @@ -162,12 +168,18 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { private static String QRCODE_JUMP_CMD_COUPON = "JC"; private static String QRCODE_JUMP_CMD_GROUP = "JG"; private static String QRCODE_JUMP_CMD_CAMPGIN = "JB"; + private byte[] getQrcode(Long id, int type, int subType, WxAppinfo appInfo) throws Exception { if(appInfo == null) { logger.error("QRCODE get error: appinfo is null"); return null; } - WxMaService wxMaService = MaUtil.getWeappService(appInfo); + WxMaService wxMaService = null; + if(isFmOpen) { + wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appInfo.getAppId()); + } else { + wxMaService = MaUtil.getWeappService(appInfo); + } String scene = ""; if (EnumScreenAdType.COUPON.getCode().equals(type)) { diff --git a/mallinkService/src/main/java/com/iformall/service/wechat/FmOpenInRedisDBConfigStorage.java b/mallinkService/src/main/java/com/iformall/service/wechat/FmOpenInRedisDBConfigStorage.java new file mode 100644 index 000000000..979bb609a --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/wechat/FmOpenInRedisDBConfigStorage.java @@ -0,0 +1,253 @@ +package com.iformall.service.wechat; + +import com.iformall.common.MipHttpClientBuilder; +import com.iformall.domain.po.WxAuthorizerInfo; +import com.iformall.domain.po.WxComponentVerifyTicket; +import com.iformall.mapper.WxAuthorizerInfoMapper; +import com.iformall.mapper.WxComponentVerifyTicketMapper; +import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; +import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage; +import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.util.Pool; + +import java.util.Date; + +public class FmOpenInRedisDBConfigStorage extends WxOpenInMemoryConfigStorage { + private final static String COMPONENT_VERIFY_TICKET_KEY = "wechat_component_verify_ticket:"; + private final static String COMPONENT_ACCESS_TOKEN_KEY = "wechat_component_access_token:"; + + private final static String AUTHORIZER_REFRESH_TOKEN_KEY = "wechat_authorizer_refresh_token:"; + private final static String AUTHORIZER_ACCESS_TOKEN_KEY = "wechat_authorizer_access_token:"; + private final static String JSAPI_TICKET_KEY = "wechat_jsapi_ticket:"; + private final static String CARD_API_TICKET_KEY = "wechat_card_api_ticket:"; + + protected final Pool jedisPool; + private WxComponentVerifyTicketMapper wxComponentVerifyTicketMapper; + private WxAuthorizerInfoMapper wxAuthorizerInfoMapper; + + + /** + * redis 存储的 key 的前缀,可为空 + */ + private String keyPrefix; + private String componentVerifyTicketKey; + private String componentAccessTokenKey; + private String authorizerRefreshTokenKey; + private String authorizerAccessTokenKey; + private String jsapiTicketKey; + private String cardApiTicket; + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + + public FmOpenInRedisDBConfigStorage(Pool jedisPool) { + this.jedisPool = jedisPool; + } + + public FmOpenInRedisDBConfigStorage(Pool jedisPool, String keyPrefix) { + this.jedisPool = jedisPool; + this.keyPrefix = keyPrefix; + } + + public FmOpenInRedisDBConfigStorage(JedisPool jedisPool, WxComponentVerifyTicketMapper componentVerifyTicketMapper, WxAuthorizerInfoMapper authorizerInfoMapper) { + this.jedisPool = jedisPool; + this.wxComponentVerifyTicketMapper = componentVerifyTicketMapper; + this.wxAuthorizerInfoMapper = authorizerInfoMapper; + } + + @Override + public void setComponentAppId(String componentAppId) { + super.setComponentAppId(componentAppId); + String prefix = StringUtils.isBlank(keyPrefix) ? "" : + (StringUtils.endsWith(keyPrefix, ":") ? keyPrefix : (keyPrefix + ":")); + componentVerifyTicketKey = prefix + COMPONENT_VERIFY_TICKET_KEY.concat(componentAppId); + componentAccessTokenKey = prefix + COMPONENT_ACCESS_TOKEN_KEY.concat(componentAppId); + authorizerRefreshTokenKey = prefix + AUTHORIZER_REFRESH_TOKEN_KEY.concat(componentAppId); + authorizerAccessTokenKey = prefix + AUTHORIZER_ACCESS_TOKEN_KEY.concat(componentAppId); + this.jsapiTicketKey = JSAPI_TICKET_KEY.concat(componentAppId); + this.cardApiTicket = CARD_API_TICKET_KEY.concat(componentAppId); + } + + @Override + public String getComponentVerifyTicket() { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(this.componentVerifyTicketKey); + } + } + + @Override + public void setComponentVerifyTicket(String componentVerifyTicket) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.set(this.componentVerifyTicketKey, componentVerifyTicket); + } + } + + @Override + public String getComponentAccessToken() { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(this.componentAccessTokenKey); + } + } + + @Override + public boolean isComponentAccessTokenExpired() { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.ttl(this.componentAccessTokenKey) < 2; + } + } + + @Override + public void expireComponentAccessToken(){ + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.expire(this.componentAccessTokenKey, 0); + } + } + + @Override + public void updateComponentAccessTokent(String componentAccessToken, int expiresInSeconds) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.setex(this.componentAccessTokenKey, expiresInSeconds - 200, componentAccessToken); + + WxComponentVerifyTicket ticket = new WxComponentVerifyTicket(); + ticket.setComponentAppid(getComponentAppId()); + ticket.setAccessToken(componentAccessToken); + ticket.setAccessTokenExpire(new Date(Long.valueOf(System.currentTimeMillis() + (expiresInSeconds * 1000)))); + int num = wxComponentVerifyTicketMapper.updateAccessToken(ticket); + logger.info("updateComponentVerifyTicketAccessToken rows: " + num); + } + } + + private String getKey(String prefix, String appId) { + return prefix.endsWith(":") ? prefix.concat(appId) : prefix.concat(":").concat(appId); + } + + @Override + public String getAuthorizerRefreshToken(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(this.getKey(this.authorizerRefreshTokenKey, appId)); + } + } + + @Override + public void setAuthorizerRefreshToken(String appId, String authorizerRefreshToken) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.set(this.getKey(this.authorizerRefreshTokenKey, appId), authorizerRefreshToken); + + WxAuthorizerInfo authorizerInfo = new WxAuthorizerInfo(); + authorizerInfo.setAuthorizerAppid(appId); + authorizerInfo.setRefreshToken(authorizerRefreshToken); + int num = wxAuthorizerInfoMapper.updateRefreshToken(authorizerInfo); + logger.info("setAuthorizerRefreshToken " + appId + " rows: " + num); + } + } + + @Override + public String getAuthorizerAccessToken(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(this.getKey(this.authorizerAccessTokenKey, appId)); + } + } + + @Override + public boolean isAuthorizerAccessTokenExpired(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.ttl(this.getKey(this.authorizerAccessTokenKey, appId)) < 2; + } + } + + @Override + public void expireAuthorizerAccessToken(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.expire(this.getKey(this.authorizerAccessTokenKey, appId), 0); + } + } + + @Override + public void updateAuthorizerAccessToken(String appId, WxOpenAuthorizerAccessToken authorizerAccessToken) { + this.updateAuthorizerAccessToken(appId, authorizerAccessToken.getAuthorizerAccessToken(), authorizerAccessToken.getExpiresIn()); + + WxAuthorizerInfo authorizerInfo = new WxAuthorizerInfo(); + authorizerInfo.setAuthorizerAppid(appId); + authorizerInfo.setAccessToken(authorizerAccessToken.getAuthorizerAccessToken()); + authorizerInfo.setAccessTokenExpire(new Date(Long.valueOf(System.currentTimeMillis() + (authorizerAccessToken.getExpiresIn() * 1000)))); + int num = wxAuthorizerInfoMapper.updateAccessToken(authorizerInfo); + logger.info("updateAuthorizerAccessToken " + appId + " rows: " + num); + } + + @Override + public void updateAuthorizerAccessToken(String appId, String authorizerAccessToken, int expiresInSeconds) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.setex(this.getKey(this.authorizerAccessTokenKey, appId), expiresInSeconds - 200, authorizerAccessToken); + } + } + + @Override + public String getJsapiTicket(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(this.getKey(this.jsapiTicketKey, appId)); + } + } + + @Override + public boolean isJsapiTicketExpired(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.ttl(this.getKey(this.jsapiTicketKey, appId)) < 2; + } + } + + @Override + public void expireJsapiTicket(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.expire(this.getKey(this.jsapiTicketKey, appId), 0); + } + } + + @Override + public void updateJsapiTicket(String appId, String jsapiTicket, int expiresInSeconds) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.setex(this.getKey(this.jsapiTicketKey, appId), expiresInSeconds - 200, jsapiTicket); + } + + // TODO update to DB + } + + @Override + public String getCardApiTicket(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.get(this.getKey(this.cardApiTicket, appId)); + } + } + + @Override + public boolean isCardApiTicketExpired(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + return jedis.ttl(this.getKey(this.cardApiTicket, appId)) < 2; + } + } + + @Override + public void expireCardApiTicket(String appId) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.expire(this.getKey(this.cardApiTicket, appId), 0); + } + } + + @Override + public void updateCardApiTicket(String appId, String cardApiTicket, int expiresInSeconds) { + try (Jedis jedis = this.jedisPool.getResource()) { + jedis.setex(this.getKey(this.cardApiTicket, appId), expiresInSeconds - 200, cardApiTicket); + } + + // TODO update to DB + } + + @Override + public ApacheHttpClientBuilder getApacheHttpClientBuilder() { + return MipHttpClientBuilder.get(); + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/wechat/FmOpenService.java b/mallinkService/src/main/java/com/iformall/service/wechat/FmOpenService.java new file mode 100644 index 000000000..d267024a1 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/wechat/FmOpenService.java @@ -0,0 +1,73 @@ +package com.iformall.service.wechat; + +import com.iformall.config.WechatOpenProperties; +import com.iformall.config.WechatRedisProperies; +import com.iformall.mapper.WxAuthorizerInfoMapper; +import com.iformall.mapper.WxComponentVerifyTicketMapper; +import me.chanjar.weixin.open.api.impl.WxOpenMessageRouter; +import me.chanjar.weixin.open.api.impl.WxOpenServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.stereotype.Service; +import redis.clients.jedis.JedisPool; + +import javax.annotation.PostConstruct; + +/** + * Stormeye WU + */ +@Service +@EnableConfigurationProperties({WechatOpenProperties.class, WechatRedisProperies.class}) +public class FmOpenService extends WxOpenServiceImpl { + private Logger logger = LoggerFactory.getLogger(getClass()); + @Autowired + private WechatOpenProperties wechatProperties; + @Autowired + private WechatRedisProperies redisProperies; + + @Autowired + private WxComponentVerifyTicketMapper componentVerifyTicketMapper; + + @Autowired + private WxAuthorizerInfoMapper authorizerInfoMapper; + + private static JedisPool pool; + private WxOpenMessageRouter wxOpenMessageRouter; + + @PostConstruct + public void init() { + FmOpenInRedisDBConfigStorage configStorage = new FmOpenInRedisDBConfigStorage(getJedisPool(), componentVerifyTicketMapper, authorizerInfoMapper); + configStorage.setComponentAppId(wechatProperties.getComponentAppId()); + configStorage.setComponentAppSecret(wechatProperties.getComponentSecret()); + configStorage.setComponentToken(wechatProperties.getComponentToken()); + configStorage.setComponentAesKey(wechatProperties.getComponentAesKey()); + setWxOpenConfigStorage(configStorage); + wxOpenMessageRouter = new WxOpenMessageRouter(this); + wxOpenMessageRouter.rule().handler((wxMpXmlMessage, map, wxMpService, wxSessionManager) -> { + logger.info("\n接收到 {} 公众号请求消息,内容:{}", wxMpService.getWxMpConfigStorage().getAppId(), wxMpXmlMessage); + return null; + }).next(); + } + + public WxOpenMessageRouter getWxOpenMessageRouter() { + return wxOpenMessageRouter; + } + + private JedisPool getJedisPool() { + if (pool == null) { + synchronized (FmOpenService.class) { + if (pool == null) { + pool = new JedisPool(redisProperies, redisProperies.getHost(), + redisProperies.getPort(), redisProperies.getConnectionTimeout(), + redisProperies.getSoTimeout(), redisProperies.getPassword(), + redisProperies.getDatabase(), redisProperies.getClientName(), + redisProperies.isSsl(), redisProperies.getSslSocketFactory(), + redisProperies.getSslParameters(), redisProperies.getHostnameVerifier()); + } + } + } + return pool; + } +} diff --git a/mallinkService/src/main/resources/mapper/WxAuthorizerInfoMapper.xml b/mallinkService/src/main/resources/mapper/WxAuthorizerInfoMapper.xml index f2c6efed2..13e351fe9 100644 --- a/mallinkService/src/main/resources/mapper/WxAuthorizerInfoMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxAuthorizerInfoMapper.xml @@ -246,6 +246,14 @@ + +