缓存数据开关的使用,若不开启则不更新不使用;

This commit is contained in:
terrfly 2021-11-19 10:05:03 +08:00
parent 3d882d977d
commit 3a4af7b04b
8 changed files with 64 additions and 40 deletions

View File

@ -26,6 +26,7 @@ import com.jeequan.jeepay.core.entity.MchInfo;
import com.jeequan.jeepay.core.entity.PayInterfaceConfig;
import com.jeequan.jeepay.core.entity.PayInterfaceDefine;
import com.jeequan.jeepay.core.model.ApiRes;
import com.jeequan.jeepay.core.model.DBApplicationConfig;
import com.jeequan.jeepay.core.model.params.NormalMchParams;
import com.jeequan.jeepay.core.utils.StringKit;
import com.jeequan.jeepay.mgr.ctrl.CommonCtrl;
@ -168,8 +169,9 @@ public class MchPayInterfaceConfigController extends CommonCtrl {
MchApp mchApp = mchAppService.getById(mchAppId);
MchInfo mchInfo = mchInfoService.getById(mchApp.getMchNo());
String authUrl = sysConfigService.getDBApplicationConfig().genAlipayIsvsubMchAuthUrl(mchInfo.getIsvNo(), mchAppId);
String authQrImgUrl = sysConfigService.getDBApplicationConfig().genScanImgUrl(authUrl);
DBApplicationConfig dbApplicationConfig = sysConfigService.getDBApplicationConfig();
String authUrl = dbApplicationConfig.genAlipayIsvsubMchAuthUrl(mchInfo.getIsvNo(), mchAppId);
String authQrImgUrl = dbApplicationConfig.genScanImgUrl(authUrl);
JSONObject result = new JSONObject();
result.put("authUrl", authUrl);

View File

@ -24,6 +24,7 @@ import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.entity.*;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.model.ApiRes;
import com.jeequan.jeepay.core.model.DBApplicationConfig;
import com.jeequan.jeepay.core.model.params.NormalMchParams;
import com.jeequan.jeepay.core.utils.StringKit;
import com.jeequan.jeepay.mch.ctrl.CommonCtrl;
@ -166,8 +167,9 @@ public class MchPayInterfaceConfigController extends CommonCtrl {
}
MchInfo mchInfo = mchInfoService.getById(mchApp.getMchNo());
String authUrl = sysConfigService.getDBApplicationConfig().genAlipayIsvsubMchAuthUrl(mchInfo.getIsvNo(), mchAppId);
String authQrImgUrl = sysConfigService.getDBApplicationConfig().genScanImgUrl(authUrl);
DBApplicationConfig dbApplicationConfig = sysConfigService.getDBApplicationConfig();
String authUrl = dbApplicationConfig.genAlipayIsvsubMchAuthUrl(mchInfo.getIsvNo(), mchAppId);
String authQrImgUrl = dbApplicationConfig.genScanImgUrl(authUrl);
JSONObject result = new JSONObject();
result.put("authUrl", authUrl);

View File

@ -22,6 +22,7 @@ import com.jeequan.jeepay.core.entity.MchApp;
import com.jeequan.jeepay.core.entity.MchPayPassage;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.model.ApiRes;
import com.jeequan.jeepay.core.model.DBApplicationConfig;
import com.jeequan.jeepay.exception.JeepayException;
import com.jeequan.jeepay.mch.ctrl.CommonCtrl;
import com.jeequan.jeepay.model.PayOrderCreateReqModel;
@ -111,7 +112,10 @@ public class PaytestController extends CommonCtrl {
model.setClientIp(getClientIp());
model.setSubject(orderTitle + "[" + getCurrentMchNo() + "商户联调]");
model.setBody(orderTitle + "[" + getCurrentMchNo() + "商户联调]");
model.setNotifyUrl(sysConfigService.getDBApplicationConfig().getMchSiteUrl() + "/api/anon/paytestNotify/payOrder"); //回调地址
DBApplicationConfig dbApplicationConfig = sysConfigService.getDBApplicationConfig();
model.setNotifyUrl(dbApplicationConfig.getMchSiteUrl() + "/api/anon/paytestNotify/payOrder"); //回调地址
model.setDivisionMode(divisionMode); //分账模式
//设置扩展参数
@ -124,7 +128,7 @@ public class PaytestController extends CommonCtrl {
}
model.setChannelExtra(extParams.toString());
JeepayClient jeepayClient = new JeepayClient(sysConfigService.getDBApplicationConfig().getPaySiteUrl(), mchApp.getAppSecret());
JeepayClient jeepayClient = new JeepayClient(dbApplicationConfig.getPaySiteUrl(), mchApp.getAppSecret());
try {
PayOrderCreateResponse response = jeepayClient.execute(request);

View File

@ -24,6 +24,7 @@ import com.jeequan.jeepay.core.entity.PayInterfaceConfig;
import com.jeequan.jeepay.core.entity.PayInterfaceDefine;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.model.ApiRes;
import com.jeequan.jeepay.core.model.DBApplicationConfig;
import com.jeequan.jeepay.core.utils.JeepayKit;
import com.jeequan.jeepay.core.utils.StringKit;
import com.jeequan.jeepay.exception.JeepayException;
@ -105,10 +106,13 @@ public class MchTransferController extends CommonCtrl {
param.put("reqTime", System.currentTimeMillis() + "");
param.put("version", "1.0");
param.put("signType", "MD5");
param.put("redirectUrl", sysConfigService.getDBApplicationConfig().getMchSiteUrl() + "/api/anon/channelUserIdCallback");
DBApplicationConfig dbApplicationConfig = sysConfigService.getDBApplicationConfig();
param.put("redirectUrl", dbApplicationConfig.getMchSiteUrl() + "/api/anon/channelUserIdCallback");
param.put("sign", JeepayKit.getSign(param, mchApp.getAppSecret()));
String url = StringKit.appendUrlQuery(sysConfigService.getDBApplicationConfig().getPaySiteUrl() + "/api/channelUserId/jump", param);
String url = StringKit.appendUrlQuery(dbApplicationConfig.getPaySiteUrl() + "/api/channelUserId/jump", param);
return ApiRes.ok(url);
}

View File

@ -25,6 +25,7 @@ import com.jeequan.jeepay.core.entity.MchPayPassage;
import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.model.ApiRes;
import com.jeequan.jeepay.core.model.DBApplicationConfig;
import com.jeequan.jeepay.core.utils.*;
import com.jeequan.jeepay.pay.channel.IPaymentService;
import com.jeequan.jeepay.pay.ctrl.ApiController;
@ -142,9 +143,11 @@ public abstract class AbstractPayOrderController extends ApiController {
QrCashierOrderRS qrCashierOrderRS = new QrCashierOrderRS();
QrCashierOrderRQ qrCashierOrderRQ = (QrCashierOrderRQ)bizRQ;
String payUrl = sysConfigService.getDBApplicationConfig().genUniJsapiPayUrl(payOrderId);
DBApplicationConfig dbApplicationConfig = sysConfigService.getDBApplicationConfig();
String payUrl = dbApplicationConfig.genUniJsapiPayUrl(payOrderId);
if(CS.PAY_DATA_TYPE.CODE_IMG_URL.equals(qrCashierOrderRQ.getPayDataType())){ //二维码地址
qrCashierOrderRS.setCodeImgUrl(sysConfigService.getDBApplicationConfig().genScanImgUrl(payUrl));
qrCashierOrderRS.setCodeImgUrl(dbApplicationConfig.genScanImgUrl(payUrl));
}else{ //默认都为跳转地址方式
qrCashierOrderRS.setPayUrl(payUrl);

View File

@ -15,46 +15,29 @@
*/
package com.jeequan.jeepay.pay.service;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.entity.IsvInfo;
import com.jeequan.jeepay.core.entity.MchApp;
import com.jeequan.jeepay.core.entity.MchInfo;
import com.jeequan.jeepay.core.entity.PayInterfaceConfig;
import com.jeequan.jeepay.core.model.params.IsvParams;
import com.jeequan.jeepay.core.model.params.IsvsubMchParams;
import com.jeequan.jeepay.core.model.params.NormalMchParams;
import com.jeequan.jeepay.core.model.params.alipay.AlipayConfig;
import com.jeequan.jeepay.core.model.params.alipay.AlipayIsvParams;
import com.jeequan.jeepay.core.model.params.alipay.AlipayNormalMchParams;
import com.jeequan.jeepay.core.model.params.wxpay.WxpayIsvParams;
import com.jeequan.jeepay.core.model.params.wxpay.WxpayNormalMchParams;
import com.jeequan.jeepay.pay.model.*;
import com.jeequan.jeepay.pay.util.ChannelCertConfigKitBean;
import com.jeequan.jeepay.service.impl.IsvInfoService;
import com.jeequan.jeepay.pay.model.AlipayClientWrapper;
import com.jeequan.jeepay.pay.model.IsvConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.model.WxServiceWrapper;
import com.jeequan.jeepay.service.impl.MchAppService;
import com.jeequan.jeepay.service.impl.MchInfoService;
import com.jeequan.jeepay.service.impl.PayInterfaceConfigService;
import com.jeequan.jeepay.service.impl.SysConfigService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/*
* 配置信息查询服务 兼容 缓存 直接查询方式
*
@ -72,7 +55,7 @@ public class ConfigContextQueryService {
@Autowired private PayInterfaceConfigService payInterfaceConfigService;
private boolean isCache(){
return false;
return SysConfigService.IS_USE_CACHE;
}
public MchApp queryMchApp(String mchNo, String mchAppId){

View File

@ -28,10 +28,7 @@ import com.jeequan.jeepay.core.model.params.alipay.AlipayNormalMchParams;
import com.jeequan.jeepay.core.model.params.wxpay.WxpayIsvParams;
import com.jeequan.jeepay.core.model.params.wxpay.WxpayNormalMchParams;
import com.jeequan.jeepay.pay.model.*;
import com.jeequan.jeepay.service.impl.IsvInfoService;
import com.jeequan.jeepay.service.impl.MchAppService;
import com.jeequan.jeepay.service.impl.MchInfoService;
import com.jeequan.jeepay.service.impl.PayInterfaceConfigService;
import com.jeequan.jeepay.service.impl.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -110,6 +107,10 @@ public class ConfigContextService {
/** 初始化 [商户配置信息] **/
public synchronized void initMchInfoConfigContext(String mchNo){
if(!isCache()){ // 当前系统不进行缓存
return ;
}
//商户主体信息
MchInfo mchInfo = mchInfoService.getById(mchNo);
if(mchInfo == null){ // 查询不到商户主体 可能已经删除
@ -151,6 +152,10 @@ public class ConfigContextService {
/** 初始化 [商户应用支付参数配置信息] **/
public synchronized void initMchAppConfigContext(String mchNo, String appId){
if(!isCache()){ // 当前系统不进行缓存
return ;
}
// 获取商户的配置信息
MchInfoConfigContext mchInfoConfigContext = getMchInfoConfigContext(mchNo);
if(mchInfoConfigContext == null){ // 商户信息不存在
@ -239,6 +244,10 @@ public class ConfigContextService {
/** 初始化 [ISV支付参数配置信息] **/
public synchronized void initIsvConfigContext(String isvNo){
if(!isCache()){ // 当前系统不进行缓存
return ;
}
//查询出所有商户的配置信息并更新
List<String> mchNoList = new ArrayList<>();
mchInfoService.list(MchInfo.gw().select(MchInfo::getMchNo).eq(MchInfo::getIsvNo, isvNo)).forEach(r -> mchNoList.add(r.getMchNo()));
@ -309,8 +318,8 @@ public class ConfigContextService {
}
private boolean isCache(){
return SysConfigService.IS_USE_CACHE;
}
}

View File

@ -39,6 +39,12 @@ import java.util.Set;
@Service
public class SysConfigService extends ServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService {
/** 是否启用缓存
* true: 表示将使用内存缓存 将部分系统配置项 商户应用/服务商信息进行缓存并读取
* false: 直接查询DB
* **/
public static boolean IS_USE_CACHE = false;
@Autowired
private SysConfigService sysConfigService;
@ -47,6 +53,11 @@ public class SysConfigService extends ServiceImpl<SysConfigMapper, SysConfig> im
public synchronized void initDBConfig(String groupKey) {
// 若当前系统不缓存则直接返回
if(!IS_USE_CACHE){
return;
}
if(APPLICATION_CONFIG.getLeft().equalsIgnoreCase(groupKey)){
APPLICATION_CONFIG.right = this.selectByGroupKey(groupKey).toJavaObject(DBApplicationConfig.class);
}
@ -56,6 +67,12 @@ public class SysConfigService extends ServiceImpl<SysConfigMapper, SysConfig> im
@Override
public DBApplicationConfig getDBApplicationConfig() {
// 查询DB
if(!IS_USE_CACHE){
return this.selectByGroupKey(APPLICATION_CONFIG.getLeft()).toJavaObject(DBApplicationConfig.class);
}
// 缓存数据
if(APPLICATION_CONFIG.getRight() == null ){
initDBConfig(APPLICATION_CONFIG.getLeft());
}