yshop2.0.1微信公众号与支付配置新增redis标识解决必须api模块必须重启配置才能生效的问题
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
package co.yixiang.mp.config;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.constant.ShopConstants;
|
||||
import co.yixiang.mp.handler.*;
|
||||
import co.yixiang.utils.RedisUtil;
|
||||
import com.google.common.collect.Maps;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
|
||||
@ -65,16 +67,20 @@ public class WxMpConfiguration {
|
||||
public static WxMpService getWxMpService() {
|
||||
|
||||
WxMpService wxMpService = mpServices.get(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
|
||||
if(wxMpService == null) {
|
||||
//增加一个redis标识
|
||||
if(wxMpService == null || RedisUtil.get(ShopConstants.YSHOP_WEIXIN_MP_SERVICE) == null) {
|
||||
WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
|
||||
configStorage.setAppId(redisHandler.getVal("wechat_appid"));
|
||||
configStorage.setSecret(redisHandler.getVal("wechat_appsecret"));
|
||||
configStorage.setToken(redisHandler.getVal("wechat_token"));
|
||||
configStorage.setAesKey(redisHandler.getVal("wechat_encodingaeskey"));
|
||||
configStorage.setAppId(RedisUtil.get("wechat_appid"));
|
||||
configStorage.setSecret(RedisUtil.get("wechat_appsecret"));
|
||||
configStorage.setToken(RedisUtil.get("wechat_token"));
|
||||
configStorage.setAesKey(RedisUtil.get("wechat_encodingaeskey"));
|
||||
wxMpService = new WxMpServiceImpl();
|
||||
wxMpService.setWxMpConfigStorage(configStorage);
|
||||
mpServices.put(ShopConstants.YSHOP_WEIXIN_MP_SERVICE, wxMpService);
|
||||
routers.put(ShopConstants.YSHOP_WEIXIN_MP_SERVICE, newRouter(wxMpService));
|
||||
|
||||
//增加标识
|
||||
RedisUtil.set(ShopConstants.YSHOP_WEIXIN_MP_SERVICE,"yshop");
|
||||
}
|
||||
return wxMpService;
|
||||
}
|
||||
@ -83,6 +89,7 @@ public class WxMpConfiguration {
|
||||
* 移除WxMpService
|
||||
*/
|
||||
public static void removeWxMpService(){
|
||||
RedisUtil.del(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
|
||||
mpServices.remove(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
|
||||
routers.remove(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package co.yixiang.mp.config;
|
||||
|
||||
import co.yixiang.constant.ShopConstants;
|
||||
import co.yixiang.mp.handler.RedisHandler;
|
||||
import co.yixiang.utils.RedisUtil;
|
||||
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||
@ -36,19 +37,20 @@ public class WxPayConfiguration {
|
||||
*/
|
||||
public static WxPayService getPayService() {
|
||||
WxPayService wxPayService = payServices.get(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE);
|
||||
if(wxPayService == null) {
|
||||
if(wxPayService == null || RedisUtil.get(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE) == null) {
|
||||
WxPayConfig payConfig = new WxPayConfig();
|
||||
payConfig.setAppId(redisHandler.getVal("wxpay_appId"));
|
||||
payConfig.setMchId(redisHandler.getVal("wxpay_mchId"));
|
||||
payConfig.setMchKey(redisHandler.getVal("wxpay_mchKey"));
|
||||
payConfig.setKeyPath(redisHandler.getVal("wxpay_keyPath"));
|
||||
payConfig.setAppId(RedisUtil.get("wxpay_appId"));
|
||||
payConfig.setMchId(RedisUtil.get("wxpay_mchId"));
|
||||
payConfig.setMchKey(RedisUtil.get("wxpay_mchKey"));
|
||||
payConfig.setKeyPath(RedisUtil.get("wxpay_keyPath"));
|
||||
// 可以指定是否使用沙箱环境
|
||||
payConfig.setUseSandboxEnv(false);
|
||||
wxPayService = new WxPayServiceImpl();
|
||||
wxPayService.setConfig(payConfig);
|
||||
payServices.put(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE, wxPayService);
|
||||
|
||||
|
||||
//增加标识
|
||||
RedisUtil.set(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE,"yshop");
|
||||
}
|
||||
return wxPayService;
|
||||
}
|
||||
@ -57,6 +59,7 @@ public class WxPayConfiguration {
|
||||
* 移除WxPayService
|
||||
*/
|
||||
public static void removeWxPayService(){
|
||||
RedisUtil.del(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE);
|
||||
payServices.remove(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user