nnnn
This commit is contained in:
@@ -137,6 +137,18 @@ public enum TrdPayTypeEnum {
|
||||
*/
|
||||
V13("https://pp123.bghyvwk.cn","/mapi.php","/api.php","/api/pay/trd/notify/v13","success"),
|
||||
V14("https://efps.epaylinks.cn","/mapi.php","/api.php","/api/pay/trd/notify/v14","success"),
|
||||
/**
|
||||
* 下单网关:http://n5d4.damiepay.paysanguo.com/Pay_Index.html
|
||||
* 查询网关:http://n5d4.damiepay.paysanguo.com/Pay_Trade_query.html
|
||||
* 商户登录地址:http://n5d4.damiepay.paysanguo.com/user.html
|
||||
* 用户名:嫣语
|
||||
* 密码和登录密码默认:123456
|
||||
* 回调IP:47.238.194.1,47.238.186.95,47.242.93.145
|
||||
* 商务号:251121186
|
||||
* 秘钥:2euc8m2wgvruotdez38prne6wa9x2zc1
|
||||
* 对接文档:https://hackmd.io/@qHzyKONURmSGQo5bMSA9sg/Hk9We_3Jbx
|
||||
*/
|
||||
V15("http://n5d4.damiepay.paysanguo.com","/Pay_Index.html","/api.php","/api/pay/trd/notify/v15","OK"),
|
||||
|
||||
;
|
||||
private final String gatewayUrl;
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
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.service.PayTrdConfigService;
|
||||
import com.ruoyi.cai.trdpay.PaySignUtil;
|
||||
import com.ruoyi.cai.trdpay.PayTrdService;
|
||||
import com.ruoyi.cai.trdpay.TrdPayTypeEnum;
|
||||
import com.ruoyi.cai.trdpay.dto.NotifyResp;
|
||||
import com.ruoyi.cai.util.MapUtils;
|
||||
import com.ruoyi.cai.util.RestTemplateUtil;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PayTrdV15Service implements PayTrdService {
|
||||
|
||||
@Autowired
|
||||
private OrderLogsService orderLogsService;
|
||||
@Autowired
|
||||
private PayManager payManager;
|
||||
@Autowired
|
||||
private PayTrdConfigService payTrdConfigService;
|
||||
|
||||
@Override
|
||||
public TrdPayTypeEnum getType() {
|
||||
return TrdPayTypeEnum.V15;
|
||||
}
|
||||
@Override
|
||||
public PayReturnResp createOrderAli(PayOrderInfoDTO payOrderInfoDTO, PayTrdConfig payTrdConfig, boolean wx) {
|
||||
TrdPayTypeEnum type = getType();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("pay_memberid", payTrdConfig.getMchId());
|
||||
params.put("pay_orderid", payOrderInfoDTO.getOrderNo());
|
||||
params.put("pay_applydate", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
if(wx){
|
||||
params.put("pay_bankcode", payTrdConfig.getWxProductId());
|
||||
}else{
|
||||
params.put("pay_bankcode", payTrdConfig.getAliProductId());
|
||||
}
|
||||
String notifyUrl = type.getNotifyUrl(payTrdConfig.getNotifyUrl(), wx);
|
||||
params.put("pay_notifyurl", notifyUrl);
|
||||
params.put("pay_callbackurl", notifyUrl);
|
||||
params.put("pay_amount", payOrderInfoDTO.getPriceYuanStr());
|
||||
String sign = PaySignUtil.createMD5(params, "&key="+payTrdConfig.getSign()).toUpperCase();
|
||||
MultiValueMap<String, String> multiValueMap = MapUtils.mapToMultiValueMap(params);
|
||||
multiValueMap.add("pay_md5sign", sign);
|
||||
multiValueMap.add("pay_productname",payOrderInfoDTO.getSubject());
|
||||
multiValueMap.add("pay_ip", ServletUtils.getClientIP());
|
||||
String gatewayUrl = getGatewayUrl(payTrdConfig);
|
||||
String createOrderUrl = gatewayUrl + type.getCreateOrderUrl();
|
||||
String body = RestTemplateUtil.postFormData(createOrderUrl, multiValueMap);
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
boolean success = checkSuccess(jsonObject);
|
||||
orderLogsService.createAliPayLogs(payOrderInfoDTO.getOrderNo(), createOrderUrl+JSON.toJSONString(multiValueMap), jsonObject, success, type, getStepName(wx));
|
||||
if(!success){
|
||||
log.info("第三方支付失败 V15 统一支付失败失败 url={} params={} body={}, payTrdConfig={}", createOrderUrl,JSON.toJSONString(multiValueMap), body, JSON.toJSONString(payTrdConfig));
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
String payUrl = jsonObject.getString("h5_url");
|
||||
return PayReturnResp.createH5(payUrl);
|
||||
}
|
||||
|
||||
private boolean checkSuccess(JSONObject jsonObject) {
|
||||
if(jsonObject == null){
|
||||
return false;
|
||||
}
|
||||
if(!"1".equals(jsonObject.getString("status"))){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@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) {
|
||||
throw new ServiceException("V15不支持订单查询");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject resetOrder(String orderNo, PayTrdConfig payTrdConfig, boolean updateData) {
|
||||
throw new ServiceException("V15不支持订单查询");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user