优化微信H5支付支持同步跳转

This commit is contained in:
zhuxiao 2022-07-28 10:45:53 +08:00
parent 1d19023a48
commit 54cb88c6ad
5 changed files with 53 additions and 5 deletions

View File

@ -112,6 +112,8 @@ public class CS {
return String.format(CACHE_KEY_IMG_CODE, imgToken);
}
/** 回调URL的格前缀 */
public static final String PAY_RETURNURL_FIX_ONLY_JUMP_PREFIX = "ONLYJUMP_";
/** 登录认证类型 **/
public interface AUTH_TYPE{

View File

@ -16,6 +16,7 @@
package com.jeequan.jeepay.pay.channel;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.pay.service.ConfigContextQueryService;
import com.jeequan.jeepay.pay.util.ChannelCertConfigKitBean;
@ -60,4 +61,8 @@ public abstract class AbstractPaymentService implements IPaymentService{
return sysConfigService.getDBApplicationConfig().getPaySiteUrl() + "/api/pay/return/" + getIfCode() + "/" + payOrderId;
}
protected String getReturnUrlOnlyJump(String payOrderId){
return sysConfigService.getDBApplicationConfig().getPaySiteUrl() + "/api/pay/return/" + getIfCode() + "/" + CS.PAY_RETURNURL_FIX_ONLY_JUMP_PREFIX + payOrderId;
}
}

View File

@ -16,6 +16,7 @@
package com.jeequan.jeepay.pay.channel.wxpay.payway;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.net.URLEncodeUtil;
import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult;
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
import com.github.binarywang.wxpay.constant.WxPayConstants;
@ -74,8 +75,10 @@ public class WxH5 extends WxpayPaymentService {
try {
WxPayMwebOrderResult wxPayMwebOrderResult = wxPayService.createOrder(req);
String payUrl = wxPayMwebOrderResult.getMwebUrl();
payUrl = sysConfigService.getDBApplicationConfig().getPaySiteUrl() + "/api/common/payUrl/" + Base64.encode(payUrl);
// 拼接returnUrl
String payUrl = String.format("%s&redirect_url=%s", wxPayMwebOrderResult.getMwebUrl(), URLEncodeUtil.encode(getReturnUrlOnlyJump(payOrder.getPayOrderId())));
payUrl = String.format("%s/api/common/payUrl/%s", sysConfigService.getDBApplicationConfig().getPaySiteUrl(), Base64.encode(payUrl));
if(CS.PAY_DATA_TYPE.FORM.equals(bizRQ.getPayDataType())){ //表单方式
res.setFormContent(payUrl);

View File

@ -16,6 +16,7 @@
package com.jeequan.jeepay.pay.channel.wxpay.paywayV3;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.net.URLEncodeUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.exception.WxPayException;
@ -88,8 +89,11 @@ public class WxH5 extends WxpayPaymentService {
try {
JSONObject resJSON = WxpayV3Util.unifiedOrderV3(reqUrl, reqJSON, wxPayService);
String payUrl = resJSON.getString("h5_url");
payUrl = sysConfigService.getDBApplicationConfig().getPaySiteUrl() + "/api/common/payUrl/" + Base64.encode(payUrl);
// 拼接returnUrl
String payUrl = String.format("%s&redirect_url=%s", resJSON.getString("h5_url"), URLEncodeUtil.encode(getReturnUrlOnlyJump(payOrder.getPayOrderId())));
payUrl = String.format("%s/api/common/payUrl/%s", sysConfigService.getDBApplicationConfig().getPaySiteUrl(), Base64.encode(payUrl));
if (CS.PAY_DATA_TYPE.CODE_IMG_URL.equals(bizRQ.getPayDataType())){ //二维码图片地址
res.setCodeImgUrl(sysConfigService.getDBApplicationConfig().genScanImgUrl(payUrl));
}else{ // 默认都为 payUrl方式

View File

@ -15,6 +15,7 @@
*/
package com.jeequan.jeepay.pay.ctrl.payorder;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.ctrls.AbstractCtrl;
import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.core.exception.BizException;
@ -39,6 +40,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
/*
* 渠道侧的通知入口Controller 分为同步跳转doReturn和异步回调(doNotify)
@ -56,7 +58,11 @@ public class ChannelNoticeController extends AbstractCtrl {
@Autowired private PayMchNotifyService payMchNotifyService;
@Autowired private PayOrderProcessService payOrderProcessService;
/** 同步通知入口 **/
/**
* 同步通知入口
*
* payOrderId 前缀为 ONLYJUMP_表示直接跳转
**/
@RequestMapping(value= {"/api/pay/return/{ifCode}", "/api/pay/return/{ifCode}/{payOrderId}"})
public String doReturn(HttpServletRequest request, @PathVariable("ifCode") String ifCode, @PathVariable(value = "payOrderId", required = false) String urlOrderId){
@ -80,6 +86,9 @@ public class ChannelNoticeController extends AbstractCtrl {
return this.toReturnPage("[" + ifCode + "] interface not exists");
}
// 仅做跳转直接跳转订单的returnUrl
onlyJump(urlOrderId, logPrefix);
// 解析订单号 请求参数
MutablePair<String, Object> mutablePair = payNotifyService.parseParams(request, urlOrderId, IChannelNoticeService.NoticeTypeEnum.DO_RETURN);
if(mutablePair == null){ // 解析数据失败 响应已处理
@ -268,4 +277,29 @@ public class ChannelNoticeController extends AbstractCtrl {
return "cashier/returnPage";
}
private void onlyJump(String urlOrderId, String logPrefix) throws IOException {
if (StringUtils.isNotBlank(urlOrderId) && urlOrderId.startsWith(CS.PAY_RETURNURL_FIX_ONLY_JUMP_PREFIX)) {
String payOrderId = urlOrderId.substring(CS.PAY_RETURNURL_FIX_ONLY_JUMP_PREFIX.length());
//获取订单号 订单数据
PayOrder payOrder = payOrderService.getById(payOrderId);
// 订单不存在
if(payOrder == null){
log.error("{}, 订单不存在. payOrderId={} ", logPrefix, payOrderId);
this.toReturnPage("支付订单不存在");
}
//查询出商户应用的配置信息
MchAppConfigContext mchAppConfigContext = configContextQueryService.queryMchInfoAndAppInfo(payOrder.getMchNo(), payOrder.getAppId());
if (StringUtils.isBlank(payOrder.getReturnUrl())) {
this.toReturnPage(null);
}
response.sendRedirect(payMchNotifyService.createReturnUrl(payOrder, mchAppConfigContext.getMchApp().getAppSecret()));
}
}
}