String body = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()))
商户证书为空,serialNumberCertificatesManager certificatesManager = CertificatesManager.getInstance(); FileInputStream certKeyStream = new FileInputStream(new File(wxPayProperties.getCertKeyPath())); FileInputStream weChatPayStream = new FileInputStream(new File(wxPayProperties.getWeChatPayPath())); x509Certificate = PemUtil.loadCertificate(weChatPayStream); privateKey = PemUtil.loadPrivateKey(certKeyStream); certificatesManager.putMerchant(wxPayProperties.getMchId(), new WechatPay2Credentials(wxPayProperties.getMchId(), new PrivateKeySigner(wxPayProperties.getSerialNumber(), privateKey)), wxPayProperties.getApiV3Key().getBytes(StandardCharsets.UTF_8)); verifier = certificatesManager.getVerifier(wxPayProperties.getMchId()); 使用上述方式获取平台证书,在接受到微信通知后,使用verifier进行验签,报商户证书为空。传的参数 mchid 商户id,secrialnumber 商户序列号 这段代码写在@PostConstruct 注解的方法内,只初始化一次,后面用成员变量使用
2023-11-07CloseableHttpResponse response = httpclient.execute(httpGet); String bodyAsString = EntityUtils.toString(response.getEntity()); System.out.println(bodyAsString); 查看报文
特约商户进件-查询申请单状态API,应答的状态码不为200-299。status code[400]接口调用代码: CloseableHttpClient httpClient = WxHttpClient.createHttpClient(); HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/applyment4sub/applyment/business_code/" + businessCode); httpGet.addHeader("Accept", "application/json"); httpGet.addHeader("Content-type", "application/json; charset=utf-8"); CloseableHttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); WxAuthStatusResponse res = JSONObject.parseObject(EntityUtils.toString(entity), WxAuthStatusResponse.class); 工具类代码: public class WxHttpClient { // 设置VX证书默认参数 // 服务商Id private static final String merchantId = "163..."; // API V3密钥 private static final String apiV3Key = "zL3gprVKrr05..."; // 证书序列号 public static final String serialNumber = "2DD9DABDD05..."; public static CloseableHttpClient createHttpClient() { PrivateKey privateKey = createPrivateKey(); Verifier verifier = createVerifier(privateKey); WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create() .withMerchant(merchantId, serialNumber, privateKey) .withValidator(new WechatPay2Validator(verifier)); return builder.build(); } public static PrivateKey createPrivateKey() { InputStream inputStream = ResourceUtil.getStream("wx_pay/apiclient_key.pem"); return PemUtil.loadPrivateKey(inputStream); } public static Verifier createVerifier(PrivateKey privateKey) { try { CertificatesManager instance = CertificatesManager.getInstance(); instance.putMerchant(merchantId, new WechatPay2Credentials( merchantId, new PrivateKeySigner(serialNumber, privateKey)), apiV3Key.getBytes(StandardCharsets.UTF_8)); return instance.getVerifier(merchantId); } catch (GeneralSecurityException | NotFoundException | IOException | HttpCodeException e) { e.printStackTrace(); } return null; } } 响应返回内容: c.w.pay.contrib.apache.httpclient.SignatureExec > 应答的状态码不为200-299。status code[400] request headers[[Accept: application/json, Content-type: application/json; charset=utf-8, Authorization: WECHATPAY2-SHA256-RSA2048 mchid="1638262312",nonce_str="4X2TDkZuX94X55pxWoeaezI0rsSDvkZk",timestamp="1677857507",serial_no="2DD9DAB...",signature="tFEwJ6qmBCmmbADju/7VqtdL7vXsb8URSdsw69HwNVtRGyUcJASdyY391bOnjVB11SDR5t/a1uC+XhRalrwQN2IDJiJPWpL0OEZR7aKea5MV0YIgkmkldiDS3V8VgrBnuGAaTCDovgkHOrDibN6sVoy16zZmTAEGxCf5Vr/lUOsDa5IkfqdgsB7E25ZzCli4M4g7sKldOiGhUEVSynFEAbW9n3kgmjntlwKaoyU6D9ABSz5k8eGMGc4wO/EFGZQEnHj3SwLufB2xV1ub1ZkBrUv3fwau1BXiN1EwQ0Dxwmj/XVx6XXeJ7Tt4K9AKj1GJdnxBPPu1PbHdVZtL/jmPSQ==", Host: api.mch.weixin.qq.com, Connection: Keep-Alive, User-Agent: WechatPay-Apache-HttpClient/0.4.7 (Mac OS X/10.16) Java/1.8.0_322, Accept-Encoding: gzip,deflate]]
2023-11-06