提交代码

yy_dev
胡锐 1 year ago
parent d7995316aa
commit 0e9752e055
  1. 43
      open-api/src/main/java/com/api/controller/v1/TradeController.java
  2. 36
      service/src/main/java/com/hfkj/openapi/v1/model/RequestQueryRefundModel.java
  3. 3
      service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java

@ -178,4 +178,47 @@ public class TradeController {
}
}
@RequestMapping(value="/queryRefund",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "查询退款")
public ResponseData queryRefund(@RequestBody RequestQueryRefundModel body) {
log.info("========= Start 查询退款 Start ===========");
log.info("请求参数:" + JSONObject.toJSONString(body));
try {
// 验证签名
if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, "");
}
// 查询交易订单号
BsTradeOrderRefund refund = openApiTradeOrderService.getRefundByNo(body.getRefundTradeNo());
if (refund == null) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的退款单号");
}
// 查询交易订单
BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(refund.getOutTradeNo());
if (tradeOrder == null) {
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的交易订单");
}
ResponseRefundTradeModel refundTradeModel = new ResponseRefundTradeModel();
refundTradeModel.setMerchantNo(tradeOrder.getMerNo());
refundTradeModel.setOutTradeNo(tradeOrder.getOutTradeNo());
refundTradeModel.setPayMode(tradeOrder.getPayMode());
refundTradeModel.setRefundTradeNo(refund.getRefundNo());
refundTradeModel.setRefundAmount(refund.getRefundAmount().toString());
refundTradeModel.setRefundPayerAmount(refund.getPayerAmount().toString());
refundTradeModel.setRefundTime(refund.getRefundTime());
refundTradeModel.setSign(SignatureUtil.createSign(refundTradeModel, merKeyService.getKeyByMerNo(tradeOrder.getMerNo())));
log.info("返回参数:" + JSONObject.toJSONString(refundTradeModel));
return ResponseMsgUtil.success(refundTradeModel);
} catch (Exception e) {
log.info("出现异常:", e);
return ResponseMsgUtil.exception(e);
} finally {
log.info("========= END 查询退款 END ===========");
}
}
}

@ -0,0 +1,36 @@
package com.hfkj.openapi.v1.model;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
/**
* 请求查询交易模型
* @className: TradePreorderModel
* @author: HuRui
* @date: 2023/5/23
**/
@Data
public class RequestQueryRefundModel {
/**
* 商户号
*/
@NotBlank(message = "商户号必填项")
private String merchantNo;
/**
* 退款单号
*/
@Length(min = 6, max = 50, message = "退款单号长度限制6至50位字符串长度")
@NotBlank(message = "退款单号必填项")
private String refundTradeNo;
/**
* 签名参数
*/
@NotBlank(message = "签名必填项")
private String sign;
}

@ -81,9 +81,6 @@ public class SignatureUtil {
public static void main(String[] args) throws Exception {
String paramStr = "{\n" +
" \"merchantNo\": \"2023030909414450700\",\n" +
" \"outTradeNo\": \"ZF1130202305242035187441186606\",\n" +
" \"refundAmount\": \"0.01\",\n" +
" \"refundReason\": \"测试退款\",\n" +
" \"refundTradeNo\": \"1170202305051137247442194606\"" +
"}";
String sign = createSign(JSONObject.parseObject(paramStr), "LRL9uflTQGeyp9yVWDD6orhBp2VhYDvP");

Loading…
Cancel
Save