对于程序中配置字段,统一管理

This commit is contained in:
wangdawei
2020-05-25 10:45:05 +08:00
parent 200b48dc4e
commit ceb396c91e
27 changed files with 328 additions and 132 deletions

View File

@ -0,0 +1,156 @@
package co.yixiang.mp.config;
import co.yixiang.constant.ShopConstants;
import co.yixiang.constant.SystemConfigConstants;
/**
* 处理缓存key值的统一入口方面后面扩展
* 例如:多租户就要在每个key后拼接上租户ID只要统一修改这里就可以了
*/
public class ShopKeyUtils {
/**
*扩展值,默认为空, 把这个值追加到所有key值上
*/
private static String getExtendValue(){
String extendValue= "";
return extendValue;
}
//*********************************begin yx_system_config 通用值 *****************************************************
/**
* api_url
*/
public static String getApiUrl(){
String apiUrl= SystemConfigConstants.API_URL;
return apiUrl;
}
/**
* site_url
*/
public static String getSiteUrl(){
String siteUrl= SystemConfigConstants.SITE_URL;
return siteUrl;
}
/**
* 腾讯mapkey tengxun_map_key
*/
public static String getTengXunMapKey(){
String tengxunMapKey= SystemConfigConstants.TENGXUN_MAP_KEY;
return tengxunMapKey;
}
//*********************************begin yx_system_config 业务字段 *****************************************************
/**
* store_self_mention
*/
public static String getStoreSelfMention(){
String storeSelfMention= SystemConfigConstants.STORE_SEFL_MENTION;
return storeSelfMention+getExtendValue();
}
//*********************************begin yx_system_config 微信配置相关字段 *****************************************************
/**
* 微信公众号service
*/
public static String getYshopWeiXinMpSevice(){
String yshopWeiXinMpSevice= ShopConstants.YSHOP_WEIXIN_MP_SERVICE;
return yshopWeiXinMpSevice+getExtendValue();
}
/**
* 微信公众号id
*/
public static String getWechatAppId(){
String wechatAppId= SystemConfigConstants.WECHAT_APPID;
return wechatAppId+getExtendValue();
}
/**
* 微信公众号secret
*/
public static String getWechatAppSecret(){
String wechatAppSecret= SystemConfigConstants.WECHAT_APPSECRET;
return wechatAppSecret+getExtendValue();
}
/**
* 微信公众号验证token
*/
public static String getWechatToken(){
String wechatToken= SystemConfigConstants.WECHAT_TOKEN;
return wechatToken+getExtendValue();
}
/**
* 微信公众号 EncodingAESKey
*/
public static String getWechatEncodingAESKey(){
String wechatEncodingAESKey= SystemConfigConstants.WECHAT_ENCODINGAESKEY;
return wechatEncodingAESKey+getExtendValue();
}
/**
* 微信支付service
*/
public static String getYshopWeiXinPayService(){
String yshopWeiXinPayService= ShopConstants.YSHOP_WEIXIN_PAY_SERVICE;
return yshopWeiXinPayService+getExtendValue();
}
/**
* 商户号
*/
public static String getWxPayMchId(){
String wxPayMchId= SystemConfigConstants.WXPAY_MCHID;
return wxPayMchId+getExtendValue();
}
/**
* 商户秘钥
*/
public static String getWxPayMchKey(){
String wxPayMchKey= SystemConfigConstants.WXPAY_MCHKEY;
return wxPayMchKey+getExtendValue();
}
/**
* 商户证书路径
*/
public static String getWxPayKeyPath(){
String wxPayKeyPath= SystemConfigConstants.WXPAY_KEYPATH;
return wxPayKeyPath+getExtendValue();
}
/**
* 微信支付小程序service
*/
public static String getYshopWeiXinMiniPayService(){
String yshopWeiXinMiniPayService= ShopConstants.YSHOP_WEIXIN_MINI_PAY_SERVICE;
return yshopWeiXinMiniPayService+getExtendValue();
}
/**
* 微信支付app service
*/
public static String getYshopWeiXinAppPayService(){
String yshopWeiXinAppPayService= ShopConstants.YSHOP_WEIXIN_APP_PAY_SERVICE;
return yshopWeiXinAppPayService+getExtendValue();
}
/**
* 微信小程序id
*/
public static String getWxAppAppId(){
String wxAppAppId= SystemConfigConstants.WXAPP_APPID;
return wxAppAppId+getExtendValue();
}
/**
* 微信小程序秘钥
*/
public static String getWxAppSecret(){
String wxAppSecret= SystemConfigConstants.WXAPP_SECRET;
return wxAppSecret+getExtendValue();
}
/**
* 支付appId
*/
public static String getWxNativeAppAppId(){
String wxNativeAppAppId= SystemConfigConstants.WX_NATIVE_APP_APPID;
return wxNativeAppAppId+getExtendValue();
}
}

View File

@ -5,9 +5,6 @@
*/
package co.yixiang.mp.config;
import cn.hutool.core.util.StrUtil;
import co.yixiang.constant.ShopConstants;
import co.yixiang.enums.RedisKeyEnum;
import co.yixiang.mp.handler.*;
import co.yixiang.utils.RedisUtil;
import com.google.common.collect.Maps;
@ -72,21 +69,21 @@ public class WxMpConfiguration {
*/
public static WxMpService getWxMpService() {
WxMpService wxMpService = mpServices.get(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
WxMpService wxMpService = mpServices.get(ShopKeyUtils.getYshopWeiXinMpSevice());
//增加一个redis标识
if(wxMpService == null || RedisUtil.get(ShopConstants.YSHOP_WEIXIN_MP_SERVICE) == null) {
if(wxMpService == null || RedisUtil.get(ShopKeyUtils.getYshopWeiXinMpSevice()) == null) {
WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
configStorage.setAppId(RedisUtil.get(RedisKeyEnum.WECHAT_APPID.getValue()));
configStorage.setSecret(RedisUtil.get(RedisKeyEnum.WECHAT_APPSECRET.getValue()));
configStorage.setToken(RedisUtil.get(RedisKeyEnum.WECHAT_TOKEN.getValue()));
configStorage.setAesKey(RedisUtil.get(RedisKeyEnum.WECHAT_ENCODINGAESKEY.getValue()));
configStorage.setAppId(RedisUtil.get(ShopKeyUtils.getWechatAppId()));
configStorage.setSecret(RedisUtil.get(ShopKeyUtils.getWechatAppSecret()));
configStorage.setToken(RedisUtil.get(ShopKeyUtils.getWechatToken()));
configStorage.setAesKey(RedisUtil.get(ShopKeyUtils.getWechatEncodingAESKey()));
wxMpService = new WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(configStorage);
mpServices.put(ShopConstants.YSHOP_WEIXIN_MP_SERVICE, wxMpService);
routers.put(ShopConstants.YSHOP_WEIXIN_MP_SERVICE, newRouter(wxMpService));
mpServices.put(ShopKeyUtils.getYshopWeiXinMpSevice(), wxMpService);
routers.put(ShopKeyUtils.getYshopWeiXinMpSevice(), newRouter(wxMpService));
//增加标识
RedisUtil.set(ShopConstants.YSHOP_WEIXIN_MP_SERVICE,"yshop");
RedisUtil.set(ShopKeyUtils.getYshopWeiXinMpSevice(),"yshop");
}
return wxMpService;
}
@ -95,16 +92,16 @@ 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);
RedisUtil.del(ShopKeyUtils.getYshopWeiXinMpSevice());
mpServices.remove(ShopKeyUtils.getYshopWeiXinMpSevice());
routers.remove(ShopKeyUtils.getYshopWeiXinMpSevice());
}
/**
* 获取WxMpMessageRouter
*/
public static WxMpMessageRouter getWxMpMessageRouter() {
WxMpMessageRouter wxMpMessageRouter = routers.get(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
WxMpMessageRouter wxMpMessageRouter = routers.get(ShopKeyUtils.getYshopWeiXinMpSevice());
return wxMpMessageRouter;
}

View File

@ -5,8 +5,6 @@
*/
package co.yixiang.mp.config;
import co.yixiang.constant.ShopConstants;
import co.yixiang.enums.RedisKeyEnum;
import co.yixiang.mp.handler.RedisHandler;
import co.yixiang.utils.RedisUtil;
import com.github.binarywang.wxpay.config.WxPayConfig;
@ -42,22 +40,22 @@ public class WxPayConfiguration {
* @return
*/
public static WxPayService getPayService() {
WxPayService wxPayService = payServices.get(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE);
if(wxPayService == null || RedisUtil.get(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE) == null) {
WxPayService wxPayService = payServices.get(ShopKeyUtils.getYshopWeiXinPayService());
if(wxPayService == null || RedisUtil.get(ShopKeyUtils.getYshopWeiXinPayService()) == null) {
WxPayConfig payConfig = new WxPayConfig();
payConfig.setAppId(RedisUtil.get(RedisKeyEnum.WECHAT_APPID.getValue()));
payConfig.setMchId(RedisUtil.get(RedisKeyEnum.WXPAY_MCHID.getValue()));
payConfig.setMchKey(RedisUtil.get(RedisKeyEnum.WXPAY_MCHKEY.getValue()));
payConfig.setKeyPath(RedisUtil.get(RedisKeyEnum.WXPAY_KEYPATH.getValue()));
payConfig.setAppId(RedisUtil.get(ShopKeyUtils.getWechatAppId()));
payConfig.setMchId(RedisUtil.get(ShopKeyUtils.getWxPayMchId()));
payConfig.setMchKey(RedisUtil.get(ShopKeyUtils.getWxPayMchKey()));
payConfig.setKeyPath(RedisUtil.get(ShopKeyUtils.getWxPayKeyPath()));
// 可以指定是否使用沙箱环境
payConfig.setUseSandboxEnv(false);
wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(payConfig);
payServices.put(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE, wxPayService);
payServices.put(ShopKeyUtils.getYshopWeiXinPayService(), wxPayService);
//增加标识
RedisUtil.set(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE,"yshop");
}
RedisUtil.set(ShopKeyUtils.getYshopWeiXinPayService(),"yshop");
}
return wxPayService;
}
@ -66,21 +64,21 @@ public class WxPayConfiguration {
* @return
*/
public static WxPayService getWxAppPayService() {
WxPayService wxPayService = payServices.get(ShopConstants.YSHOP_WEIXIN_MINI_PAY_SERVICE);
if(wxPayService == null || RedisUtil.get(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE) == null) {
WxPayService wxPayService = payServices.get(ShopKeyUtils.getYshopWeiXinMiniPayService());
if(wxPayService == null || RedisUtil.get(ShopKeyUtils.getYshopWeiXinPayService()) == null) {
WxPayConfig payConfig = new WxPayConfig();
payConfig.setAppId(RedisUtil.get(RedisKeyEnum.WXAPP_APPID.getValue()));
payConfig.setMchId(RedisUtil.get(RedisKeyEnum.WXPAY_MCHID.getValue()));
payConfig.setMchKey(RedisUtil.get(RedisKeyEnum.WXPAY_MCHKEY.getValue()));
payConfig.setKeyPath(RedisUtil.get(RedisKeyEnum.WXPAY_KEYPATH.getValue()));
payConfig.setAppId(RedisUtil.get(ShopKeyUtils.getWxAppAppId()));
payConfig.setMchId(RedisUtil.get(ShopKeyUtils.getWxPayMchId()));
payConfig.setMchKey(RedisUtil.get(ShopKeyUtils.getWxPayMchKey()));
payConfig.setKeyPath(RedisUtil.get(ShopKeyUtils.getWxPayKeyPath()));
// 可以指定是否使用沙箱环境
payConfig.setUseSandboxEnv(false);
wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(payConfig);
payServices.put(ShopConstants.YSHOP_WEIXIN_MINI_PAY_SERVICE, wxPayService);
payServices.put(ShopKeyUtils.getYshopWeiXinMiniPayService(), wxPayService);
//增加标识
RedisUtil.set(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE,"yshop");
RedisUtil.set(ShopKeyUtils.getYshopWeiXinPayService(),"yshop");
}
return wxPayService;
}
@ -90,21 +88,21 @@ public class WxPayConfiguration {
* @return
*/
public static WxPayService getAppPayService() {
WxPayService wxPayService = payServices.get(ShopConstants.YSHOP_WEIXIN_APP_PAY_SERVICE);
if(wxPayService == null || RedisUtil.get(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE) == null) {
WxPayService wxPayService = payServices.get(ShopKeyUtils.getYshopWeiXinAppPayService());
if(wxPayService == null || RedisUtil.get(ShopKeyUtils.getYshopWeiXinPayService()) == null) {
WxPayConfig payConfig = new WxPayConfig();
payConfig.setAppId(RedisUtil.get(RedisKeyEnum.WX_NATIVE_APP_APPID.getValue()));
payConfig.setMchId(RedisUtil.get(RedisKeyEnum.WXPAY_MCHID.getValue()));
payConfig.setMchKey(RedisUtil.get(RedisKeyEnum.WXPAY_MCHKEY.getValue()));
payConfig.setKeyPath(RedisUtil.get(RedisKeyEnum.WXPAY_KEYPATH.getValue()));
payConfig.setAppId(RedisUtil.get(ShopKeyUtils.getWxNativeAppAppId()));
payConfig.setMchId(RedisUtil.get(ShopKeyUtils.getWxPayMchId()));
payConfig.setMchKey(RedisUtil.get(ShopKeyUtils.getWxPayMchKey()));
payConfig.setKeyPath(RedisUtil.get(ShopKeyUtils.getWxPayKeyPath()));
// 可以指定是否使用沙箱环境
payConfig.setUseSandboxEnv(false);
wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(payConfig);
payServices.put(ShopConstants.YSHOP_WEIXIN_APP_PAY_SERVICE, wxPayService);
payServices.put(ShopKeyUtils.getYshopWeiXinAppPayService(), wxPayService);
//增加标识
RedisUtil.set(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE,"yshop");
RedisUtil.set(ShopKeyUtils.getYshopWeiXinPayService(),"yshop");
}
return wxPayService;
}
@ -113,12 +111,10 @@ public class WxPayConfiguration {
* 移除WxPayService
*/
public static void removeWxPayService(){
RedisUtil.del(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE);
payServices.remove(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE);
payServices.remove(ShopConstants.YSHOP_WEIXIN_MINI_PAY_SERVICE);
payServices.remove(ShopConstants.YSHOP_WEIXIN_APP_PAY_SERVICE);
RedisUtil.del(ShopKeyUtils.getYshopWeiXinPayService());
payServices.remove(ShopKeyUtils.getYshopWeiXinPayService());
payServices.remove(ShopKeyUtils.getYshopWeiXinMiniPayService());
payServices.remove(ShopKeyUtils.getYshopWeiXinAppPayService());
}
}

View File

@ -7,6 +7,7 @@ package co.yixiang.mp.service;
import cn.hutool.core.util.StrUtil;
import co.yixiang.exception.ErrorRequestException;
import co.yixiang.mp.config.ShopKeyUtils;
import co.yixiang.mp.config.WxPayConfiguration;
import co.yixiang.mp.handler.RedisHandler;
import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
@ -43,7 +44,7 @@ public class YxMiniPayService {
public WxPayMpOrderResult wxPay(String orderId, String openId, String body,
Integer totalFee,String attach) throws WxPayException {
String apiUrl = redisHandler.getVal("api_url");
String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl());
if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
WxPayService wxPayService = WxPayConfiguration.getWxAppPayService();
@ -74,7 +75,7 @@ public class YxMiniPayService {
* @throws WxPayException
*/
public void refundOrder(String orderId, Integer totalFee) throws WxPayException {
String apiUrl = redisHandler.getVal("api_url");
String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl());
if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
WxPayService wxPayService = WxPayConfiguration.getWxAppPayService();

View File

@ -8,6 +8,7 @@ package co.yixiang.mp.service;
import cn.hutool.core.util.StrUtil;
import co.yixiang.exception.BadRequestException;
import co.yixiang.exception.ErrorRequestException;
import co.yixiang.mp.config.ShopKeyUtils;
import co.yixiang.mp.config.WxPayConfiguration;
import co.yixiang.mp.handler.RedisHandler;
import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
@ -48,7 +49,7 @@ public class YxPayService {
public WxPayMpOrderResult wxPay(String orderId, String openId, String body,
Integer totalFee,String attach) throws WxPayException {
String apiUrl = redisHandler.getVal("api_url");
String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl());
if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
WxPayService wxPayService = WxPayConfiguration.getPayService();
@ -83,7 +84,7 @@ public class YxPayService {
public WxPayMwebOrderResult wxH5Pay(String orderId, String body,
Integer totalFee,String attach) throws WxPayException {
String apiUrl = redisHandler.getVal("api_url");
String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl());
if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
WxPayService wxPayService = WxPayConfiguration.getPayService();
@ -115,7 +116,7 @@ public class YxPayService {
public WxPayAppOrderResult appPay(String orderId, String body,
Integer totalFee, String attach) throws WxPayException {
String apiUrl = redisHandler.getVal("api_url");
String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl());
if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
WxPayService wxPayService = WxPayConfiguration.getAppPayService();
@ -143,7 +144,7 @@ public class YxPayService {
* @throws WxPayException
*/
public void refundOrder(String orderId, Integer totalFee) throws WxPayException {
String apiUrl = redisHandler.getVal("api_url");
String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl());
if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
WxPayService wxPayService = WxPayConfiguration.getPayService();

View File

@ -5,6 +5,7 @@
*/
package co.yixiang.mp.service;
import co.yixiang.mp.config.ShopKeyUtils;
import co.yixiang.mp.domain.YxWechatTemplate;
import co.yixiang.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
@ -38,7 +39,7 @@ public class YxTemplateService {
* @param openid
*/
public void rechargeSuccessNotice(String time,String price,String openid){
String siteUrl = RedisUtil.get("site_url");
String siteUrl = RedisUtil.get(ShopKeyUtils.getSiteUrl());
YxWechatTemplate WechatTemplate = templateService.findByTempkey(RECHARGE_SUCCESS_KEY);
Map<String,String> map = new HashMap<>();
map.put("first","您的账户金币发生变动,详情如下:");
@ -59,7 +60,7 @@ public class YxTemplateService {
* @param openid
*/
public void paySuccessNotice(String orderId,String price,String openid){
String siteUrl = RedisUtil.get("site_url");
String siteUrl = RedisUtil.get(ShopKeyUtils.getSiteUrl());
YxWechatTemplate WechatTemplate = templateService.findByTempkey(PAY_SUCCESS_KEY);
Map<String,String> map = new HashMap<>();
map.put("first","您的订单已支付成功,我们会尽快为您发货。");
@ -79,7 +80,7 @@ public class YxTemplateService {
* @param time
*/
public void refundSuccessNotice(String orderId,String price,String openid,String time){
String siteUrl = RedisUtil.get("site_url");
String siteUrl = RedisUtil.get(ShopKeyUtils.getSiteUrl());
YxWechatTemplate WechatTemplate = templateService.findByTempkey(REFUND_SUCCESS_KEY);
Map<String,String> map = new HashMap<>();
map.put("first","您在yshop的订单退款申请被通过钱款将很快还至您的支付账户。");
@ -100,7 +101,7 @@ public class YxTemplateService {
* @param openid
*/
public void deliverySuccessNotice(String orderId,String deliveryName,String deliveryId,String openid){
String siteUrl = RedisUtil.get("site_url");
String siteUrl = RedisUtil.get(ShopKeyUtils.getSiteUrl());
YxWechatTemplate WechatTemplate = templateService.findByTempkey(DELIVERY_SUCCESS_KEY);
Map<String,String> map = new HashMap<>();
map.put("first","亲,宝贝已经启程了,好想快点来到你身边。");