请求URL:https://api.mch.weixin.qq.com/v3/pay/transactions/h5
请求方式:POST
PrivateKey merchantPrivateKey = PemUtil.loadPrivateKey(
new ByteArrayInputStream(privateKey.getBytes("utf-8")));
//使用自动更新的签名验证器,不需要传入证书
verifier = new AutoUpdateCertificatesVerifier(
new WechatPay2Credentials(mchId, new PrivateKeySigner(mchSerialNo, merchantPrivateKey)),
apiV3Key.getBytes("utf-8"));
httpClient = WechatPayHttpClientBuilder.create()
.withMerchant(mchId, mchSerialNo, merchantPrivateKey)
.withValidator(new WechatPay2Validator(verifier))
.build();
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/h5");
String data = "{\n" +
" \"time_expire\": \"2018-06-08T10:34:56+08:00\",\n" +
" \"amount\": {\n" +
" \"total\": 100,\n" +
" \"currency\": \"CNY\"\n" +
" },\n" +
" \"mchid\": \"商户id\",\n" +
" \"description\": \"Image形象店-深圳腾大-QQ公仔\",\n" +
" \"notify_url\": \" https://www.weixin.qq.com/wxpay/pay.php\",\n" +
" \"out_trade_no\": \"1217752501201407033233368019\",\n" +
" \"appid\": \"appid\",\n" +
" \"scene_info\": {\n" +
" \"h5_info\": {\n" +
" \"type\": \"iOSAndroidWap\"\n" +
" },\n" +
" \"payer_client_ip\": \"14.23.150.211\"\n" +
" }\n" +
"}";
StringEntity reqEntity = new StringEntity(
data, ContentType.create("application/json", "utf-8"));
httpPost.setEntity(reqEntity);
httpPost.addHeader("Accept", "application/json");
httpPost.addHeader("Wechatpay-Serial", "微信支付平台生成的证书得序列号");//请求头这里加了Wechatpay-Serial,加不加都是400错误
CloseableHttpResponse response = httpClient.execute(httpPost);
//httpClient构建的时候会组装好Authorization,Authorization里面放的商户签名,是普通商户不能用这个api吗?
已解决,官方demo回调地址多个空格,坑了好几天、、、
你好,400 bad request,一般是你的请求中语法有问题。https://wechatpay-api.gitbook.io/wechatpay-api-v3/,参考V3签名文档以及https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transactions/chapter3_4.shtml普通商户H5支付进行调整。可选用Postman先进行调试。