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

README 回调通知的例子返回值错误的问题 #300

Open
wyl086 opened this issue Oct 17, 2024 · 0 comments
Open

README 回调通知的例子返回值错误的问题 #300

wyl086 opened this issue Oct 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@wyl086
Copy link

wyl086 commented Oct 17, 2024

错误描述

// 返回类型为 ResponseEntity.BodyBuilder 不正确
// return ResponseEntity.status(HttpStatus.OK);
// 应改为返回类型 ResponseEntity
return ResponseEntity.status(HttpStatus.OK).build();

重现bug的步骤

微信支付通知接口使用README的回调通知代码即可复现
回调通知链接引用

预期行为

不报错 No acceptable representation

导致错误的代码片段

// 构造 RequestParam
RequestParam requestParam = new RequestParam.Builder()
        .serialNumber(wechatPaySerial)
        .nonce(wechatpayNonce)
        .signature(wechatSignature)
        .timestamp(wechatTimestamp)
        .body(requestBody)
        .build();

// 如果已经初始化了 RSAAutoCertificateConfig,可直接使用
// 没有的话,则构造一个
NotificationConfig config = new RSAAutoCertificateConfig.Builder()
        .merchantId(merchantId)
        .privateKeyFromPath(privateKeyPath)
        .merchantSerialNumber(merchantSerialNumber)
        .apiV3Key(apiV3Key)
        .build();

// 初始化 NotificationParser
NotificationParser parser = new NotificationParser(config);

try {
  // 以支付通知回调为例,验签、解密并转换成 Transaction
  Transaction transaction = parser.parse(requestParam, Transaction.class);
} catch (ValidationException e) {
  // 签名验证失败,返回 401 UNAUTHORIZED 状态码
  logger.error("sign verification failed", e);
  return ResponseEntity.status(HttpStatus.UNAUTHORIZED);
}

// 如果处理失败,应返回 4xx/5xx 的状态码,例如 500 INTERNAL_SERVER_ERROR
if (/* process error */) {
  return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR);
}

// 处理成功,返回 200 OK 状态码
return ResponseEntity.status(HttpStatus.OK);

操作系统

Windows11

Java 版本

Java 17

wechatpay-java 版本

0.2.14

其他信息

No response

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

1 participant