From a7501803a3ca43310e57a5dd912e5047919c2e43 Mon Sep 17 00:00:00 2001 From: 彭雪彬 <1724387007@qq.com> Date: Tue, 15 Jul 2025 15:26:55 +0800 Subject: [PATCH] Merge branch 'xin' into pxb --- oying-system/src/main/java/com/oying/modules/hwc/service/impl/SwiftPassServiceImpl.java | 125 +++++++++++------------------------------ 1 files changed, 35 insertions(+), 90 deletions(-) diff --git a/oying-system/src/main/java/com/oying/modules/hwc/service/impl/SwiftPassServiceImpl.java b/oying-system/src/main/java/com/oying/modules/hwc/service/impl/SwiftPassServiceImpl.java index bc39419..e0a7063 100644 --- a/oying-system/src/main/java/com/oying/modules/hwc/service/impl/SwiftPassServiceImpl.java +++ b/oying-system/src/main/java/com/oying/modules/hwc/service/impl/SwiftPassServiceImpl.java @@ -8,8 +8,8 @@ import com.oying.modules.hwc.utils.SignUtils; import com.oying.modules.hwc.utils.XmlUtils; import com.oying.modules.security.config.SwiftPassProperties; -import com.oying.modules.sh.service.OrderReturnService; -import com.oying.modules.sh.service.OrderService; +import com.oying.modules.security.config.WeiXinProperties; +import com.oying.utils.CloseUtil; import com.oying.utils.enums.PayTypeEnum; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -22,10 +22,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; import java.util.*; /** @@ -47,13 +43,12 @@ private final static String service_close = "unified.trade.close"; private final SwiftPassProperties properties; - private final OrderService orderService; - private final OrderReturnService returnService; + private final WeiXinProperties weiXinProperties; @Override @Transactional(rollbackFor = Exception.class) - public HwcResponse pay(String ip, Integer total, String timeExpire, String description, String openId, - String orderNum, PayTypeEnum status) throws IOException { + public HwcResponse pay(String ip, String total, String timeExpire, String description, String openId, + String orderNum, PayTypeEnum status) { SortedMap<String, String> map = new TreeMap<>(); map.put("service", service_pay); map.put("version", version); @@ -64,8 +59,8 @@ map.put("out_trade_no", orderNum); map.put("body", description); map.put("sub_openid", openId); - map.put("sub_appid", properties.getAppId()); - map.put("total_fee", String.valueOf(total)); + map.put("sub_appid", weiXinProperties.getAppId()); + map.put("total_fee", total); map.put("mch_create_ip", ip); map.put("notify_url", properties.getNotifyUrl()); map.put("time_expire", timeExpire); @@ -73,6 +68,9 @@ switch (status) { case HWC: map.put("mch_id", properties.getMchId()); + break; + case HWC2: + map.put("mch_id", properties.getMchId2()); break; default: throw new BadRequestException("汇旺财类型错误"); @@ -104,9 +102,7 @@ throw new BadRequestException("验证签名错误"); } else { if ("0".equals(resultMap.get("status")) && "0".equals(resultMap.get("result_code"))) { -// Gson gson = new Gson(); -// return gson.fromJson(resultMap.get("pay_info"), HwcResponse.class); - return null; + return JSONObject.parseObject(resultMap.get("pay_info"), HwcResponse.class); } else { throw new BadRequestException(resultMap.get("err_code") + " : " + resultMap.get("err_msg") + "\n" + resultMap.get("status") + " : " + resultMap.get("message")); @@ -116,21 +112,21 @@ throw new BadRequestException("操作失败"); } } catch (Exception e) { - log.error("请求参数:{}", params); - log.error("返回参数:{}", resultMap); - throw new BadRequestException("系统异常:" + e.getMessage()); + log.error("汇旺财下单错误请求参数:{}", params); + log.error("汇旺财下单错误返回参数:{}", resultMap); + throw new BadRequestException("汇旺财下单错误:" + e.getMessage()); } finally { if (response != null) { - response.close(); + CloseUtil.close(response); } if (client != null) { - client.close(); + CloseUtil.close(client); } } } @Override - public JSONObject query(String orderNum, PayTypeEnum status) throws IOException { + public JSONObject query(String orderNum, PayTypeEnum status) { // 参数 SortedMap<String, String> map = new TreeMap<>(); map.put("service", service_query); @@ -141,6 +137,9 @@ switch (status) { case HWC: map.put("mch_id", properties.getMchId()); + break; + case HWC2: + map.put("mch_id", properties.getMchId2()); break; default: throw new BadRequestException("汇旺财类型错误"); @@ -188,16 +187,16 @@ throw new BadRequestException("操作失败,原因:" + e.getMessage()); } finally { if (response != null) { - response.close(); + CloseUtil.close(response); } if (client != null) { - client.close(); + CloseUtil.close(client); } } } @Override - public void closeOrder(String outTradeNo, PayTypeEnum status) throws IOException { + public void closeOrder(String outTradeNo, PayTypeEnum status) { // 参数 SortedMap<String, String> map = new TreeMap<>(); map.put("service", service_close); @@ -208,6 +207,9 @@ switch (status) { case HWC: map.put("mch_id", properties.getMchId()); + break; + case HWC2: + map.put("mch_id", properties.getMchId2()); break; default: throw new BadRequestException("汇旺财类型错误"); @@ -252,10 +254,10 @@ throw new BadRequestException("操作失败,原因:" + e.getMessage()); } finally { if (response != null) { - response.close(); + CloseUtil.close(response); } if (client != null) { - client.close(); + CloseUtil.close(client); } } } @@ -263,7 +265,7 @@ @Override @Transactional(rollbackFor = Exception.class) public Map<String, String> refund(String returnNum, String orderNum, String reason, long refund, - long total, PayTypeEnum payType) throws IOException { + long total, PayTypeEnum payType) { // 参数 SortedMap<String, String> map = new TreeMap<>(); map.put("service", service_refund); @@ -279,6 +281,10 @@ case HWC: map.put("mch_id", properties.getMchId()); map.put("op_user_id", properties.getMchId()); + break; + case HWC2: + map.put("mch_id", properties.getMchId2()); + map.put("op_user_id", properties.getMchId2()); break; default: throw new BadRequestException("汇旺财类型错误"); @@ -322,74 +328,13 @@ throw new BadRequestException("操作失败,原因:" + e); } finally { if (response != null) { - response.close(); + CloseUtil.close(response); } if (client != null) { - client.close(); + CloseUtil.close(client); } } } - @Override - @Transactional(rollbackFor = Exception.class) - public void alipayCallback(HttpServletRequest request, HttpServletResponse response) { - try { - String resString = XmlUtils.parseRequest(request); - String respString = "error"; - if (!resString.isEmpty()) { - Map<String, String> map = XmlUtils.toMap(resString.getBytes(), "utf-8"); - String sign_type = map.get("sign_type"); - String reSign = map.get("sign"); - if (map.containsKey("sign")) { -// OrderDto order = orderService.findByOrderNum(map.get("out_trade_no")); - PayTypeEnum status = PayTypeEnum.find("order.getPayType()"); - if (SignUtil.verifySign(reSign, sign_type, map, properties, status)) { - System.out.println("验证签名错误!:" + map); - } else { - if ("0".equals(map.get("status"))) { - if ("0".equals(map.get("result_code"))) { - //业务处理 - respString = "success"; - response.getWriter().write(respString); - } - } - } - } - } - response.getWriter().write(respString); - } catch (Exception e) { - throw new BadRequestException("操作失败,原因:" + e.getMessage()); - } - } - @Override - @Transactional(rollbackFor = Exception.class) - public void returnNotify(HttpServletRequest request, HttpServletResponse response) { - try { - String resString = XmlUtils.parseRequest(request); - String respString = "error"; - if (!resString.isEmpty()) { - Map<String, String> map = XmlUtils.toMap(resString.getBytes(), "utf-8"); - String sign_type = map.get("sign_type"); - String reSign = map.get("sign"); - if (map.containsKey("sign")) { -// ReturnOrder returnOrder = returnOrderRepository.findByReturnNum(map.get("out_refund_no")); - PayTypeEnum status = PayTypeEnum.find("order.getPayType()"); - if (SignUtil.verifySign(reSign, sign_type, map, properties, status)) { - System.out.println("验证签名错误!:" + map); - } else { - if ("0".equals(map.get("status"))) { - if ("0".equals(map.get("result_code"))) { - // 业务处理 - respString = "success"; - } - } - } - } - } - response.getWriter().write(respString); - } catch (Exception e) { - System.out.println("操作失败,原因:" + e.getMessage()); - } - } } -- Gitblit v1.9.3