看了你的问题,反而解决了我的问题,哈哈哈哈哈 // 初始化商户配置 Config config = new RSAAutoCertificateConfig.Builder() .merchantId(merchantId) // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 .privateKeyFromPath(privateKeyPath) .merchantSerialNumber(merchantSerialNumber) .apiV3Key(apiV3Key) .build(); //这才是正确的(解决支付回调验签失败问题) notificationConfig = (NotificationConfig)config; // 之前这么写的。巨坑,支付回调就报错:com.wechat.pay.java.core.exception.ValidationException: Processing WechatPay notification,signature // notificationConfig = new RSANotificationConfig.Builder() // // 注意这里必须是 收资商户号的ApiV3Key // .apiV3Key(apiV3Key) // // 注意这里必须是 收资商户生成的对应平台证书 // .certificatesFromPath(certificatesFromPath) // .build(); // 初始化服务 service = new JsapiService.Builder().config(config).build(); jsapiServiceExtension = new JsapiServiceExtension.Builder().config(config).build(); 看注释部分,好像官方的示例也是这样的啊。我没搞懂,但我发现你的NotificationConfig跟我的不一样,然后尝试着使用notificationConfig = (NotificationConfig)config;居然成功了。
收到小程序支付成功通知回调,但一直报错,求助啊?支付后,成功收到回调通知,使用官方工具包进行处理报错,报错和打印的数据如下: com.wechat.pay.java.core.exception.ValidationException: Processing WechatPay notification,signature verification failed,signType[WECHATPAY2-SHA256-RSA2048] serial[28A6ECAC59FBAC47784205BB1AB25B744ADF55CF] message[1691820382 Ftx0RrGc4hp8nHm05xQwNGKhlG2VLRX5 {"id":"15b6e163-c913-5b31-9655-b24c60419b3a","create_time":"2023-08-12T14:06:22 08:00","resource_type":"encrypt-resource","event_type":"TRANSACTION.SUCCESS","summary":"支付成功","resource":{"original_type":"transaction","algorithm":"AEAD_AES_256_GCM","ciphertext":"2SytYk8XbdJbJYjo3Nh ljTLaS3tiUuJqXWsZQB0WuNUmHIqZwEjL130JSSCJlJZj PwPNf ACPVCeGFBrwawGyOzC5PmAaG9Uk5mqulTpT/Jgo2R9qLk7J2lkTwXLvfxxZGYemkHzwv7fMmoOheoLThv2yIXmgXd7y7wkMMkiBEWMym 15 8jyPxuosZtxoGetVXN15hPQX/VvY41iBEJ4DQxwp0zZtg1urAMDrXIqmlkycEjDNvDEY8s2YHG23c4tuGLS64rT 9mhMdkXVR3V2CC7ZYMlMin7RvVwsV9Fk/JQD0F1r3cQV0p9NP9AsqxZ8f7iqJ7btCL65wHSmWnPgmqbokD6125yFQ8TRVa9giax7NP3 6aV8A Hm2QvKP4uvWeRHTS9pAEe3NP96mWqM7Qs21vlR2QorWNTGxyj6vY217nG85Q2E34nD0UxhDx19FAFpQVLbsgcWQZEeRYvleXZGMGNPfxEOQQoj3IiQewzBuH1KTmfqpR6jkivx0g0vbej1vIpCYfQ aM88LP/vnaVgJfFWKU7PS Y 4 zxRoDEWJG2VQ2FoGNh4q8Kx3V9v2cHC2SNnBmnghN","associated_data":"transaction","nonce":"liX2WiKzV6vZ"}} ] sign[XBQmbyuwd9gczoTplkw6GgYab0CYzAV8Fw+ASswgshsi0qw8rQeLzvpvacSIzSJR3YQqK71bpnhJGo9hoONC3FGnBuGoWLibY3f8fzwERlmRKnaBILYohnwbjHlbMVvKd02asAuW2jx+ISGPpCDxnj9OURc6nAriOtzg5Sdcj+x059DtkXFrteFN1DK6S8XGFFHyRJkRIOoD6h+52V4aP7eSKqkGHrK2v5jnUqTithcmEMqTakNbIuI95dN3WmeYeq21cZS2z8sLzXQ9FSQidVYknFyXFUHdNslY/U66z2J34Jlf2rZKmI0Jefgpuinmaz365cApkpZXETmBhrrR1A==] at com.wechat.pay.java.core.notification.NotificationParser.validateRequest(NotificationParser.java:93) at com.wechat.pay.java.core.notification.NotificationParser.parse(NotificationParser.java:49) 我的代码: // 所有配置参数都是发起支付时候的,能成功发起说明这些配置参数肯定没问题 NotificationConfig config = new RSAAutoCertificateConfig.Builder() .merchantId(merchantId) .privateKeyFromPath(privateKeyPath) .merchantSerialNumber(merchantSerialNumber) .apiV3Key(apiV3Key) .build(); // 初始化 NotificationParser NotificationParser parser = new NotificationParser(config); // 构造 RequestParam RequestParam requestParam = new RequestParam.Builder() .serialNumber(wechatPaySerial) .nonce(wechatpayNonce) .signature(wechatSignature.replace(" ","+")) .timestamp(wechatTimestamp) .body(body) // 这个body是StreamUtils.copyToString(req.getInputStream(), StandardCharsets.UTF_8);从req获取的 .build(); logger.log("==requestParam=="+ JsonUtil.toJson(requestParam)); Transaction transaction; try { // 这里失败的 // 以支付通知回调为例,验签、解密并转换成 Transaction transaction = parser.parse(requestParam, Transaction.class); } catch (ValidationException e) { // 签名验证失败,返回 401 UNAUTHORIZED 状态码 logger.log("sign verification failed", e); return ResponseEntity.status(HttpStatus.UNAUTHORIZED); } 官方工具包版本: <dependency> <groupId>com.github.wechatpay-apiv3</groupId> <artifactId>wechatpay-java</artifactId> <version>0.2.11</version> </dependency>
02-03