123
This commit is contained in:
@@ -32,6 +32,7 @@ import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.helper.LoginHelper;
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.sun.org.apache.bcel.internal.generic.RETURN;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -304,77 +305,29 @@ public class PayController {
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/trd/notify/v1")
|
||||
@PostMapping(value = "/trd/notify/{type}")
|
||||
@Operation(hidden = true)
|
||||
@Log(title = "第三方支付回调V1", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||
@Log(title = "第三方支付回调", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||
@SaIgnore
|
||||
public String trdNotifyUrlV1(HttpServletRequest request) {
|
||||
public String trdNotifyUrlV1(HttpServletRequest request,@PathVariable("type") String type) {
|
||||
try {
|
||||
TrdPayTypeEnum trdPayTypeEnum = TrdPayTypeEnum.getByCode(type);
|
||||
if(trdPayTypeEnum == null){
|
||||
log.error("收到第三方支付回调,未找到支付类型 type={}",type);
|
||||
return "failure";
|
||||
}
|
||||
Map<String, String> params = AliPayApi.toMap(request);
|
||||
log.info("第三方支付回调V1:{}",JSON.toJSONString(params));
|
||||
NotifyResp notifyResp = trdPayManager.getNotifyResp(params, TrdPayTypeEnum.V1);
|
||||
log.info("收到第三方支付回调 {}:{}",trdPayTypeEnum.name(), JSON.toJSONString(params));
|
||||
NotifyResp notifyResp = trdPayManager.getNotifyResp(params, trdPayTypeEnum);
|
||||
if(!notifyResp.isSuccess()){
|
||||
return "failure";
|
||||
}
|
||||
payManager.callBack(notifyResp.getOrderNo(),notifyResp.getTrdOrderNo(),params,notifyResp.getPayTypeEnum().name(), PayTypeEnum.TRD);
|
||||
return "success";
|
||||
return trdPayTypeEnum.getNotifyResp();
|
||||
} catch (Exception e) {
|
||||
log.error("第三方支付回调失败V1!",e);
|
||||
log.error("第三方支付回调失败! type={}",type, e);
|
||||
return "failure";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/trd/notify/v2")
|
||||
@Operation(hidden = true)
|
||||
@Log(title = "第三方支付回调V2", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||
@SaIgnore
|
||||
public String trdNotifyUrlV2(HttpServletRequest request) {
|
||||
try {
|
||||
Map<String, String> params = AliPayApi.toMap(request);
|
||||
log.info("第三方支付回调V2:{}",JSON.toJSONString(params));
|
||||
NotifyResp notifyResp = trdPayManager.getNotifyResp(params, TrdPayTypeEnum.V2);
|
||||
payManager.callBack(notifyResp.getOrderNo(),notifyResp.getTrdOrderNo(),params,notifyResp.getPayTypeEnum().name(), PayTypeEnum.TRD);
|
||||
return "success";
|
||||
} catch (Exception e) {
|
||||
log.error("第三方支付回调失败V2!",e);
|
||||
return "failure";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/trd/notify/v3")
|
||||
@Operation(hidden = true)
|
||||
@Log(title = "第三方支付回调V3", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||
@SaIgnore
|
||||
public String trdNotifyUrlV3(HttpServletRequest request) {
|
||||
try {
|
||||
Map<String, String> params = AliPayApi.toMap(request);
|
||||
log.info("第三方支付回调V3:{}",JSON.toJSONString(params));
|
||||
NotifyResp notifyResp = trdPayManager.getNotifyResp(params, TrdPayTypeEnum.V3);
|
||||
payManager.callBack(notifyResp.getOrderNo(),notifyResp.getTrdOrderNo(),params,notifyResp.getPayTypeEnum().name(), PayTypeEnum.TRD);
|
||||
return "success";
|
||||
} catch (Exception e) {
|
||||
log.error("第三方支付回调失败V3!",e);
|
||||
return "failure";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/trd/notify/v4")
|
||||
@Operation(hidden = true)
|
||||
@Log(title = "第三方支付回调V4", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||
@SaIgnore
|
||||
public String trdNotifyUrlV4(HttpServletRequest request) {
|
||||
try {
|
||||
Map<String, String> params = AliPayApi.toMap(request);
|
||||
log.info("第三方支付回调V4:{}",JSON.toJSONString(params));
|
||||
NotifyResp notifyResp = trdPayManager.getNotifyResp(params, TrdPayTypeEnum.V4);
|
||||
payManager.callBack(notifyResp.getOrderNo(),notifyResp.getTrdOrderNo(),params,notifyResp.getPayTypeEnum().name(), PayTypeEnum.TRD);
|
||||
return "success";
|
||||
} catch (Exception e) {
|
||||
log.error("第三方支付回调失败V4!",e);
|
||||
return "failure";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -20,4 +20,16 @@ public class PayMd5Util {
|
||||
url.add("sign=" + sign);
|
||||
return StringUtils.join(url, "&");
|
||||
}
|
||||
|
||||
public static String createParams(Map<String, String> params, String key,String signName) {
|
||||
List<String> url = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
url.add(entry.getKey() + "=" + entry.getValue());
|
||||
}
|
||||
url = url.stream().sorted().collect(Collectors.toList());
|
||||
String stringSignTemp = StringUtils.join(url, "&") + "&key=" + key;
|
||||
String sign = DigestUtil.md5Hex(stringSignTemp).toUpperCase();
|
||||
url.add(signName + "=" + sign);
|
||||
return StringUtils.join(url, "&");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,21 +5,80 @@ import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum TrdPayTypeEnum {
|
||||
V1("http://pay.jpay.one/api","/pay/create_order","/pay/query_order","/api/pay/trd/notify/v1"),
|
||||
V2("http://121.40.24.67:56700/api","/pay/create_order","/pay/query_order","/api/pay/trd/notify/v2"),
|
||||
V3("http://pay.linken.click/api","/pay/create_order","/pay/query_order","/api/pay/trd/notify/v3"),
|
||||
V4("http://47.243.172.120:8089","/channel/apiPay","/channel/order/query","/api/pay/trd/notify/v4"),
|
||||
V1("http://pay.jpay.one/api","/pay/create_order","/pay/query_order","/api/pay/trd/notify/v1","success"),
|
||||
V2("http://121.40.24.67:56700/api","/pay/create_order","/pay/query_order","/api/pay/trd/notify/v2","success"),
|
||||
/**
|
||||
* 商户后台: http://me.linken.click (http://me.linken.click/)
|
||||
*
|
||||
* 商户ID:10097
|
||||
*
|
||||
* 密钥:J6UV81O9XTYOMAWJDGT1TM3FNLZ3E1Z8F2V2RFZOWQZ44SVUNKL3BWCRUAYCFL2ONIHFF8PUIHVF3ANZF4OVJG4RUQWBMYUOVUQBIC4YHUVTLEHTLRLFLW1GS1DJ3YQA
|
||||
*
|
||||
* 账号:hx
|
||||
*
|
||||
* 商戶密码默认是 pay666666 支付密码默认是 pay888888
|
||||
*
|
||||
* 测试编码:8004 金额:10
|
||||
*
|
||||
* 文档: http://me.linken.click/x_mch/src/views/dev/pay_doc/pay.html
|
||||
* 下单网关: http://pay.linken.click/api/pay/create_order
|
||||
* 查询网关: http://pay.linken.click/api/pay/query_order
|
||||
* 回调IP: 52.193.29.207 (https://52.193.29.207/)
|
||||
*/
|
||||
V3("http://pay.linken.click/api","/pay/create_order","/pay/query_order","/api/pay/trd/notify/v3","success"),
|
||||
/**
|
||||
* 商户ID:M1734633094653907
|
||||
* 后台登录账号:huaxiang001
|
||||
* 密钥:00d7411fbc8542b786c91d446c361ffb
|
||||
* 后台登录密码:qq123123
|
||||
* 文档下载地址:http://47.243.172.120:8089/fileDownload/doc
|
||||
* 下单地址:http://47.243.172.120:8089//channel/apiPay
|
||||
* 查单地址:http://47.243.172.120:8089//channel/order/query
|
||||
* 回调IP:47.243.172.120
|
||||
* 后台地址:http://47.243.172.120:8099/
|
||||
* tradeType:ALIPAY_H5
|
||||
*/
|
||||
V4("http://47.243.172.120:8089","/channel/apiPay","/channel/order/query","/api/pay/trd/notify/v4","success"),
|
||||
/**
|
||||
* 下单网关:http://ybax.guanghui.sgzhfu.com/Pay_Index.html
|
||||
* 查询网关:http://ybax.guanghui.sgzhfu.com/Pay_Trade_query.html
|
||||
* 商户登录地址:http://ybax.guanghui.sgzhfu.com/user.html
|
||||
* 用户名:花花
|
||||
* 密码和登录密码默认:123456
|
||||
* 回调IP:8.217.109.149
|
||||
* 商务号:241288099
|
||||
* 秘钥:69i3orn6idkvbopr42s3f4aaldhybzmr
|
||||
* 对接文档:http://ybax.guanghui.sgzhfu.com/api.pdf
|
||||
* 支付宝编码 8000
|
||||
*/
|
||||
V5("http://ybax.guanghui.sgzhfu.com","/Pay_Index.html","/Pay_Trade_query.html","/api/pay/trd/notify/v5","OK"),
|
||||
/**
|
||||
* 商户后台:http://ydme.blzf.cc
|
||||
* 登录账号:hx666888
|
||||
* 登录密码:pay666666
|
||||
*
|
||||
* 对接信息
|
||||
* 商户ID:20000004
|
||||
* 密钥:DI7BQKRI6FP2OOUMB6F5PKHGTBZYKJ1E7NRED1SEG3WOX9RMJPNYHLTYQYPEUBBLKIBKNDQYNUQGLMMKSI7PJ7V8NUBK9QYSIEC6XX3X05EU62BLNP03DZR5VR0PEWOH
|
||||
* 下单地址:https://ydwg.blzf.cc/api/pay/create_order
|
||||
* 查询地址:https://ydwg.blzf.cc/api/pay/query_order
|
||||
* 对接文档:http://ydme.blzf.cc/x_mch/src/views/dev/pay_doc/pay.html
|
||||
* 通道编码:8010
|
||||
*/
|
||||
V6("https://ydwg.blzf.cc","/api/pay/create_order","/api/pay/query_order","/api/pay/trd/notify/v6","success"),
|
||||
;
|
||||
private final String gatewayUrl;
|
||||
private final String createOrderUrl;
|
||||
private final String queryOrderUrl;
|
||||
private final String notifyPath;
|
||||
private final String notifyResp;
|
||||
|
||||
TrdPayTypeEnum(String gatewayUrl, String createOrderUrl, String queryOrderUrl, String notifyPath) {
|
||||
TrdPayTypeEnum(String gatewayUrl, String createOrderUrl, String queryOrderUrl, String notifyPath, String notifyResp) {
|
||||
this.gatewayUrl = gatewayUrl;
|
||||
this.createOrderUrl = createOrderUrl;
|
||||
this.queryOrderUrl = queryOrderUrl;
|
||||
this.notifyPath = notifyPath;
|
||||
this.notifyResp = notifyResp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,4 +11,5 @@ public class NotifyResp {
|
||||
private String trdOrderNo;
|
||||
private TrdPayTypeEnum payTypeEnum;
|
||||
private Map<String,String> sourceData;
|
||||
private boolean success;
|
||||
}
|
||||
|
||||
@@ -75,11 +75,13 @@ public class PayTrdV1Service implements PayTrdService {
|
||||
public NotifyResp getNotifyResp(Map<String, String> sourceData) {
|
||||
String mchOrderNo = sourceData.get("mchOrderNo");
|
||||
String payOrderId = sourceData.get("payOrderId");
|
||||
String status = sourceData.get("status");
|
||||
NotifyResp resp = new NotifyResp();
|
||||
resp.setOrderNo(mchOrderNo);
|
||||
resp.setTrdOrderNo(payOrderId);
|
||||
resp.setPayTypeEnum(getType());
|
||||
resp.setSourceData(sourceData);
|
||||
resp.setSuccess("2".equals(status));
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,11 +74,13 @@ public class PayTrdV3Service implements PayTrdService {
|
||||
public NotifyResp getNotifyResp(Map<String, String> sourceData) {
|
||||
String mchOrderNo = sourceData.get("mchOrderNo");
|
||||
String payOrderId = sourceData.get("payOrderId");
|
||||
String status = sourceData.get("status");
|
||||
NotifyResp resp = new NotifyResp();
|
||||
resp.setOrderNo(mchOrderNo);
|
||||
resp.setTrdOrderNo(payOrderId);
|
||||
resp.setPayTypeEnum(getType());
|
||||
resp.setSourceData(sourceData);
|
||||
resp.setSuccess("2".equals(status));
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,11 +74,13 @@ public class PayTrdV4Service implements PayTrdService {
|
||||
public NotifyResp getNotifyResp(Map<String, String> sourceData) {
|
||||
String mchOrderNo = sourceData.get("merchantPayNo");
|
||||
String payOrderId = sourceData.get("payNo");
|
||||
String status = sourceData.get("tradeStatus");
|
||||
NotifyResp resp = new NotifyResp();
|
||||
resp.setOrderNo(mchOrderNo);
|
||||
resp.setTrdOrderNo(payOrderId);
|
||||
resp.setPayTypeEnum(getType());
|
||||
resp.setSourceData(sourceData);
|
||||
resp.setSuccess("1".equals(status));
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.ruoyi.cai.trdpay.handle;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.api.client.util.SecurityUtils;
|
||||
import com.ruoyi.cai.domain.PayTrdConfig;
|
||||
import com.ruoyi.cai.pay.PayManager;
|
||||
import com.ruoyi.cai.pay.PayOrderInfoDTO;
|
||||
import com.ruoyi.cai.pay.PayReturnResp;
|
||||
import com.ruoyi.cai.service.OrderLogsService;
|
||||
import com.ruoyi.cai.trdpay.PayMd5Util;
|
||||
import com.ruoyi.cai.trdpay.PayTrdService;
|
||||
import com.ruoyi.cai.trdpay.TrdPayTypeEnum;
|
||||
import com.ruoyi.cai.trdpay.dto.NotifyResp;
|
||||
import com.ruoyi.cai.util.RestTemplateUtil;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.helper.LoginHelper;
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PayTrdV5Service implements PayTrdService {
|
||||
|
||||
@Autowired
|
||||
private OrderLogsService orderLogsService;
|
||||
@Autowired
|
||||
private PayManager payManager;
|
||||
|
||||
@Override
|
||||
public TrdPayTypeEnum getType() {
|
||||
return TrdPayTypeEnum.V5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PayReturnResp createOrderAli(PayOrderInfoDTO payOrderInfoDTO, PayTrdConfig payTrdConfig) {
|
||||
TrdPayTypeEnum type = getType();
|
||||
RestTemplate rest = RestTemplateUtil.getRest();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("pay_memberid", payTrdConfig.getMchId());
|
||||
params.put("pay_orderid", payOrderInfoDTO.getOrderNo());
|
||||
params.put("pay_bankcode", payTrdConfig.getAliProductId());
|
||||
params.put("pay_applydate", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
params.put("pay_amount", payOrderInfoDTO.getPrice().toString());
|
||||
String notifyUrl = payTrdConfig.getNotifyUrl() + type.getNotifyPath();
|
||||
params.put("pay_notifyurl", notifyUrl);
|
||||
params.put("pay_productname",payOrderInfoDTO.getBody());
|
||||
params.put("pay_ip", ServletUtils.getClientIP());
|
||||
params.put("pay_userid", LoginHelper.getUserId()+"");
|
||||
String para = PayMd5Util.createParams(params, payTrdConfig.getSign(), "pay_md5sign");
|
||||
String gatewayUrl = type.getGatewayUrl();
|
||||
if (StringUtils.isNotBlank(payTrdConfig.getGatewayUrl())) {
|
||||
gatewayUrl = payTrdConfig.getGatewayUrl();
|
||||
}
|
||||
String createOrderUrl = gatewayUrl + type.getCreateOrderUrl();
|
||||
String url = createOrderUrl + "?" + para;
|
||||
String body = rest.postForObject(url, null, String.class);
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
orderLogsService.createAliPayLogs(payOrderInfoDTO.getOrderNo(), url, jsonObject, type);
|
||||
if(jsonObject == null){
|
||||
log.error("第三方支付失败 V5 返回数据为空 url={}",url);
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
if(!"1".equals(jsonObject.getString("status"))){
|
||||
log.info("第三方支付失败 V5 统一支付失败失败 url={} body={}, payTrdConfig={}, typeEnum={}", url, body, JSON.toJSONString(payTrdConfig), JSON.toJSONString(jsonObject));
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
String payUrl = jsonObject.getString("h5_url");
|
||||
return PayReturnResp.createH5(payUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NotifyResp getNotifyResp(Map<String, String> sourceData) {
|
||||
String mchOrderNo = sourceData.get("orderid");
|
||||
String payOrderId = sourceData.get("transaction_id");
|
||||
String status = sourceData.get("returncode");
|
||||
NotifyResp resp = new NotifyResp();
|
||||
resp.setOrderNo(mchOrderNo);
|
||||
resp.setTrdOrderNo(payOrderId);
|
||||
resp.setPayTypeEnum(getType());
|
||||
resp.setSourceData(sourceData);
|
||||
resp.setSuccess("00".equals(status));
|
||||
return resp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject queryOrder(String orderNo, PayTrdConfig payTrdConfig) {
|
||||
TrdPayTypeEnum type = getType();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("merchantId", payTrdConfig.getMchId());
|
||||
params.put("merchantPayNo", orderNo);
|
||||
String para = PayMd5Util.createParams(params,payTrdConfig.getSign());
|
||||
String gatewayUrl = type.getGatewayUrl();
|
||||
if(StringUtils.isNotBlank(payTrdConfig.getGatewayUrl())){
|
||||
gatewayUrl = payTrdConfig.getGatewayUrl();
|
||||
}
|
||||
String queryOrderUrl = gatewayUrl + type.getQueryOrderUrl();
|
||||
String url = queryOrderUrl + "?" + para;
|
||||
String body = RestTemplateUtil.getRest().getForEntity(url, String.class).getBody();
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
if(jsonObject == null){
|
||||
log.error("第三方支付查询失败 返回数据为空 URL={}",url);
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
log.info("第三方支付查询成功 V5 URL={}, body={}",url, body);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject resetOrder(String orderNo, PayTrdConfig payTrdConfig, boolean updateData) {
|
||||
throw new ServiceException("V5不支持订单查询");
|
||||
/*JSONObject jsonObject = this.queryOrder(orderNo,payTrdConfig);
|
||||
if(!"SUCCESS".equals(jsonObject.getString("retCode"))){
|
||||
log.info("第三方支付失败 V5统一支付失败失败 orderNo={}, payTrdConfig={}", orderNo, JSON.toJSONString(payTrdConfig));
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
Integer status = jsonObject.getInteger("status");
|
||||
if(status != null && status.equals(1)){
|
||||
String mchOrderNo = jsonObject.getString("mchOrderNo");
|
||||
String payOrderId = jsonObject.getString("payOrderId");
|
||||
String productId = jsonObject.getString("productId");
|
||||
Map<String,String> objectJson = new HashMap<>();
|
||||
for (String key : jsonObject.keySet()) {
|
||||
objectJson.put(key, jsonObject.getString(key));
|
||||
}
|
||||
if(updateData){
|
||||
payManager.callBack(mchOrderNo,payOrderId,objectJson,"V5", PayTypeEnum.TRD);
|
||||
}
|
||||
}
|
||||
return jsonObject;*/
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.ruoyi.cai.trdpay.handle;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.cai.domain.PayTrdConfig;
|
||||
import com.ruoyi.cai.pay.PayManager;
|
||||
import com.ruoyi.cai.pay.PayOrderInfoDTO;
|
||||
import com.ruoyi.cai.pay.PayReturnResp;
|
||||
import com.ruoyi.cai.service.OrderLogsService;
|
||||
import com.ruoyi.cai.trdpay.PayMd5Util;
|
||||
import com.ruoyi.cai.trdpay.PayTrdService;
|
||||
import com.ruoyi.cai.trdpay.TrdPayTypeEnum;
|
||||
import com.ruoyi.cai.trdpay.dto.NotifyResp;
|
||||
import com.ruoyi.cai.util.RestTemplateUtil;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.helper.LoginHelper;
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PayTrdV6Service implements PayTrdService {
|
||||
|
||||
@Autowired
|
||||
private OrderLogsService orderLogsService;
|
||||
@Autowired
|
||||
private PayManager payManager;
|
||||
|
||||
@Override
|
||||
public TrdPayTypeEnum getType() {
|
||||
return TrdPayTypeEnum.V6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PayReturnResp createOrderAli(PayOrderInfoDTO payOrderInfoDTO, PayTrdConfig payTrdConfig) {
|
||||
TrdPayTypeEnum type = getType();
|
||||
RestTemplate rest = RestTemplateUtil.getRest();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("mchId", payTrdConfig.getMchId());
|
||||
params.put("mchOrderNo", payOrderInfoDTO.getOrderNo());
|
||||
params.put("productId", payTrdConfig.getAliProductId());
|
||||
params.put("extra", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
params.put("amount", payOrderInfoDTO.getPriceFenStr());
|
||||
String notifyUrl = payTrdConfig.getNotifyUrl() + type.getNotifyPath();
|
||||
params.put("notifyUrl", notifyUrl);
|
||||
params.put("subject",payOrderInfoDTO.getSubject());
|
||||
params.put("body",payOrderInfoDTO.getBody());
|
||||
params.put("clientIp", ServletUtils.getClientIP());
|
||||
String para = PayMd5Util.createParams(params, payTrdConfig.getSign());
|
||||
String gatewayUrl = type.getGatewayUrl();
|
||||
if (StringUtils.isNotBlank(payTrdConfig.getGatewayUrl())) {
|
||||
gatewayUrl = payTrdConfig.getGatewayUrl();
|
||||
}
|
||||
String createOrderUrl = gatewayUrl + type.getCreateOrderUrl();
|
||||
String url = createOrderUrl + "?" + para;
|
||||
String body = rest.postForObject(url, null, String.class);
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
orderLogsService.createAliPayLogs(payOrderInfoDTO.getOrderNo(), url, jsonObject, type);
|
||||
if(jsonObject == null){
|
||||
log.error("第三方支付失败 V6 返回数据为空 url={}",url);
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
if(!"SUCCESS".equals(jsonObject.getString("retCode"))){
|
||||
log.info("第三方支付失败 V6 统一支付失败失败 url={} body={}, payTrdConfig={}, typeEnum={}", url, body, JSON.toJSONString(payTrdConfig), JSON.toJSONString(jsonObject));
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
String payUrl = jsonObject.getJSONObject("payParams").getString("payUrl");
|
||||
return PayReturnResp.createH5(payUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NotifyResp getNotifyResp(Map<String, String> sourceData) {
|
||||
String mchOrderNo = sourceData.get("mchOrderNo");
|
||||
String payOrderId = sourceData.get("payOrderId");
|
||||
String status = sourceData.get("status");
|
||||
NotifyResp resp = new NotifyResp();
|
||||
resp.setOrderNo(mchOrderNo);
|
||||
resp.setTrdOrderNo(payOrderId);
|
||||
resp.setPayTypeEnum(getType());
|
||||
resp.setSourceData(sourceData);
|
||||
resp.setSuccess("2".equals(status));
|
||||
return resp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject queryOrder(String orderNo, PayTrdConfig payTrdConfig) {
|
||||
TrdPayTypeEnum type = getType();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("merchantId", payTrdConfig.getMchId());
|
||||
params.put("merchantPayNo", orderNo);
|
||||
String para = PayMd5Util.createParams(params,payTrdConfig.getSign());
|
||||
String gatewayUrl = type.getGatewayUrl();
|
||||
if(StringUtils.isNotBlank(payTrdConfig.getGatewayUrl())){
|
||||
gatewayUrl = payTrdConfig.getGatewayUrl();
|
||||
}
|
||||
String queryOrderUrl = gatewayUrl + type.getQueryOrderUrl();
|
||||
String url = queryOrderUrl + "?" + para;
|
||||
String body = RestTemplateUtil.getRest().getForEntity(url, String.class).getBody();
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
if(jsonObject == null){
|
||||
log.error("第三方支付查询失败 返回数据为空 URL={}",url);
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
log.info("第三方支付查询成功 V6 URL={}, body={}",url, body);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject resetOrder(String orderNo, PayTrdConfig payTrdConfig, boolean updateData) {
|
||||
throw new ServiceException("V6不支持订单查询");
|
||||
/*JSONObject jsonObject = this.queryOrder(orderNo,payTrdConfig);
|
||||
if(!"SUCCESS".equals(jsonObject.getString("retCode"))){
|
||||
log.info("第三方支付失败 V6统一支付失败失败 orderNo={}, payTrdConfig={}", orderNo, JSON.toJSONString(payTrdConfig));
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
Integer status = jsonObject.getInteger("status");
|
||||
if(status != null && status.equals(1)){
|
||||
String mchOrderNo = jsonObject.getString("mchOrderNo");
|
||||
String payOrderId = jsonObject.getString("payOrderId");
|
||||
String productId = jsonObject.getString("productId");
|
||||
Map<String,String> objectJson = new HashMap<>();
|
||||
for (String key : jsonObject.keySet()) {
|
||||
objectJson.put(key, jsonObject.getString(key));
|
||||
}
|
||||
if(updateData){
|
||||
payManager.callBack(mchOrderNo,payOrderId,objectJson,"V6", PayTypeEnum.TRD);
|
||||
}
|
||||
}
|
||||
return jsonObject;*/
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user