Commit 252369f9 authored by terrfly's avatar terrfly
Browse files

支付网关支持商户应用配置项的下单操作;

parent bc3a2fa5
......@@ -53,10 +53,11 @@ public class CS {
}
/**
* 账号类型:1-服务商 2-商户
* 账号类型:1-服务商 2-商户 3-商户应用
*/
public static final byte INFO_TYPE_ISV = 1;
public static final byte INFO_TYPE_MCH = 2;
public static final byte INFO_TYPE_MCH_APP = 3;
/**
......@@ -132,6 +133,9 @@ public class CS {
/** 更新商户配置信息 **/
String TOPIC_MODIFY_MCH_INFO = "topic.modify.mch.info";
/** 更新商户应用配置信息 **/
String TOPIC_MODIFY_MCH_APP = "topic.modify.mch.app";
/** 更新服务商配置信息 **/
String TOPIC_MODIFY_ISV_INFO = "topic.modify.isv.info";
......
......@@ -16,7 +16,7 @@
package com.jeequan.jeepay.pay.channel;
import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import org.apache.commons.lang3.tuple.MutablePair;
import org.springframework.http.ResponseEntity;
......@@ -48,7 +48,7 @@ public interface IChannelNoticeService {
/** 返回需要更新的订单状态 和响应数据 **/
ChannelRetMsg doNotice(HttpServletRequest request,
Object params, PayOrder payOrder, MchConfigContext mchConfigContext, NoticeTypeEnum noticeTypeEnum);
Object params, PayOrder payOrder, MchAppConfigContext mchAppConfigContext, NoticeTypeEnum noticeTypeEnum);
/** 数据库订单 状态更新异常 (仅异步通知使用) **/
ResponseEntity doNotifyOrderStateUpdateFail(HttpServletRequest request);
......
......@@ -16,7 +16,7 @@
package com.jeequan.jeepay.pay.channel;
import com.alibaba.fastjson.JSONObject;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
/*
* @Description: 301方式获取渠道侧用户ID, 如微信openId 支付宝的userId等
......@@ -29,9 +29,9 @@ public interface IChannelUserService {
String getIfCode();
/** 获取重定向地址 **/
String buildUserRedirectUrl(String callbackUrlEncode, MchConfigContext mchConfigContext);
String buildUserRedirectUrl(String callbackUrlEncode, MchAppConfigContext mchAppConfigContext);
/** 获取渠道用户ID **/
String getChannelUserId(JSONObject reqParams, MchConfigContext mchConfigContext);
String getChannelUserId(JSONObject reqParams, MchAppConfigContext mchAppConfigContext);
}
......@@ -17,7 +17,7 @@ package com.jeequan.jeepay.pay.channel;
import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
/*
* 查单(渠道侧)接口定义
......@@ -32,6 +32,6 @@ public interface IPayOrderQueryService {
String getIfCode();
/** 查询订单 **/
ChannelRetMsg query(PayOrder payOrder, MchConfigContext mchConfigContext) throws Exception;
ChannelRetMsg query(PayOrder payOrder, MchAppConfigContext mchAppConfigContext) throws Exception;
}
......@@ -18,11 +18,11 @@ package com.jeequan.jeepay.pay.channel;
import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.pay.rqrs.AbstractRS;
import com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
/*
* 调起上游渠道侧支付接口
*
*
* @author terrfly
* @site https://www.jeepay.vip
* @date 2021/5/8 15:13
......@@ -39,6 +39,6 @@ public interface IPaymentService {
String preCheck(UnifiedOrderRQ bizRQ, PayOrder payOrder);
/** 调起支付接口,并响应数据; 内部处理普通商户和服务商模式 **/
AbstractRS pay(UnifiedOrderRQ bizRQ, PayOrder payOrder, MchConfigContext mchConfigContext) throws Exception;
AbstractRS pay(UnifiedOrderRQ bizRQ, PayOrder payOrder, MchAppConfigContext mchAppConfigContext) throws Exception;
}
......@@ -24,7 +24,7 @@ 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.pay.channel.AbstractChannelNoticeService;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.MutablePair;
......@@ -69,16 +69,16 @@ public class AlipayChannelNoticeService extends AbstractChannelNoticeService {
@Override
public ChannelRetMsg doNotice(HttpServletRequest request, Object params, PayOrder payOrder, MchConfigContext mchConfigContext, NoticeTypeEnum noticeTypeEnum) {
public ChannelRetMsg doNotice(HttpServletRequest request, Object params, PayOrder payOrder, MchAppConfigContext mchAppConfigContext, NoticeTypeEnum noticeTypeEnum) {
try {
//配置参数获取
Byte useCert = null;
String alipaySignType, alipayPublicCert, alipayPublicKey = null;
if(mchConfigContext.isIsvsubMch()){
if(mchAppConfigContext.isIsvsubMch()){
// 获取支付参数
AlipayIsvParams alipayParams = mchConfigContext.getIsvConfigContext().getIsvParamsByIfCode(getIfCode(), AlipayIsvParams.class);
AlipayIsvParams alipayParams = mchAppConfigContext.getIsvConfigContext().getIsvParamsByIfCode(getIfCode(), AlipayIsvParams.class);
useCert = alipayParams.getUseCert();
alipaySignType = alipayParams.getSignType();
alipayPublicCert = alipayParams.getAlipayPublicCert();
......@@ -87,7 +87,7 @@ public class AlipayChannelNoticeService extends AbstractChannelNoticeService {
}else{
// 获取支付参数
AlipayNormalMchParams alipayParams = mchConfigContext.getNormalMchParamsByIfCode(getIfCode(), AlipayNormalMchParams.class);
AlipayNormalMchParams alipayParams = mchAppConfigContext.getNormalMchParamsByIfCode(getIfCode(), AlipayNormalMchParams.class);
useCert = alipayParams.getUseCert();
alipaySignType = alipayParams.getSignType();
alipayPublicCert = alipayParams.getAlipayPublicCert();
......
......@@ -23,13 +23,13 @@ import com.jeequan.jeepay.core.model.params.alipay.AlipayIsvParams;
import com.jeequan.jeepay.core.model.params.alipay.AlipayNormalMchParams;
import com.jeequan.jeepay.pay.channel.IChannelUserService;
import com.jeequan.jeepay.pay.exception.ChannelException;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/*
* 支付宝: 获取用户ID实现类
*
*
* @author terrfly
* @site https://www.jeepay.vip
* @date 2021/6/8 17:21
......@@ -45,17 +45,17 @@ public class AlipayChannelUserService implements IChannelUserService {
}
@Override
public String buildUserRedirectUrl(String callbackUrlEncode, MchConfigContext mchConfigContext) {
public String buildUserRedirectUrl(String callbackUrlEncode, MchAppConfigContext mchAppConfigContext) {
String oauthUrl = AlipayConfig.PROD_OAUTH_URL;
String appId = null;
if(mchConfigContext.isIsvsubMch()){
AlipayIsvParams isvParams = mchConfigContext.getIsvConfigContext().getIsvParamsByIfCode(getIfCode(), AlipayIsvParams.class);
if(mchAppConfigContext.isIsvsubMch()){
AlipayIsvParams isvParams = mchAppConfigContext.getIsvConfigContext().getIsvParamsByIfCode(getIfCode(), AlipayIsvParams.class);
appId = isvParams.getAppId();
}else{
//获取商户配置信息
AlipayNormalMchParams normalMchParams = mchConfigContext.getNormalMchParamsByIfCode(getIfCode(), AlipayNormalMchParams.class);
AlipayNormalMchParams normalMchParams = mchAppConfigContext.getNormalMchParamsByIfCode(getIfCode(), AlipayNormalMchParams.class);
appId = normalMchParams.getAppId();
if(normalMchParams.getSandbox() != null && normalMchParams.getSandbox() == CS.YES){
oauthUrl = AlipayConfig.SANDBOX_OAUTH_URL;
......@@ -66,7 +66,7 @@ public class AlipayChannelUserService implements IChannelUserService {
}
@Override
public String getChannelUserId(JSONObject reqParams, MchConfigContext mchConfigContext) {
public String getChannelUserId(JSONObject reqParams, MchAppConfigContext mchAppConfigContext) {
String authCode = reqParams.getString("auth_code");
......@@ -74,7 +74,7 @@ public class AlipayChannelUserService implements IChannelUserService {
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
request.setCode(authCode); request.setGrantType("authorization_code");
try {
return mchConfigContext.getAlipayClientWrapper().execute(request).getUserId();
return mchAppConfigContext.getAlipayClientWrapper().execute(request).getUserId();
} catch (ChannelException e) {
e.printStackTrace();
return null;
......
......@@ -22,7 +22,7 @@ import com.alipay.api.request.*;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.model.params.alipay.AlipayIsvParams;
import com.jeequan.jeepay.core.model.params.alipay.AlipayIsvsubMchParams;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import org.apache.commons.lang3.StringUtils;
/*
......@@ -36,16 +36,16 @@ public class AlipayKit {
/** 放置 isv特殊信息 **/
public static void putApiIsvInfo(MchConfigContext mchConfigContext, AlipayRequest req, AlipayObject model){
public static void putApiIsvInfo(MchAppConfigContext mchAppConfigContext, AlipayRequest req, AlipayObject model){
//不是特约商户, 无需放置此值
if(!mchConfigContext.isIsvsubMch()){
if(!mchAppConfigContext.isIsvsubMch()){
return ;
}
// 获取支付参数
AlipayIsvParams isvParams = mchConfigContext.getIsvConfigContext().getIsvParamsByIfCode(CS.IF_CODE.ALIPAY, AlipayIsvParams.class);
AlipayIsvsubMchParams isvsubMchParams = mchConfigContext.getIsvsubMchParamsByIfCode(CS.IF_CODE.ALIPAY, AlipayIsvsubMchParams.class);
AlipayIsvParams isvParams = mchAppConfigContext.getIsvConfigContext().getIsvParamsByIfCode(CS.IF_CODE.ALIPAY, AlipayIsvParams.class);
AlipayIsvsubMchParams isvsubMchParams = mchAppConfigContext.getIsvsubMchParamsByIfCode(CS.IF_CODE.ALIPAY, AlipayIsvsubMchParams.class);
// 子商户信息
if(req instanceof AlipayTradePayRequest) ((AlipayTradePayRequest)req).putOtherTextParam("app_auth_token", isvsubMchParams.getAppAuthToken());
......
......@@ -21,7 +21,7 @@ import com.alipay.api.response.AlipayTradeQueryResponse;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.pay.channel.IPayOrderQueryService;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import org.springframework.stereotype.Service;
......@@ -41,7 +41,7 @@ public class AlipayPayOrderQueryService implements IPayOrderQueryService {
}
@Override
public ChannelRetMsg query(PayOrder payOrder, MchConfigContext mchConfigContext){
public ChannelRetMsg query(PayOrder payOrder, MchAppConfigContext mchAppConfigContext){
AlipayTradeQueryRequest req = new AlipayTradeQueryRequest();
......@@ -51,9 +51,9 @@ public class AlipayPayOrderQueryService implements IPayOrderQueryService {
req.setBizModel(model);
//通用字段
AlipayKit.putApiIsvInfo(mchConfigContext, req, model);
AlipayKit.putApiIsvInfo(mchAppConfigContext, req, model);
AlipayTradeQueryResponse resp = mchConfigContext.getAlipayClientWrapper().execute(req);
AlipayTradeQueryResponse resp = mchAppConfigContext.getAlipayClientWrapper().execute(req);
String result = resp.getTradeStatus();
if("TRADE_SUCCESS".equals(result)) {
......
......@@ -18,7 +18,7 @@ package com.jeequan.jeepay.pay.channel.alipay;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.pay.channel.AbstractPaymentService;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.rqrs.AbstractRS;
import com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ;
import com.jeequan.jeepay.pay.util.PaywayUtil;
......@@ -51,8 +51,8 @@ public class AlipayPaymentService extends AbstractPaymentService {
}
@Override
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchConfigContext mchConfigContext) throws Exception {
return PaywayUtil.getRealPaywayService(this, payOrder.getWayCode()).pay(rq, payOrder, mchConfigContext);
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchAppConfigContext mchAppConfigContext) throws Exception {
return PaywayUtil.getRealPaywayService(this, payOrder.getWayCode()).pay(rq, payOrder, mchAppConfigContext);
}
}
......@@ -28,7 +28,7 @@ import com.jeequan.jeepay.pay.rqrs.payorder.payway.AliAppOrderRS;
import com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import com.jeequan.jeepay.pay.util.ApiResBuilder;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import org.springframework.stereotype.Service;
/*
......@@ -47,7 +47,7 @@ public class AliApp extends AlipayPaymentService {
}
@Override
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchConfigContext mchConfigContext){
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchAppConfigContext mchAppConfigContext){
AlipayTradeAppPayRequest req = new AlipayTradeAppPayRequest();
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
......@@ -59,14 +59,14 @@ public class AliApp extends AlipayPaymentService {
req.setBizModel(model);
//统一放置 isv接口必传信息
AlipayKit.putApiIsvInfo(mchConfigContext, req, model);
AlipayKit.putApiIsvInfo(mchAppConfigContext, req, model);
String payData = null;
// sdk方式需自行拦截接口异常信息
try {
payData = mchConfigContext.getAlipayClientWrapper().getAlipayClient().sdkExecute(req).getBody();
payData = mchAppConfigContext.getAlipayClientWrapper().getAlipayClient().sdkExecute(req).getBody();
} catch (AlipayApiException e) {
throw ChannelException.sysError(e.getMessage());
}
......
......@@ -29,7 +29,7 @@ import com.jeequan.jeepay.pay.rqrs.payorder.payway.AliBarOrderRS;
import com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import com.jeequan.jeepay.pay.util.ApiResBuilder;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
......@@ -55,7 +55,7 @@ public class AliBar extends AlipayPaymentService {
}
@Override
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchConfigContext mchConfigContext){
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchAppConfigContext mchAppConfigContext){
AliBarOrderRQ bizRQ = (AliBarOrderRQ) rq;
......@@ -71,10 +71,10 @@ public class AliBar extends AlipayPaymentService {
req.setBizModel(model);
//统一放置 isv接口必传信息
AlipayKit.putApiIsvInfo(mchConfigContext, req, model);
AlipayKit.putApiIsvInfo(mchAppConfigContext, req, model);
//调起支付宝 (如果异常, 将直接跑出 ChannelException )
AlipayTradePayResponse alipayResp = mchConfigContext.getAlipayClientWrapper().execute(req);
AlipayTradePayResponse alipayResp = mchAppConfigContext.getAlipayClientWrapper().execute(req);
// 构造函数响应数据
AliBarOrderRS res = ApiResBuilder.buildSuccess(AliBarOrderRS.class);
......
......@@ -29,7 +29,7 @@ import com.jeequan.jeepay.pay.rqrs.payorder.payway.AliJsapiOrderRS;
import com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import com.jeequan.jeepay.pay.util.ApiResBuilder;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
......@@ -55,7 +55,7 @@ public class AliJsapi extends AlipayPaymentService {
}
@Override
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchConfigContext mchConfigContext) throws Exception{
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchAppConfigContext mchAppConfigContext) throws Exception{
AliJsapiOrderRQ bizRQ = (AliJsapiOrderRQ) rq;
......@@ -70,10 +70,10 @@ public class AliJsapi extends AlipayPaymentService {
req.setBizModel(model);
//统一放置 isv接口必传信息
AlipayKit.putApiIsvInfo(mchConfigContext, req, model);
AlipayKit.putApiIsvInfo(mchAppConfigContext, req, model);
//调起支付宝 (如果异常, 将直接跑出 ChannelException )
AlipayTradeCreateResponse alipayResp = mchConfigContext.getAlipayClientWrapper().execute(req);
AlipayTradeCreateResponse alipayResp = mchAppConfigContext.getAlipayClientWrapper().execute(req);
// 构造函数响应数据
AliJsapiOrderRS res = ApiResBuilder.buildSuccess(AliJsapiOrderRS.class);
......
......@@ -24,7 +24,7 @@ import com.jeequan.jeepay.core.utils.AmountUtil;
import com.jeequan.jeepay.pay.channel.alipay.AlipayKit;
import com.jeequan.jeepay.pay.channel.alipay.AlipayPaymentService;
import com.jeequan.jeepay.pay.exception.ChannelException;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.rqrs.AbstractRS;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ;
......@@ -49,7 +49,7 @@ public class AliPc extends AlipayPaymentService {
}
@Override
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchConfigContext mchConfigContext){
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchAppConfigContext mchAppConfigContext){
AliPcOrderRQ bizRQ = (AliPcOrderRQ) rq;
......@@ -66,16 +66,16 @@ public class AliPc extends AlipayPaymentService {
req.setBizModel(model);
//统一放置 isv接口必传信息
AlipayKit.putApiIsvInfo(mchConfigContext, req, model);
AlipayKit.putApiIsvInfo(mchAppConfigContext, req, model);
// 构造函数响应数据
AliPcOrderRS res = ApiResBuilder.buildSuccess(AliPcOrderRS.class);
try {
if(CS.PAY_DATA_TYPE.FORM.equals(bizRQ.getPayDataType())){
res.setFormContent(mchConfigContext.getAlipayClientWrapper().getAlipayClient().pageExecute(req).getBody());
res.setFormContent(mchAppConfigContext.getAlipayClientWrapper().getAlipayClient().pageExecute(req).getBody());
}else{
res.setPayUrl(mchConfigContext.getAlipayClientWrapper().getAlipayClient().pageExecute(req, "GET").getBody());
res.setPayUrl(mchAppConfigContext.getAlipayClientWrapper().getAlipayClient().pageExecute(req, "GET").getBody());
}
}catch (AlipayApiException e) {
throw ChannelException.sysError(e.getMessage());
......
......@@ -23,7 +23,7 @@ import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.core.utils.AmountUtil;
import com.jeequan.jeepay.pay.channel.alipay.AlipayKit;
import com.jeequan.jeepay.pay.channel.alipay.AlipayPaymentService;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.rqrs.AbstractRS;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ;
......@@ -48,7 +48,7 @@ public class AliQr extends AlipayPaymentService {
}
@Override
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchConfigContext mchConfigContext){
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchAppConfigContext mchAppConfigContext){
AliQrOrderRQ aliQrOrderRQ = (AliQrOrderRQ)rq;
......@@ -62,10 +62,10 @@ public class AliQr extends AlipayPaymentService {
req.setBizModel(model);
//统一放置 isv接口必传信息
AlipayKit.putApiIsvInfo(mchConfigContext, req, model);
AlipayKit.putApiIsvInfo(mchAppConfigContext, req, model);
//调起支付宝 (如果异常, 将直接跑出 ChannelException )
AlipayTradePrecreateResponse alipayResp = mchConfigContext.getAlipayClientWrapper().execute(req);
AlipayTradePrecreateResponse alipayResp = mchAppConfigContext.getAlipayClientWrapper().execute(req);
// 构造函数响应数据
AliQrOrderRS res = ApiResBuilder.buildSuccess(AliQrOrderRS.class);
......
......@@ -24,7 +24,7 @@ import com.jeequan.jeepay.core.utils.AmountUtil;
import com.jeequan.jeepay.pay.channel.alipay.AlipayKit;
import com.jeequan.jeepay.pay.channel.alipay.AlipayPaymentService;
import com.jeequan.jeepay.pay.exception.ChannelException;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.rqrs.AbstractRS;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ;
......@@ -49,7 +49,7 @@ public class AliWap extends AlipayPaymentService {
}
@Override
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchConfigContext mchConfigContext){
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchAppConfigContext mchAppConfigContext){
AliWapOrderRQ bizRQ = (AliWapOrderRQ)rq;
......@@ -65,22 +65,22 @@ public class AliWap extends AlipayPaymentService {
req.setBizModel(model);
//统一放置 isv接口必传信息
AlipayKit.putApiIsvInfo(mchConfigContext, req, model);
AlipayKit.putApiIsvInfo(mchAppConfigContext, req, model);
// 构造函数响应数据
AliWapOrderRS res = ApiResBuilder.buildSuccess(AliWapOrderRS.class);
try {
if(CS.PAY_DATA_TYPE.FORM.equals(bizRQ.getPayDataType())){ //表单方式
res.setFormContent(mchConfigContext.getAlipayClientWrapper().getAlipayClient().pageExecute(req).getBody());
res.setFormContent(mchAppConfigContext.getAlipayClientWrapper().getAlipayClient().pageExecute(req).getBody());
}else if (CS.PAY_DATA_TYPE.CODE_IMG_URL.equals(bizRQ.getPayDataType())){ //二维码图片地址
String payUrl = mchConfigContext.getAlipayClientWrapper().getAlipayClient().pageExecute(req, "GET").getBody();
String payUrl = mchAppConfigContext.getAlipayClientWrapper().getAlipayClient().pageExecute(req, "GET").getBody();
res.setCodeImgUrl(sysConfigService.getDBApplicationConfig().genScanImgUrl(payUrl));
}else{ // 默认都为 payUrl方式
res.setPayUrl(mchConfigContext.getAlipayClientWrapper().getAlipayClient().pageExecute(req, "GET").getBody());
res.setPayUrl(mchAppConfigContext.getAlipayClientWrapper().getAlipayClient().pageExecute(req, "GET").getBody());
}
}catch (AlipayApiException e) {
throw ChannelException.sysError(e.getMessage());
......
......@@ -33,7 +33,7 @@ import com.jeequan.jeepay.core.exception.ResponseException;
import com.jeequan.jeepay.pay.channel.AbstractChannelNoticeService;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import com.jeequan.jeepay.pay.service.ConfigContextService;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.service.impl.PayOrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
......@@ -82,13 +82,13 @@ public class WxpayChannelNoticeService extends AbstractChannelNoticeService {
}
//获取支付参数 (缓存数据) 和 商户信息
MchConfigContext mchConfigContext = configContextService.getMchConfigContext(payOrder.getMchNo());
if(mchConfigContext == null){
MchAppConfigContext mchAppConfigContext = configContextService.getMchAppConfigContext(payOrder.getMchNo(), payOrder.getAppId());
if(mchAppConfigContext == null){
throw new BizException("获取商户信息失败");
}
// 验签
if (!verifyNotifySign(request, mchConfigContext)) {
if (!verifyNotifySign(request, mchAppConfigContext)) {
throw new BizException("验签失败");
}
......@@ -100,7 +100,7 @@ public class WxpayChannelNoticeService extends AbstractChannelNoticeService {
String nonce = resource.getString("nonce");
// 解密
String result = AesUtils.decryptToString(associatedData, nonce, cipherText, mchConfigContext.getWxServiceWrapper().getWxPayService().getConfig().getApiV3Key());
String result = AesUtils.decryptToString(associatedData, nonce, cipherText, mchAppConfigContext.getWxServiceWrapper().getWxPayService().getConfig().getApiV3Key());
JSONObject decryptJSON = JSONObject.parseObject(result);
return MutablePair.of(decryptJSON.getString("out_trade_no"), decryptJSON);
......@@ -121,16 +121,16 @@ public class WxpayChannelNoticeService extends AbstractChannelNoticeService {
}
@Override
public ChannelRetMsg doNotice(HttpServletRequest request, Object params, PayOrder payOrder, MchConfigContext mchConfigContext, NoticeTypeEnum noticeTypeEnum) {
public ChannelRetMsg doNotice(HttpServletRequest request, Object params, PayOrder payOrder, MchAppConfigContext mchAppConfigContext, NoticeTypeEnum noticeTypeEnum) {
try {
ChannelRetMsg channelResult = new ChannelRetMsg();
channelResult.setChannelState(ChannelRetMsg.ChannelState.WAITING); // 默认支付中
if (CS.PAY_IF_VERSION.WX_V2.equals(mchConfigContext.getWxServiceWrapper().getApiVersion())) { // V2
if (CS.PAY_IF_VERSION.WX_V2.equals(mchAppConfigContext.getWxServiceWrapper().getApiVersion())) { // V2
// 获取回调参数
WxPayOrderNotifyResult result = (WxPayOrderNotifyResult) params;
WxPayService wxPayService = mchConfigContext.getWxServiceWrapper().getWxPayService();
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
// 验证参数
verifyWxPayParams(wxPayService, result, payOrder);
......@@ -139,7 +139,7 @@ public class WxpayChannelNoticeService extends AbstractChannelNoticeService {
channelResult.setChannelUserId(result.getOpenid()); //支付用户ID
channelResult.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_SUCCESS);
}else if (CS.PAY_IF_VERSION.WX_V3.equals(mchConfigContext.getWxServiceWrapper().getApiVersion())) { // V3
}else if (CS.PAY_IF_VERSION.WX_V3.equals(mchAppConfigContext.getWxServiceWrapper().getApiVersion())) { // V3
// 获取回调参数
JSONObject resultJSON = (JSONObject) params;
......@@ -200,10 +200,10 @@ public class WxpayChannelNoticeService extends AbstractChannelNoticeService {
/**
* V3校验通知签名
* @param request 请求信息
* @param mchConfigContext 商户配置
* @param mchAppConfigContext 商户配置
* @return true:校验通过 false:校验不通过
*/
private boolean verifyNotifySign(HttpServletRequest request, MchConfigContext mchConfigContext) throws Exception {
private boolean verifyNotifySign(HttpServletRequest request, MchAppConfigContext mchAppConfigContext) throws Exception {
SignatureHeader header = new SignatureHeader();
header.setTimeStamp(request.getHeader("Wechatpay-Timestamp"));
header.setNonce(request.getHeader("Wechatpay-Nonce"));
......@@ -215,7 +215,7 @@ public class WxpayChannelNoticeService extends AbstractChannelNoticeService {
header.getNonce(),
getReqParamJSON().toJSONString());
WxPayConfig wxPayConfig = mchConfigContext.getWxServiceWrapper().getWxPayService().getConfig();
WxPayConfig wxPayConfig = mchAppConfigContext.getWxServiceWrapper().getWxPayService().getConfig();
// 自动获取微信平台证书
PrivateKey privateKey = PemUtils.loadPrivateKey(new FileInputStream(wxPayConfig.getPrivateKeyPath()));
AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
......
......@@ -20,7 +20,7 @@ import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.model.params.wxpay.WxpayIsvParams;
import com.jeequan.jeepay.core.model.params.wxpay.WxpayNormalMchParams;
import com.jeequan.jeepay.pay.channel.IChannelUserService;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.StringUtils;
......@@ -46,17 +46,17 @@ public class WxpayChannelUserService implements IChannelUserService {
}
@Override
public String buildUserRedirectUrl(String callbackUrlEncode, MchConfigContext mchConfigContext) {
public String buildUserRedirectUrl(String callbackUrlEncode, MchAppConfigContext mchAppConfigContext) {
String appId = null;
String oauth2Url = "";
if(mchConfigContext.isIsvsubMch()){
WxpayIsvParams wxpayIsvParams = mchConfigContext.getIsvConfigContext().getIsvParamsByIfCode(CS.IF_CODE.WXPAY, WxpayIsvParams.class);
if(mchAppConfigContext.isIsvsubMch()){
WxpayIsvParams wxpayIsvParams = mchAppConfigContext.getIsvConfigContext().getIsvParamsByIfCode(CS.IF_CODE.WXPAY, WxpayIsvParams.class);
appId = wxpayIsvParams.getAppId();
oauth2Url = wxpayIsvParams.getOauth2Url();
}else{
//获取商户配置信息
WxpayNormalMchParams normalMchParams = mchConfigContext.getNormalMchParamsByIfCode(CS.IF_CODE.WXPAY, WxpayNormalMchParams.class);
WxpayNormalMchParams normalMchParams = mchAppConfigContext.getNormalMchParamsByIfCode(CS.IF_CODE.WXPAY, WxpayNormalMchParams.class);
appId = normalMchParams.getAppId();
oauth2Url = normalMchParams.getOauth2Url();
}
......@@ -69,10 +69,10 @@ public class WxpayChannelUserService implements IChannelUserService {
}
@Override
public String getChannelUserId(JSONObject reqParams, MchConfigContext mchConfigContext) {
public String getChannelUserId(JSONObject reqParams, MchAppConfigContext mchAppConfigContext) {
String code = reqParams.getString("code");
try {
return mchConfigContext.getWxServiceWrapper().getWxMpService().getOAuth2Service().getAccessToken(code).getOpenId();
return mchAppConfigContext.getWxServiceWrapper().getWxMpService().getOAuth2Service().getAccessToken(code).getOpenId();
} catch (WxErrorException e) {
e.printStackTrace();
return null;
......
......@@ -25,7 +25,7 @@ import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.pay.channel.IPayOrderQueryService;
import com.jeequan.jeepay.pay.channel.wxpay.kits.WxpayKit;
import com.jeequan.jeepay.pay.channel.wxpay.kits.WxpayV3Util;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import org.springframework.stereotype.Service;
......@@ -45,20 +45,20 @@ public class WxpayPayOrderQueryService implements IPayOrderQueryService {
}
@Override
public ChannelRetMsg query(PayOrder payOrder, MchConfigContext mchConfigContext) {
public ChannelRetMsg query(PayOrder payOrder, MchAppConfigContext mchAppConfigContext) {
try {
if (CS.PAY_IF_VERSION.WX_V2.equals(mchConfigContext.getWxServiceWrapper().getApiVersion())) { //V2
if (CS.PAY_IF_VERSION.WX_V2.equals(mchAppConfigContext.getWxServiceWrapper().getApiVersion())) { //V2
WxPayOrderQueryRequest req = new WxPayOrderQueryRequest();
//放置isv信息
WxpayKit.putApiIsvInfo(mchConfigContext, req);
WxpayKit.putApiIsvInfo(mchAppConfigContext, req);
req.setOutTradeNo(payOrder.getPayOrderId());
WxPayService wxPayService = mchConfigContext.getWxServiceWrapper().getWxPayService();
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
WxPayOrderQueryResult result = wxPayService.queryOrder(req);
......@@ -74,9 +74,9 @@ public class WxpayPayOrderQueryService implements IPayOrderQueryService {
return ChannelRetMsg.unknown();
}
}else if (CS.PAY_IF_VERSION.WX_V3.equals(mchConfigContext.getWxServiceWrapper().getApiVersion())) { //V3
}else if (CS.PAY_IF_VERSION.WX_V3.equals(mchAppConfigContext.getWxServiceWrapper().getApiVersion())) { //V3
JSONObject resultJSON = WxpayV3Util.queryOrderV3(payOrder.getPayOrderId(), mchConfigContext.getWxServiceWrapper().getWxPayService().getConfig());
JSONObject resultJSON = WxpayV3Util.queryOrderV3(payOrder.getPayOrderId(), mchAppConfigContext.getWxServiceWrapper().getWxPayService().getConfig());
String channelState = resultJSON.getString("trade_state");
if ("SUCCESS".equals(channelState)) {
......
......@@ -26,7 +26,7 @@ import com.jeequan.jeepay.pay.channel.AbstractPaymentService;
import com.jeequan.jeepay.pay.rqrs.AbstractRS;
import com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ;
import com.jeequan.jeepay.pay.util.PaywayUtil;
import com.jeequan.jeepay.pay.model.MchConfigContext;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import org.springframework.stereotype.Service;
/*
......@@ -56,14 +56,14 @@ public class WxpayPaymentService extends AbstractPaymentService {
}
@Override
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchConfigContext mchConfigContext) throws Exception {
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchAppConfigContext mchAppConfigContext) throws Exception {
// 微信API版本
String apiVersion = mchConfigContext.getWxServiceWrapper().getApiVersion();
String apiVersion = mchAppConfigContext.getWxServiceWrapper().getApiVersion();
if (CS.PAY_IF_VERSION.WX_V2.equals(apiVersion)) {
return PaywayUtil.getRealPaywayService(this, payOrder.getWayCode()).pay(rq, payOrder, mchConfigContext);
return PaywayUtil.getRealPaywayService(this, payOrder.getWayCode()).pay(rq, payOrder, mchAppConfigContext);
} else if (CS.PAY_IF_VERSION.WX_V3.equals(apiVersion)) {
return PaywayUtil.getRealPaywayV3Service(this, payOrder.getWayCode()).pay(rq, payOrder, mchConfigContext);
return PaywayUtil.getRealPaywayV3Service(this, payOrder.getWayCode()).pay(rq, payOrder, mchAppConfigContext);
} else {
throw new BizException("不支持的微信支付API版本");
}
......@@ -75,7 +75,7 @@ public class WxpayPaymentService extends AbstractPaymentService {
* @param payOrder
* @return
*/
public WxPayUnifiedOrderRequest buildUnifiedOrderRequest(PayOrder payOrder, MchConfigContext mchConfigContext) {
public WxPayUnifiedOrderRequest buildUnifiedOrderRequest(PayOrder payOrder, MchAppConfigContext mchAppConfigContext) {
String payOrderId = payOrder.getPayOrderId();
// 微信统一下单请求对象
......@@ -90,8 +90,8 @@ public class WxpayPaymentService extends AbstractPaymentService {
request.setProductId(System.currentTimeMillis()+"");
// 特约商户
if(mchConfigContext.isIsvsubMch()){
WxpayIsvsubMchParams isvsubMchParams = mchConfigContext.getIsvsubMchParamsByIfCode(getIfCode(), WxpayIsvsubMchParams.class);
if(mchAppConfigContext.isIsvsubMch()){
WxpayIsvsubMchParams isvsubMchParams = mchAppConfigContext.getIsvsubMchParamsByIfCode(getIfCode(), WxpayIsvsubMchParams.class);
request.setSubMchId(isvsubMchParams.getSubMchId());
request.setSubAppId(isvsubMchParams.getSubMchAppId());
}
......@@ -104,7 +104,7 @@ public class WxpayPaymentService extends AbstractPaymentService {
* @param payOrder
* @return
*/
public JSONObject buildV3OrderRequest(PayOrder payOrder, MchConfigContext mchConfigContext) {
public JSONObject buildV3OrderRequest(PayOrder payOrder, MchAppConfigContext mchAppConfigContext) {
String payOrderId = payOrder.getPayOrderId();
// 微信统一下单请求对象
......@@ -122,9 +122,9 @@ public class WxpayPaymentService extends AbstractPaymentService {
sceneInfo.put("payer_client_ip", payOrder.getClientIp());
reqJSON.put("scene_info", sceneInfo);
WxPayService wxPayService = mchConfigContext.getWxServiceWrapper().getWxPayService();
if(mchConfigContext.isIsvsubMch()){ // 特约商户
WxpayIsvsubMchParams isvsubMchParams = mchConfigContext.getIsvsubMchParamsByIfCode(getIfCode(), WxpayIsvsubMchParams.class);
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
if(mchAppConfigContext.isIsvsubMch()){ // 特约商户
WxpayIsvsubMchParams isvsubMchParams = mchAppConfigContext.getIsvsubMchParamsByIfCode(getIfCode(), WxpayIsvsubMchParams.class);
reqJSON.put("sp_appid", wxPayService.getConfig().getAppId());
reqJSON.put("sp_mchid", wxPayService.getConfig().getMchId());
reqJSON.put("sub_mchid", isvsubMchParams.getSubMchId());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment