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

新版商家转账 - 回调 #3549

Open
yexua opened this issue Apr 11, 2025 · 2 comments
Open

新版商家转账 - 回调 #3549

yexua opened this issue Apr 11, 2025 · 2 comments

Comments

@yexua
Copy link

yexua commented Apr 11, 2025

是否有大佬可以提供一个Controller demo处理转账回调,感谢

@yexua
Copy link
Author

yexua commented Apr 11, 2025

自己试着写了写,解析正常给大家参考下

@PostMapping(value = "/transfer/notify")
    public ResponseEntity<String> transferNotify(HttpServletRequest request, @RequestBody String notifyData) {
        SignatureHeader header = getRequestHeader(request);
        try {
            TransferBillsNotifyResult transferBillsNotifyResult = this.wxPayService.parseTransferBillsNotifyV3Result(notifyData, header);
            log.info("转账通知: {}", transferBillsNotifyResult);
            String resp = WxPayNotifyV3Response.success("");
            return ResponseEntity.ok(resp);
        } catch (Exception e) {
            log.error("WxPayController#transferNotify", e);
            String resp = WxPayNotifyV3Response.fail("系统错误");
            return ResponseEntity.status(500).body(resp);
        }
    }

    /**
     * 组装请求头重的前面信息
     *
     * @param request
     * @return
     */
    private SignatureHeader getRequestHeader(HttpServletRequest request) {
        // 获取通知签名
        String signature = request.getHeader("Wechatpay-Signature");
        String nonce = request.getHeader("Wechatpay-Nonce");
        String serial = request.getHeader("Wechatpay-Serial");
        String timestamp = request.getHeader("Wechatpay-Timestamp");

        SignatureHeader signatureHeader = new SignatureHeader();
        signatureHeader.setSignature(signature);
        signatureHeader.setNonce(nonce);
        signatureHeader.setSerial(serial);
        signatureHeader.setTimeStamp(timestamp);
        return signatureHeader;
    }

@binarywang
Copy link
Owner

欢迎你把代码直接通过PR贡献到demo里

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants