商户、应用、服务商配置信息支持直接数据库查询(第三卷);

This commit is contained in:
terrfly 2021-11-19 09:42:07 +08:00
parent 021f010a4b
commit 3d882d977d
3 changed files with 28 additions and 18 deletions

View File

@ -32,6 +32,7 @@ import com.jeequan.jeepay.pay.channel.AbstractRefundService;
import com.jeequan.jeepay.pay.channel.wxpay.kits.WxpayKit;
import com.jeequan.jeepay.pay.channel.wxpay.kits.WxpayV3Util;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.model.WxServiceWrapper;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import com.jeequan.jeepay.pay.rqrs.refund.RefundOrderRQ;
import lombok.extern.slf4j.Slf4j;
@ -62,8 +63,12 @@ public class WxpayRefundService extends AbstractRefundService {
@Override
public ChannelRetMsg refund(RefundOrderRQ bizRQ, RefundOrder refundOrder, PayOrder payOrder, MchAppConfigContext mchAppConfigContext) throws Exception {
try {
ChannelRetMsg channelRetMsg = new ChannelRetMsg();
if (CS.PAY_IF_VERSION.WX_V2.equals(mchAppConfigContext.getWxServiceWrapper().getApiVersion())) { //V2
WxServiceWrapper wxServiceWrapper = configContextQueryService.getWxServiceWrapper(mchAppConfigContext);
if (CS.PAY_IF_VERSION.WX_V2.equals(wxServiceWrapper.getApiVersion())) { //V2
WxPayRefundRequest req = new WxPayRefundRequest();
@ -74,7 +79,7 @@ public class WxpayRefundService extends AbstractRefundService {
req.setOutRefundNo(refundOrder.getRefundOrderId()); // 退款单号
req.setTotalFee(payOrder.getAmount().intValue()); // 订单总金额
req.setRefundFee(refundOrder.getRefundAmount().intValue()); // 退款金额
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
WxPayService wxPayService = wxServiceWrapper.getWxPayService();
setCretPath(mchAppConfigContext, wxPayService); // 证书路径
WxPayRefundResult result = wxPayService.refundV2(req);
@ -86,7 +91,7 @@ public class WxpayRefundService extends AbstractRefundService {
channelRetMsg.setChannelErrCode(result.getErrCode());
channelRetMsg.setChannelErrMsg(WxpayKit.appendErrMsg(result.getReturnMsg(), result.getErrCodeDes()));
}
}else if (CS.PAY_IF_VERSION.WX_V3.equals(mchAppConfigContext.getWxServiceWrapper().getApiVersion())) { //V3
}else if (CS.PAY_IF_VERSION.WX_V3.equals(wxServiceWrapper.getApiVersion())) { //V3
// 微信统一下单请求对象
JSONObject reqJSON = new JSONObject();
reqJSON.put("out_trade_no", refundOrder.getPayOrderId()); // 订单号
@ -97,15 +102,15 @@ public class WxpayRefundService extends AbstractRefundService {
amountJson.put("total", payOrder.getAmount());// 订单总金额
amountJson.put("currency", "CNY");// 币种
reqJSON.put("amount", amountJson);
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
WxPayService wxPayService = wxServiceWrapper.getWxPayService();
setCretPath(mchAppConfigContext, wxPayService); // 证书路径
if(mchAppConfigContext.isIsvsubMch()){ // 特约商户
WxpayIsvsubMchParams isvsubMchParams = mchAppConfigContext.getIsvsubMchParamsByIfCode(getIfCode(), WxpayIsvsubMchParams.class);
WxpayIsvsubMchParams isvsubMchParams = (WxpayIsvsubMchParams)configContextQueryService.queryIsvsubMchParams(mchAppConfigContext.getMchNo(), mchAppConfigContext.getAppId(), getIfCode());
reqJSON.put("sub_mchid", isvsubMchParams.getSubMchId());
}
JSONObject resultJSON = WxpayV3Util.refundV3(reqJSON, mchAppConfigContext.getWxServiceWrapper().getWxPayService().getConfig());
JSONObject resultJSON = WxpayV3Util.refundV3(reqJSON, wxServiceWrapper.getWxPayService().getConfig());
String status = resultJSON.getString("status");
if("SUCCESS".equals(status)){ // 退款成功
String refundId = resultJSON.getString("refund_id");
@ -139,7 +144,11 @@ public class WxpayRefundService extends AbstractRefundService {
public ChannelRetMsg query(RefundOrder refundOrder, MchAppConfigContext mchAppConfigContext) throws Exception {
try {
ChannelRetMsg channelRetMsg = new ChannelRetMsg();
if (CS.PAY_IF_VERSION.WX_V2.equals(mchAppConfigContext.getWxServiceWrapper().getApiVersion())) { //V2
WxServiceWrapper wxServiceWrapper = configContextQueryService.getWxServiceWrapper(mchAppConfigContext);
if (CS.PAY_IF_VERSION.WX_V2.equals(wxServiceWrapper.getApiVersion())) { //V2
WxPayRefundQueryRequest req = new WxPayRefundQueryRequest();
@ -147,7 +156,7 @@ public class WxpayRefundService extends AbstractRefundService {
WxpayKit.putApiIsvInfo(mchAppConfigContext, req);
req.setOutRefundNo(refundOrder.getRefundOrderId()); // 退款单号
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
WxPayService wxPayService = wxServiceWrapper.getWxPayService();
setCretPath(mchAppConfigContext, wxPayService); // 证书路径
WxPayRefundQueryResult result = wxPayService.refundQueryV2(req);
@ -158,12 +167,12 @@ public class WxpayRefundService extends AbstractRefundService {
channelRetMsg.setChannelErrMsg(result.getReturnMsg());
}
}else if (CS.PAY_IF_VERSION.WX_V3.equals(mchAppConfigContext.getWxServiceWrapper().getApiVersion())) { //V3
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
}else if (CS.PAY_IF_VERSION.WX_V3.equals(wxServiceWrapper.getApiVersion())) { //V3
WxPayService wxPayService = wxServiceWrapper.getWxPayService();
setCretPath(mchAppConfigContext, wxPayService); // 证书路径
JSONObject resultJSON = null;
if (mchAppConfigContext.isIsvsubMch()) {
WxpayIsvsubMchParams isvsubMchParams = mchAppConfigContext.getIsvsubMchParamsByIfCode(getIfCode(), WxpayIsvsubMchParams.class);
WxpayIsvsubMchParams isvsubMchParams = (WxpayIsvsubMchParams)configContextQueryService.queryIsvsubMchParams(mchAppConfigContext.getMchNo(), mchAppConfigContext.getAppId(), getIfCode());
wxPayService.getConfig().setSubMchId(isvsubMchParams.getSubMchId());
resultJSON = WxpayV3Util.refundQueryV3Isv(refundOrder.getRefundOrderId(), wxPayService.getConfig());
}else {
@ -190,11 +199,11 @@ public class WxpayRefundService extends AbstractRefundService {
private void setCretPath(MchAppConfigContext mchAppConfigContext, WxPayService wxPayService) {
if(mchAppConfigContext.isIsvsubMch()){
// 获取服务商配置信息
WxpayIsvParams wxpayIsvParams = mchAppConfigContext.getIsvConfigContext().getIsvParamsByIfCode(CS.IF_CODE.WXPAY, WxpayIsvParams.class);
WxpayIsvParams wxpayIsvParams = (WxpayIsvParams)configContextQueryService.queryIsvParams(mchAppConfigContext.getMchInfo().getIsvNo(), CS.IF_CODE.WXPAY);
wxPayService.getConfig().setKeyPath(channelCertConfigKitBean.getCertFilePath(wxpayIsvParams.getCert()));
}else{
// 获取商户配置信息
WxpayNormalMchParams normalMchParams = mchAppConfigContext.getNormalMchParamsByIfCode(CS.IF_CODE.WXPAY, WxpayNormalMchParams.class);
WxpayNormalMchParams normalMchParams = (WxpayNormalMchParams)configContextQueryService.queryNormalMchParams(mchAppConfigContext.getMchNo(), mchAppConfigContext.getAppId(), CS.IF_CODE.WXPAY);
wxPayService.getConfig().setKeyPath(channelCertConfigKitBean.getCertFilePath(normalMchParams.getCert()));
}
}

View File

@ -24,6 +24,7 @@ import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.pay.channel.wxpay.WxpayPaymentService;
import com.jeequan.jeepay.pay.channel.wxpay.kits.WxpayKit;
import com.jeequan.jeepay.pay.model.WxServiceWrapper;
import com.jeequan.jeepay.pay.rqrs.AbstractRS;
import com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ;
import com.jeequan.jeepay.pay.rqrs.payorder.payway.WxBarOrderRQ;
@ -86,7 +87,8 @@ public class WxBar extends WxpayPaymentService {
// 调起上游接口
// 1. 如果抛异常则订单状态为 生成状态此时没有查单处理操作 订单将超时关闭
// 2. 接口调用成功 后续异常需进行捕捉 如果 逻辑代码出现异常则需要走完正常流程此时订单状态为 支付中 需要查单处理
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
WxServiceWrapper wxServiceWrapper = configContextQueryService.getWxServiceWrapper(mchAppConfigContext);
WxPayService wxPayService = wxServiceWrapper.getWxPayService();
try {
WxPayMicropayResult wxPayMicropayResult = wxPayService.micropay(request);

View File

@ -19,13 +19,12 @@ import com.alibaba.fastjson.JSONObject;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.ctrls.AbstractCtrl;
import com.jeequan.jeepay.core.entity.MchApp;
import com.jeequan.jeepay.core.entity.MchInfo;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.utils.JeepayKit;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.rqrs.AbstractMchAppRQ;
import com.jeequan.jeepay.pay.rqrs.AbstractRQ;
import com.jeequan.jeepay.pay.service.ConfigContextService;
import com.jeequan.jeepay.pay.service.ConfigContextQueryService;
import com.jeequan.jeepay.pay.service.ValidateService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -40,7 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
public abstract class ApiController extends AbstractCtrl {
@Autowired private ValidateService validateService;
@Autowired private ConfigContextService configContextService;
@Autowired private ConfigContextQueryService configContextQueryService;
/** 获取请求参数并转换为对象,通用验证 **/
@ -72,7 +71,7 @@ public abstract class ApiController extends AbstractCtrl {
throw new BizException("参数有误!");
}
MchAppConfigContext mchAppConfigContext = configContextService.getMchAppConfigContext(mchNo, appId);
MchAppConfigContext mchAppConfigContext = configContextQueryService.queryMchInfoAndAppInfo(mchNo, appId);
if(mchAppConfigContext == null){
throw new BizException("商户或商户应用不存在");