问题描述:
普通商户调用单次分账接口一直报错,使用工具校验签名是校验正确通过的,请问这是什么问题?请求需要双向证书,请问是我代码加载p12证书有问题吗?还是证书加载错误了?
错误提示:
{"chunked":false,"contentLength":476,"contentType":{"buffer":{"empty":false,"full":false},"elements":[{"name":"text/plain","parameterCount":1,"parameters":[{"name":"charset","value":"UTF-8"}]}],"name":"Content-Type","value":"text/plain;charset=UTF-8","valuePos":13},"repeatable":false,"streaming":true}
具体代码如下:
// 调用请求单次分账接口必需传的参数
jsonArray.add(jsonObject);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("appid",APPID)); //服务商商户号对应服务号的appid
nvps.add(new BasicNameValuePair("mch_id",mchId));//服务商商户号
nvps.add(new BasicNameValuePair("nonce_str",nonceStr));
nvps.add(new BasicNameValuePair("out_order_no",profitSharingUuid));//商户系统内部的分账单号
nvps.add(new BasicNameValuePair("receivers",jsonArray.toJSONString()));
nvps.add(new BasicNameValuePair("transaction_id",profit.getTransaction_id()));
StringBuffer sb = new StringBuffer();
for (NameValuePair nvp : nvps) {
sb.append(nvp.getName() + "=" + nvp.getValue() + "&");
}
String signA = sb.toString();
String stringSignTemp = signA + "key="+apiV3Key; // key是服务商商户号的密钥
String sign = HMACSHA256(stringSignTemp, apiV3Key);//校验通过
nvps.add(new BasicNameValuePair("sign", sign)); // 把签名后的数据组装成参数
//加载P12证书并POST调用单次请求接口
CloseableHttpResponse response=null;
try {
KeyStore clientStore = KeyStore.getInstance("PKCS12");
// 读取本机存放的PKCS12证书文件
FileInputStream inputStream =new FileInputStream(certPath);
try {
// 指定PKCS12的密码(商户ID)
clientStore.load(inputStream, certPass.toCharArray());
}finally {
inputStream.close();
}
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(clientStore,
certPass.toCharArray()).build();
// 指定TLS版本
SSLConnectionSocketFactory sslsf =new SSLConnectionSocketFactory(sslcontext, new
String[]{"TLSv1"}, null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
// 设置httpclient的SSLSocketFactory
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
try {
HttpPost httpost =new HttpPost(url); // 设置响应头信息
httpost.addHeader("Connection", "keep-alive");
httpost.addHeader("Accept", "*/*");
httpost.addHeader("Content-Type", "text/xml");
httpost.addHeader("X-Requested-With", "XMLHttpRequest");
httpost.addHeader("Cache-Control", "max-age=0");
httpost.addHeader("User-Agent", "*");
httpost.setEntity(new StringEntity(data, "UTF-8"));
response = httpclient.execute(httpost);
}finally {
httpclient.close();
}
你分账请求的哪个文档的接口,发一下,虽然V3接口当前可以打分账标识了,但是分账请求接口还是V2
这错误信息不是官方返回吧?
java不知道怎么加载证书。。
另外分账也不是v3key.