数据
This commit is contained in:
@@ -4,7 +4,13 @@ package com.ruoyi.cai.trdpay;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.cai.domain.Account;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||
import com.ruoyi.cai.pay.PayManager;
|
||||
import com.ruoyi.cai.pay.PayOrderInfoDTO;
|
||||
import com.ruoyi.cai.pay.PayTypeEnum;
|
||||
import com.ruoyi.cai.service.AccountService;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -29,6 +35,7 @@ import java.util.stream.Collectors;
|
||||
public class TrdPayManager {
|
||||
|
||||
private final String CREATE_ORDER_URL = "http://pay.jpay.one/api/pay/create_order";
|
||||
private final String QUERY_ORDER_URL = "http://pay.jpay.one/api/pay/query_order";
|
||||
|
||||
private static final String NOTIFY_ALI_URL = "/api/pay/trd/notify";
|
||||
|
||||
@@ -60,6 +67,63 @@ public class TrdPayManager {
|
||||
return createOrder(payOrderInfoDTO,trdPayProperties.getAliProductId());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private AccountService accountService;
|
||||
@Autowired
|
||||
private SystemConfigManager systemConfigManager;
|
||||
|
||||
public boolean useTrdPay(Long userId){
|
||||
Account account = accountService.getByUserId(userId);
|
||||
if(account == null){
|
||||
return true;
|
||||
}
|
||||
BigDecimal payLimit = systemConfigManager.getSystemConfigOfBigDecimal(SystemConfigEnum.PAY_LIMIT);
|
||||
if(payLimit == null || payLimit.compareTo(BigDecimal.ZERO) == 0){
|
||||
return false;
|
||||
}
|
||||
if(account.getTotalTrdMoney().compareTo(payLimit) >= 0){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private PayManager payManager;
|
||||
|
||||
public JSONObject resetOrder(String orderNo){
|
||||
JSONObject jsonObject = queryOrder(orderNo);
|
||||
Integer status = jsonObject.getInteger("status");
|
||||
if(status != null && status.equals(2)){
|
||||
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));
|
||||
}
|
||||
payManager.callBack(mchOrderNo,payOrderId,objectJson,productId, PayTypeEnum.TRD);
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
public JSONObject queryOrder(String orderNo){
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("mchId", trdPayProperties.getMchId());
|
||||
params.put("mchOrderNo", orderNo);
|
||||
String para = createParams(params);
|
||||
String url = QUERY_ORDER_URL + "?" + para;
|
||||
String body = restTemplate.getForEntity(url, String.class).getBody();
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
if(jsonObject == null){
|
||||
log.error("第三方支付查询失败 返回数据为空");
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
if(!"SUCCESS".equals(jsonObject.getString("retCode"))){
|
||||
log.info("第三方支付查询失败 第三方支付查询失败 url={}, body={}",url, body);
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
log.info("第三方支付成功 URL={}, body={}",url, body);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
|
||||
public JSONObject createOrder(PayOrderInfoDTO payOrderInfoDTO,String productId){
|
||||
|
||||
Reference in New Issue
Block a user