收藏
回答

v3 转账到零钱 支付 nginx 过不去

//官方提供的初始化客户端方法 无法通过 nginx


//privateKeyPath  私钥路径
String privateKey = new String(Files.readAllBytes(Paths.get(privateKeyPath)), "utf-8");
PrivateKey merchantPrivateKey = PemUtil.loadPrivateKey(privateKey);
//mchId  商户号
//wechatPayserialNo 证书序列号
//apiV3Key  支付密码
CertificatesManager instance = CertificatesManager.getInstance();    
instance.putMerchant(mchId, new WechatPay2Credentials(mchId,
                    new PrivateKeySigner(wechatPayserialNo, merchantPrivateKey)),
            apiV3Key.getBytes(StandardCharsets.UTF_8));

    Verifier verifier = instance.getVerifier(mchId);
    httpclient = WechatPayHttpClientBuilder.create()
            .withMerchant(mchId, wechatPayserialNo, merchantPrivateKey)
            .withValidator(new WechatPay2Validator(verifier))
            .build();

此方法返回


400 Bad Request

400 Bad Request


nginx





阿帕奇默认创建客户端 可以通过请求

CloseableHttpClient   httpClient = HttpClients.createDefault();

请问各路大神,导致这种情况的原因可能是什么?

最后一次编辑于  2022-11-08
回答关注问题邀请回答
收藏

1 个回答

  • 北望沣渭
    北望沣渭
    2022-11-08
    curl -v https://api.mch.weixin.qq.com/
    * Rebuilt URL to: https://api.mch.weixin.qq.com/
    *   Trying 101.91.0.140...
    * TCP_NODELAY set
    * Connected to api.mch.weixin.qq.com (101.91.0.140) port 443 (#0)
    * ALPN, offering h2
    * ALPN, offering http/1.1
    * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
    * successfully set certificate verify locations:
    *   CAfile: /etc/ssl/cert.pem
      CApath: none
    * TLSv1.2 (OUT), TLS handshake, Client hello (1):
    * TLSv1.2 (IN), TLS handshake, Server hello (2):
    * TLSv1.2 (IN), TLS handshake, Certificate (11):
    * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
    * TLSv1.2 (IN), TLS handshake, Request CERT (13):
    * TLSv1.2 (IN), TLS handshake, Server finished (14):
    * TLSv1.2 (OUT), TLS handshake, Certificate (11):
    * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
    * TLSv1.2 (OUT), TLS change cipher, Client hello (1):
    * TLSv1.2 (OUT), TLS handshake, Finished (20):
    * TLSv1.2 (IN), TLS change cipher, Client hello (1):
    * TLSv1.2 (IN), TLS handshake, Finished (20):
    * SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
    * ALPN, server accepted to use http/1.1
    * Server certificate:
    *  subject: C=CN; ST=Guangdong Province; L=Shenzhen; O=Tenpay Technology Company Limited; CN=payapp.weixin.qq.com
    *  start date: Sep 21 00:00:00 2022 GMT
    *  expire date: Oct 21 23:59:59 2023 GMT
    *  subjectAltName: host "api.mch.weixin.qq.com" matched cert's "*.mch.weixin.qq.com"
    *  issuer: C=US; O=DigiCert Inc; CN=DigiCert Secure Site CN CA G3
    *  SSL certificate verify ok.
    > GET / HTTP/1.1
    > Host: api.mch.weixin.qq.com
    > User-Agent: curl/7.54.0
    > Accept: */*
    >
    < HTTP/1.1 404 Not Found
    < Server: nginx
    < Date: Tue, 08 Nov 2022 03:51:23 GMT
    < Content-Type: text/html
    < Content-Length: 162
    < Connection: keep-alive
    < Keep-Alive: timeout=8
    <
    <html>
    <head><title>404 Not Found</title></head>
    <body bgcolor="white">
    <center><h1>404 Not Found</h1></center>
    <hr><center>nginx</center>
    </body>
    </html>
    * Connectio #0 to host api.mch.weixin.qq.com left intact
    

    你请求的URL不存在的话,默认返回就是404,例如上述 curl 命令行回显一样。

    2022-11-08
    有用
    回复 4
    • UU
      UU
      2022-11-08
      不是 404   是 400      使用 HttpClients.createDefault();就可以请求成功  使用    httpclient = WechatPayHttpClientBuilder.create().build();  返回的是 400
      2022-11-08
      回复
    • UU
      UU
      2022-11-08回复卞柘
      同一个求地址   这个是创建httpPost 的方法       
      请求地址  https://api.mch.weixin.qq.com/v3/transfer/batches
      2022-11-08
      回复
    • UU
      UU
      2022-11-08回复卞柘
      跟url 没关系
      2022-11-08
      回复
    • UU
      UU
      2022-11-08回复卞柘
      不要捣乱,谢谢
      2022-11-08
      回复
登录 后发表内容