xin
2025-09-03 ca0f290991d7a15748d90d01e57f0f4cd6f26c9c
汇旺财支付回调-优化日志
4 files modified
38 ■■■■ changed files
oying-system/src/main/java/com/oying/modules/hwc/service/impl/CallbackServiceImpl.java 21 ●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/hwc/utils/SignUtil.java 11 ●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/hwc/utils/XmlUtils.java 3 ●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderOperationLogServiceImpl.java 3 ●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/hwc/service/impl/CallbackServiceImpl.java
@@ -13,11 +13,14 @@
import com.oying.utils.enums.PayTypeEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.DocumentException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -75,15 +78,21 @@
                }
            }
            response.getWriter().write(respString);
        } catch (DataIntegrityViolationException e) {
            log.error("汇旺财退款回调数据异常失败:{} {}", map.toString(), e.getMessage());
        } catch (DocumentException e) {
            log.error("汇旺财退款回调XML转码失败:{} {}", map.toString(), e.getMessage());
        } catch (IOException e) {
            log.error("汇旺财退款回调写入流失败:{} {}", map.toString(), e.getMessage());
        } catch (Exception e) {
            log.error("汇旺财支付回调失败:{}", map.toString());
            log.error("汇旺财退款回调失败:{} {}", map.toString(), e.getMessage());
        }
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void returnNotify(HttpServletRequest request, HttpServletResponse response) {
        Map<String, String> map =  new HashMap<>();
        Map<String, String> map = new HashMap<>();
        try {
            String resString = XmlUtils.parseRequest(request);
            String respString = "error";
@@ -110,8 +119,14 @@
                }
            }
            response.getWriter().write(respString);
        } catch (DataIntegrityViolationException e) {
            log.error("汇旺财退款回调数据异常失败:{} {}", map.toString(), e.getMessage());
        } catch (DocumentException e) {
            log.error("汇旺财退款回调XML转码失败:{} {}", map.toString(), e.getMessage());
        } catch (IOException e) {
            log.error("汇旺财退款回调写入流失败:{} {}", map.toString(), e.getMessage());
        } catch (Exception e) {
            log.error("汇旺财退款回调失败:{}", map.toString());
            log.error("汇旺财退款回调失败:{} {}", map.toString(), e.getMessage());
        }
    }
}
oying-system/src/main/java/com/oying/modules/hwc/utils/SignUtil.java
@@ -40,7 +40,8 @@
    /**
     * 对返回参数的验证签名
     */
    public static boolean verifySign(String sign, String signType, Map<String, String> resultMap, SwiftPassProperties properties, PayTypeEnum status) throws Exception {
    public static boolean verifySign(String sign, String signType, Map<String, String> resultMap,
                                     SwiftPassProperties properties, PayTypeEnum status)  {
        if ("RSA_1_256".equals(signType)) {
            Map<String, String> params = SignUtils.paraFilter(resultMap);
            StringBuilder builder = new StringBuilder((params.size() + 1) * 10);
@@ -62,7 +63,7 @@
    /**
     * RSA_1_256 验证签名
     */
    public static boolean verifySign(String preStr, String sign, String signType, String platPublicKey) throws Exception {
    public static boolean verifySign(String preStr, String sign, String signType, String platPublicKey) {
        // 调用这个函数前需要先判断是MD5还是RSA
        // 商户的验签函数要同时支持MD5和RSA
        RSAUtil.SignatureSuite suite;
@@ -71,7 +72,7 @@
        } else if ("RSA_1_256".equals(signType)) {
            suite = RSAUtil.SignatureSuite.SHA256;
        } else {
            throw new Exception("不支持的签名方式");
            throw new BadRequestException("不支持的签名方式");
        }
        return RSAUtil.verifySign(suite, preStr.getBytes(StandardCharsets.UTF_8), Base64.decodeBase64(sign.getBytes(StandardCharsets.UTF_8)),
                platPublicKey);
@@ -80,14 +81,14 @@
    /**
     * RSA_1_256生成不同的sign
     */
    public static String sign(String preStr, String signType, String mchPrivateKey) throws Exception {
    public static String sign(String preStr, String signType, String mchPrivateKey) {
        RSAUtil.SignatureSuite suite;
        if ("RSA_1_1".equals(signType)) {
            suite = RSAUtil.SignatureSuite.SHA1;
        } else if ("RSA_1_256".equals(signType)) {
            suite = RSAUtil.SignatureSuite.SHA256;
        } else {
            throw new Exception("不支持的签名方式");
            throw new BadRequestException("不支持的签名方式");
        }
        byte[] signBuf = RSAUtil.sign(suite, preStr.getBytes(StandardCharsets.UTF_8),
                mchPrivateKey);
oying-system/src/main/java/com/oying/modules/hwc/utils/XmlUtils.java
@@ -2,6 +2,7 @@
import com.oying.exception.BadRequestException;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.xml.sax.InputSource;
@@ -101,7 +102,7 @@
    /**
     * 转XML map
     */
    public static Map<String, String> toMap(byte[] xmlBytes, String charset) throws Exception {
    public static Map<String, String> toMap(byte[] xmlBytes, String charset) throws DocumentException {
        SAXReader reader = new SAXReader(false);
        InputSource source = new InputSource(new ByteArrayInputStream(xmlBytes));
        source.setEncoding(charset);
oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderOperationLogServiceImpl.java
@@ -2,7 +2,6 @@
import com.alibaba.fastjson2.JSON;
import com.oying.exception.BadRequestException;
import com.oying.modules.message.common.MesTypeEnum;
import com.oying.modules.message.common.MsgStatusEnum;
import com.oying.modules.message.service.MesMsgRecordService;
import com.oying.modules.sh.domain.OrderOperationLog;
@@ -183,7 +182,7 @@
        resources.setOperationTime(time);
        orderOperationLogMapper.insert(resources);
        if (msgStatusEnum != null){
            mesMsgRecordService.insertOrderMsg(response.getOrder(), msgStatusEnum, MesTypeEnum.ORDER);
//            mesMsgRecordService.insertOrderMsg(response.getOrder(), msgStatusEnum, MesTypeEnum.ORDER);
        }
        orderMapper.updateOrderStatus(response.getOrder().getOrderNum(), statusEnum.getKey(), statusEnum.getValue());
    }