公众号支付配置重构,增加枚举,增加积分抵扣限制
This commit is contained in:
@ -24,7 +24,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java-pay-spring-boot-starter</artifactId>
|
||||
<artifactId>weixin-java-pay</artifactId>
|
||||
<version>${weixin-java.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package co.yixiang.mp.config;
|
||||
|
||||
import co.yixiang.constant.ShopConstants;
|
||||
import co.yixiang.mp.handler.*;
|
||||
import com.google.common.collect.Maps;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
@ -61,9 +62,9 @@ public class WxMpConfiguration {
|
||||
* 获取WxMpService
|
||||
* @return
|
||||
*/
|
||||
public static WxMpService getWxMpService(String appId) {
|
||||
public static WxMpService getWxMpService() {
|
||||
|
||||
WxMpService wxMpService = mpServices.get(appId);
|
||||
WxMpService wxMpService = mpServices.get(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
|
||||
if(wxMpService == null) {
|
||||
WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
|
||||
configStorage.setAppId(redisHandler.getVal("wechat_appid"));
|
||||
@ -72,27 +73,25 @@ public class WxMpConfiguration {
|
||||
configStorage.setAesKey(redisHandler.getVal("wechat_encodingaeskey"));
|
||||
wxMpService = new WxMpServiceImpl();
|
||||
wxMpService.setWxMpConfigStorage(configStorage);
|
||||
mpServices.put(appId, wxMpService);
|
||||
routers.put(appId, newRouter(wxMpService));
|
||||
mpServices.put(ShopConstants.YSHOP_WEIXIN_MP_SERVICE, wxMpService);
|
||||
routers.put(ShopConstants.YSHOP_WEIXIN_MP_SERVICE, newRouter(wxMpService));
|
||||
}
|
||||
return wxMpService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除WxMpService
|
||||
* @param appId
|
||||
*/
|
||||
public static void removeWxMpService(String appId){
|
||||
mpServices.remove(appId);
|
||||
routers.remove(appId);
|
||||
public static void removeWxMpService(){
|
||||
mpServices.remove(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
|
||||
routers.remove(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取WxMpMessageRouter
|
||||
* @param appId
|
||||
*/
|
||||
public static WxMpMessageRouter getWxMpMessageRouter(String appId) {
|
||||
WxMpMessageRouter wxMpMessageRouter = routers.get(appId);
|
||||
public static WxMpMessageRouter getWxMpMessageRouter() {
|
||||
WxMpMessageRouter wxMpMessageRouter = routers.get(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
|
||||
return wxMpMessageRouter;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,62 @@
|
||||
package co.yixiang.mp.config;
|
||||
|
||||
import co.yixiang.constant.ShopConstants;
|
||||
import co.yixiang.mp.handler.RedisHandler;
|
||||
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 支付配置
|
||||
* @author hupeng
|
||||
* @date 2020/03/01
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class WxPayConfiguration {
|
||||
|
||||
private static Map<String, WxPayService> payServices = Maps.newHashMap();
|
||||
|
||||
private static RedisHandler redisHandler;
|
||||
|
||||
@Autowired
|
||||
public WxPayConfiguration(RedisHandler redisHandler) {
|
||||
this.redisHandler = redisHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取WxPayService
|
||||
* @return
|
||||
*/
|
||||
public static WxPayService getPayService() {
|
||||
WxPayService wxPayService = payServices.get(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE);
|
||||
if(wxPayService == 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.setUseSandboxEnv(false);
|
||||
wxPayService = new WxPayServiceImpl();
|
||||
wxPayService.setConfig(payConfig);
|
||||
payServices.put(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE, wxPayService);
|
||||
|
||||
|
||||
}
|
||||
return wxPayService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除WxPayService
|
||||
*/
|
||||
public static void removeWxPayService(){
|
||||
payServices.remove(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE);
|
||||
}
|
||||
}
|
@ -55,11 +55,7 @@ public class WechatMenuController {
|
||||
Boolean isExist = yxCacheService.isExist("wechat_menus");
|
||||
WxMenu menu = JSONObject.parseObject(jsonStr,WxMenu.class);
|
||||
|
||||
String appId = RedisUtil.get("wechat_appid");
|
||||
if(StrUtil.isBlank(appId)) {
|
||||
throw new BadRequestException("请配置公众号");
|
||||
}
|
||||
WxMpService wxService = WxMpConfiguration.getWxMpService(appId);
|
||||
WxMpService wxService = WxMpConfiguration.getWxMpService();
|
||||
if(isExist){
|
||||
yxCache.setKey("wechat_menus");
|
||||
yxCache.setResult(jsonButton);
|
||||
|
@ -25,11 +25,7 @@ public class WxMpTemplateMessageServiceImpl implements WxMpTemplateMessageServic
|
||||
.build();
|
||||
map.forEach( (k,v)-> { templateMessage.addData(new WxMpTemplateData(k, v, "#000000"));} );
|
||||
String msgId = null;
|
||||
String appId = RedisUtil.get("wechat_appid");
|
||||
if(StrUtil.isBlank(appId)) {
|
||||
return "请配置公众号";
|
||||
}
|
||||
WxMpService wxService = WxMpConfiguration.getWxMpService(appId);
|
||||
WxMpService wxService = WxMpConfiguration.getWxMpService();
|
||||
try {
|
||||
msgId = wxService.getTemplateMsgService().sendTemplateMsg(templateMessage);
|
||||
} catch (WxErrorException e) {
|
||||
|
@ -106,11 +106,7 @@ public class YxArticleServiceImpl implements YxArticleService {
|
||||
@Override
|
||||
public void uploadNews(YxArticleDTO wxNewsArticleItem) throws Exception {
|
||||
|
||||
String appId = RedisUtil.get("wechat_appid");
|
||||
if(StrUtil.isBlank(appId)) {
|
||||
throw new BadRequestException("请配置公众号");
|
||||
}
|
||||
WxMpService wxMpService = WxMpConfiguration.getWxMpService(appId);
|
||||
WxMpService wxMpService = WxMpConfiguration.getWxMpService();
|
||||
|
||||
WxMpMaterialNews wxMpMaterialNews = new WxMpMaterialNews();
|
||||
|
||||
|
Reference in New Issue
Block a user