response=HttpResponseProxy{HTTP/1.1 400 Bad Request [Server: nginx, Date: Thu, 09 Jul 2020 01:26:53 GMT, Content-Type: text/html, Content-Length: 166, Connection: close] ResponseEntityProxy{[Content-Type: text/html,Content-Length: 166,Chunked: false]}}
400 Bad Request 是由于明显的客户端错误(例如,格式错误的请求语法,太大的大小,无效的请求消息或欺骗性路由请求),服务器不能或不会处理该请求。应该是你本地的请求语法有问题。麻烦仔细检查一下。
InputStream inputStream = classPathResource.getInputStream();
PrivateKey merchantPrivateKey = PemUtil.loadPrivateKey(inputStream);
WechatPay2Credentials wechatPay2Credentials = new WechatPay2Credentials(mchId, new PrivateKeySigner(mchSerialNo, merchantPrivateKey));
AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(wechatPay2Credentials,
apiV3Key.getBytes(PayConstant.WXPAY_CHARSET));
CloseableHttpClient httpClient = WechatPayHttpClientBuilder.create()
.withMerchant(mchId, mchSerialNo, merchantPrivateKey)
.withValidator(new WechatPay2Validator(verifier))
.build();
// 封装请求参数
String req = JSONUtil.toJsonStr(applymentObj);
log.info("生成请求微信商户入驻申请数据,req={}", req);
HttpPost request = new HttpPost(PayConstant.MERCHANT_APPLY);
request.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()+"; charset="+ContentType.APPLICATION_JSON.getCharset().name());
request.addHeader("Wechatpay-Serial", mchSerialNo);
request.addHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType());
request.addHeader(HttpHeaders.USER_AGENT, "wxpay sdk java v1.0 " + mchId);
request.setEntity(new StringEntity(req, ContentType.APPLICATION_JSON.getCharset()));
request.setHeader(HttpHeaders.AUTHORIZATION, wechatPay2Credentials.getSchema() + " " + wechatPay2Credentials.getToken(HttpRequestWrapper.wrap(request)));
CloseableHttpResponse response = httpClient.execute(request);
请问我那个请求语法不对呀?
PayConstant.MERCHANT_APPLY 你的这个常量可能定义错了,切记不能少了末尾的斜杠(/ slash),少了即400错了
有/呢
const {Wechatpay} = require('wechcatpay-axios-plugin');
// js代码,构造参数隐去了
new Wechatpay({ mchid, serial, privateKey, certs });
•
;(async () => {
try {
//这是能复现你的请求示例
await Wechatpay.client.post('/v3/applyment4sub/applyment', {})
} catch({response: {status, statusText, data, headers}}) {
console.info(status, statusText, headers, data)
}
})()
// 404 Not Found {
// server: 'nginx',
// date: 'Thu, 09 Jul 2020 07:08:17 GMT',
// 'content-type': 'text/html',
// 'content-length': '162',
// connection: 'close'
// } <html>
// <head><title>404 Not Found</title></head>
// <body bgcolor="white">
// <center><h1>404 Not Found</h1></center>
// <hr><center>nginx</center>
// </body>
// </html>
//
// <center><h1>404 Not Found</h1></center>