From 0e9752e055415c6304a8c642bc3ecd09ddd19633 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Thu, 25 May 2023 10:24:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/v1/TradeController.java | 43 +++++++++++++++++++ .../v1/model/RequestQueryRefundModel.java | 36 ++++++++++++++++ .../hfkj/openapi/v1/utils/SignatureUtil.java | 7 +-- 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 service/src/main/java/com/hfkj/openapi/v1/model/RequestQueryRefundModel.java diff --git a/open-api/src/main/java/com/api/controller/v1/TradeController.java b/open-api/src/main/java/com/api/controller/v1/TradeController.java index 5ea29b5..449024f 100644 --- a/open-api/src/main/java/com/api/controller/v1/TradeController.java +++ b/open-api/src/main/java/com/api/controller/v1/TradeController.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 ==========="); + } + } + + + } diff --git a/service/src/main/java/com/hfkj/openapi/v1/model/RequestQueryRefundModel.java b/service/src/main/java/com/hfkj/openapi/v1/model/RequestQueryRefundModel.java new file mode 100644 index 0000000..cd38a6c --- /dev/null +++ b/service/src/main/java/com/hfkj/openapi/v1/model/RequestQueryRefundModel.java @@ -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; + +} diff --git a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java index 895144f..f338e40 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java +++ b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java @@ -80,11 +80,8 @@ 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\"" + + " \"merchantNo\": \"2023030909414450700\",\n" + + " \"refundTradeNo\": \"1170202305051137247442194606\"" + "}"; String sign = createSign(JSONObject.parseObject(paramStr), "LRL9uflTQGeyp9yVWDD6orhBp2VhYDvP"); System.out.println(sign);