通过商户进件接口提交进件信息:
String url = "https://api.mch.weixin.qq.com/v3/applyment4sub/applyment/";
String uri = "/v3/applyment4sub/applyment/";
// 发起请求
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(mediaType, jsonBody);
// 构建 Request 对象
String authorization = null;
try {
authorization = JSApiSignature.getAuthorization("POST",uri,jsonBody,
wechatPayConfig.getMchId(),
wechatPayConfig.getMchSerialNo(),
wechatPayConfig.getPrivateKeyPath());
} catch (Exception e) {
e.printStackTrace();
}
String schema = "WECHATPAY2-SHA256-RSA2048";
String authorizationValue = schema + " " + authorization;
System.out.println("authorizationValue=>"+authorizationValue);
Request request = new Request.Builder()
.addHeader("Authorization", authorizationValue)
.addHeader("Accept", "application/json")
.addHeader("Content-Type", "application/json")
.addHeader("Wechatpay-Serial", wechatPayConfig.getPublicKeyId())
.url(url)
.post(body)
.build();
// 创建 OkHttpClient 实例
OkHttpClient client = new OkHttpClient();
client.newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS);
// 同步发送请求
try (Response response = client.newCall(request).execute()) {
int respcode = response.code();
if (response.isSuccessful() && response.body() != null) {
String result = response.body().string();
System.out.println("响应编码="+respcode+",\n\r响应内容 Body: " + result);
log.info("result=>"+result);
return ReturnT.success(result);
} else {
System.out.println("请求失败:" + respcode);
String respstr = response.body().string();
log.info("商户入驻失败 respstr=>"+respstr); //{"code":"PARAM_ERROR","message":"平台私钥解密失败"}
//throw new RuntimeException("商户入驻失败:" + response.body().string());
return ReturnT.failure(respstr);
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("异常啦:"+e.getMessage());
return ReturnT.failure("异常啦:"+e.getMessage());
}
返回结果
Wrong HttpStatusCode[400]
httpResponseBody[{"code":"PARAM_ERROR","message":"平台私钥解密失败"}]
目前该商户平台已经启用公钥,平台证书已经废弃,之前在其他项目都能正常运行,不知道是哪里出问题了。
你好,请问问题是否已解决?检查下加密的证书/公钥,以及请求头传递的证书/公钥是否对应
我也遇到了这个报错,我怀疑是我使用的证书不对应导致的。但是我又找不到在哪下载这个证书,能帮忙说一下怎么下载这个证书文件吗?
这种报错就是加密使用的公钥/证书不对,要用微信支付公钥or微信支付平台证书
平台私钥解密的是敏感信息,你看看你的代码加密姓名/身份证号等敏感字段用的是不是平台公钥进行的加密