-
Notifications
You must be signed in to change notification settings - Fork 227
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
微信支付回调报错DecryptionException #304
Labels
bug
Something isn't working
Comments
公钥相关的问题现在解决了么 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
错误描述
新版商户号没有证书, 只能使用本地平台公钥方式验证签名。 使用这种方式目前下单接口可以执行成功, 但是回调没有解析成功, 报错如下:
com.wechat.pay.java.core.exception.DecryptionException: Decryption failed
public Transaction parseTransactionFromRequestParam(RequestParam requestParam) {
NotificationParser parser = new NotificationParser((NotificationConfig)config);
return parser.parse(requestParam, Transaction.class);
}
重现bug的步骤
1、 解析请求 body, 这一步是能正常解析的:
private String readRequest(HttpServletRequest request) {
try {
BufferedReader reader = request.getReader();
String line;
StringBuilder inputString = new StringBuilder();
while ((line = reader.readLine()) != null) {
inputString.append(line);
}
reader.close();
return inputString.toString();
} catch (IOException e) {
log.error("read request error", e);
return null;
}
}
2、 获取并创建requestParam
String signature = request.getHeader("Wechatpay-Signature");
String timestamp = request.getHeader("Wechatpay-Timestamp");
String nonce = request.getHeader("Wechatpay-Nonce");
String wechatPayCertificateSerialNumber = request.getHeader("Wechatpay-Serial");
// 构造 RequestParam
RequestParam requestParam = new RequestParam.Builder()
.serialNumber(wechatPayCertificateSerialNumber)
.nonce(nonce)
.signature(signature)
.timestamp(timestamp)
.body(body)
.build();
3、 验证并解析transaction :
public Transaction parseTransactionFromRequestParam(RequestParam requestParam) {
NotificationParser parser = new NotificationParser((NotificationConfig)config);
return parser.parse(requestParam, Transaction.class);
}
上述的config 是和下单定义的config一样的, 这个config 用于appServiceExtension 下单是能正常调用成功的:
@PostConstruct
public void initAppServiceExtension() throws Exception {
config =
// 可以根据实际情况使用publicKeyFromPath或publicKey加载公钥
new RSAPublicKeyConfig.Builder()
.merchantId(merchantId)
.privateKey(privateKey)
//.privateKeyFromPath(privateKeyPath)
.publicKey(publicKey)
//.publicKeyFromPath(publicKeyPath)
.publicKeyId(publicKeyId)
.merchantSerialNumber(mchSerialNo)
.apiV3Key(apiV3Key)
.build();
appServiceExtension = new AppServiceExtension.Builder().config(config).build();
}
预期行为
正确解析微信支付状态的回调
导致错误的代码片段
操作系统
macOS
Java 版本
java 8
wechatpay-java 版本
0.2.14
其他信息
No response
The text was updated successfully, but these errors were encountered: