收藏
回答

同样的代码在其他项目正常,替换新的商户信息后,商户进件提示平台私钥解密失败?

通过商户进件接口提交进件信息:

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":"平台私钥解密失败"}]


目前该商户平台已经启用公钥,平台证书已经废弃,之前在其他项目都能正常运行,不知道是哪里出问题了。

回答关注问题邀请回答
收藏

4 个回答

  • 支付社区运营
    支付社区运营
    05-26

    你好,请问问题是否已解决?检查下加密的证书/公钥,以及请求头传递的证书/公钥是否对应

    05-26
    有用
    回复 1
    •  云帆
       云帆
      05-26
      目前问题已解决,使用公钥的时候建议直接通过内置工具类读取公钥内容,不要奖内容复制到项目中,容易出现空格或者其他转义情况。
      05-26
      1
      回复
  • mr. Brown
    mr. Brown
    07-04

    我也遇到了这个报错,我怀疑是我使用的证书不对应导致的。但是我又找不到在哪下载这个证书,能帮忙说一下怎么下载这个证书文件吗?

    07-04
    有用
    回复
  • Memory
    Memory
    05-24

    这种报错就是加密使用的公钥/证书不对,要用微信支付公钥or微信支付平台证书

    05-24
    有用
    回复 2
    •  云帆
       云帆
      发表于移动端
      05-24
      目前就是用的支付工钥,平台证书已经停用了的,再其他项目都能正常进件,到这里就不行了,给整不会了。
      05-24
      回复
    • Memory
      Memory
      05-24回复 云帆
      1000%用错了
      05-24
      回复
  • 北望沣渭
    北望沣渭
    05-23

    平台私钥解密的是敏感信息,你看看你的代码加密姓名/身份证号等敏感字段用的是不是平台公钥进行的加密

    05-23
    有用
    回复 7
    查看更多(2)
登录 后发表内容