Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支付成功回调后,出现极个别支付单解签失败的情况 #251

Open
liguangling-lgl opened this issue Jan 13, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@liguangling-lgl
Copy link

错误描述

WechatIMG5119

重现bug的步骤

@Override
public PayCallbackResult callbackWechatPay(HttpServletRequest httpServletRequest) {
    String body = getRequestBody(httpServletRequest);
    String serialNumber = httpServletRequest.getHeader("Wechatpay-Serial");
    String nonce = httpServletRequest.getHeader("Wechatpay-Nonce");
    String signature = httpServletRequest.getHeader("Wechatpay-Signature");
    String timestamp = httpServletRequest.getHeader("Wechatpay-Timestamp");
    RequestParam requestParam = new RequestParam.Builder()
            .serialNumber(serialNumber)
            .nonce(nonce)
            .signature(signature)
            .timestamp(timestamp)
            .body(body)
            .build();
    log.info("支付回调,通知参数:{}", JSON.toJSONString(requestParam));
    NotificationConfig config = (NotificationConfig) wechatPayConfigHolder.getConfig();
    NotificationParser parser = new NotificationParser(config);
    Transaction transaction = parser.parse(requestParam, Transaction.class);
    String paySn = "P" + IdGeneratorManager.globalGenerator();
    OrderCallbackReqDTO orderCallbackReqDTO = OrderCallbackReqDTO.builder()
            .status(TradeStatusEnum.queryActualTradeStatusCode(transaction.getTradeState().name()))
            .joinTime(DateUtil.date())
            .tradeNo(transaction.getTransactionId())
            .gmtPayment(DateUtil.parse(transaction.getSuccessTime()))
            .orderSn(transaction.getOutTradeNo())
            .paySn(paySn)
            .build();
    return orderService.callbackOrder(orderCallbackReqDTO);
}

private String getRequestBody(HttpServletRequest request) {
    ByteArrayOutputStream body = new ByteArrayOutputStream();
    try {
        ServletInputStream inputStream = request.getInputStream();
        byte[] buffer = new byte[1024];
        for (int length; (length = inputStream.read(buffer)) != -1; ) {
            body.write(buffer, 0, length);
        }
    } catch (IOException ex) {
        log.error("支付回调,读取数据流异常", ex);
    }
    log.info("支付回调,通知消息体:{}", body);
    return body.toString();
}

}
解签代码 ,使用的微信SDK

预期行为

有的订单支付成功回调没有问题,极少订单会出现解签失败的情况,不清楚为什么

导致错误的代码片段

Transaction transaction = parser.parse(requestParam, Transaction.class);

操作系统

linux

Java 版本

Java21

wechatpay-java 版本

0.2.7

其他信息

No response

@liguangling-lgl liguangling-lgl added the bug Something isn't working label Jan 13, 2024
@liguangling-lgl
Copy link
Author

是的 ,感谢 确实是这个原因

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants