33333333333

This commit is contained in:
777
2025-01-16 17:05:08 +08:00
parent 91ea4d1806
commit a096f565e1
4 changed files with 129 additions and 1 deletions

View File

@@ -91,6 +91,16 @@ public enum TrdPayTypeEnum {
* https://31.bghyvwk.cn * https://31.bghyvwk.cn
*/ */
V8("https://31.bghyvwk.cn","/mapi.php","/api/pay/query","/api/pay/trd/notify/v8","success"), V8("https://31.bghyvwk.cn","/mapi.php","/api/pay/query","/api/pay/trd/notify/v8","success"),
/**
* API设置
* API对接参数
* 商户号250207611
* 网关地址https://api.pay.wangwang888.cloud/Pay_Index.html
* 商户APIKEYjmc1ge7ldzyt18kd3vtigovb8m5vfwge
* 989 支付宝 934 微信
*/
V9("https://api.pay.wangwang888.cloud","/Pay_Index.html","/Pay_Trade_query.html","/api/pay/trd/notify/v9","OK"),
; ;
private final String gatewayUrl; private final String gatewayUrl;
private final String createOrderUrl; private final String createOrderUrl;

View File

@@ -79,7 +79,7 @@ public class PayTrdV5Service implements PayTrdService {
boolean success = checkSuccess(jsonObject); boolean success = checkSuccess(jsonObject);
orderLogsService.createAliPayLogs(payOrderInfoDTO.getOrderNo(), createOrderUrl+JSON.toJSONString(map), jsonObject, success, type); orderLogsService.createAliPayLogs(payOrderInfoDTO.getOrderNo(), createOrderUrl+JSON.toJSONString(map), jsonObject, success, type);
if(!success){ if(!success){
log.info("第三方支付失败 V7 统一支付失败失败 url={} params={} body={}, payTrdConfig={}, typeEnum={}", createOrderUrl,JSON.toJSONString(map), body, JSON.toJSONString(payTrdConfig), JSON.toJSONString(jsonObject)); log.info("第三方支付失败 V5 统一支付失败失败 url={} params={} body={}, payTrdConfig={}, typeEnum={}", createOrderUrl,JSON.toJSONString(map), body, JSON.toJSONString(payTrdConfig), JSON.toJSONString(jsonObject));
throw new ServiceException("调用支付失败"); throw new ServiceException("调用支付失败");
} }
String payUrl = jsonObject.getString("h5_url"); String payUrl = jsonObject.getString("h5_url");

View File

@@ -0,0 +1,106 @@
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 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.util.MultiValueMap;
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 PayTrdV9Service implements PayTrdService {
@Autowired
private OrderLogsService orderLogsService;
@Autowired
private PayManager payManager;
@Override
public TrdPayTypeEnum getType() {
return TrdPayTypeEnum.V9;
}
@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_applydate", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
params.put("pay_bankcode", payTrdConfig.getAliProductId());
String notifyUrl = payTrdConfig.getNotifyUrl() + type.getNotifyPath();
params.put("pay_notifyurl", notifyUrl);
params.put("pay_amount", payOrderInfoDTO.getPriceYuanStr());
MultiValueMap<String, String> map = PayMd5Util.createParamsOfMap(params, payTrdConfig.getSign(), "pay_md5sign");
map.add("pay_productname",payOrderInfoDTO.getBody());
String gatewayUrl = type.getGatewayUrl();
if (StringUtils.isNotBlank(payTrdConfig.getGatewayUrl())) {
gatewayUrl = payTrdConfig.getGatewayUrl();
}
String createOrderUrl = gatewayUrl + type.getCreateOrderUrl();
String body = RestTemplateUtil.postFormData(rest, createOrderUrl, map);
JSONObject jsonObject = JSON.parseObject(body);
boolean success = checkSuccess(jsonObject);
orderLogsService.createAliPayLogs(payOrderInfoDTO.getOrderNo(), createOrderUrl+JSON.toJSONString(map), jsonObject, success, type);
if(!success){
log.info("第三方支付失败 V9 统一支付失败失败 url={} params={} body={}, payTrdConfig={}, typeEnum={}", createOrderUrl,JSON.toJSONString(map), body, JSON.toJSONString(payTrdConfig), JSON.toJSONString(jsonObject));
throw new ServiceException("调用支付失败");
}
String payUrl = jsonObject.getString("h5_url");
return PayReturnResp.createH5(payUrl);
}
private boolean checkSuccess(JSONObject jsonObject) {
if(jsonObject == null){
return false;
}
if(!"success".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("V9不支持订单查询");
}
@Override
public JSONObject resetOrder(String orderNo, PayTrdConfig payTrdConfig, boolean updateData) {
throw new ServiceException("V9不支持订单查询");
}
}

View File

@@ -1,11 +1,15 @@
package com.ruoyi.cai.util; package com.ruoyi.cai.util;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.BufferingClientHttpRequestFactory; import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -59,4 +63,12 @@ public class RestTemplateUtil {
public static RestTemplate getNoSSLRest(){ public static RestTemplate getNoSSLRest(){
return NO_SSL_REST_TEMPLATE; return NO_SSL_REST_TEMPLATE;
} }
public static String postFormData(RestTemplate restTemplate, String url, MultiValueMap<String, String> map) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
return restTemplate.postForObject(url, request, String.class);
}
} }