微信支付退款接口调用证书出现错误
PS:代码是copy腾讯提供的demo,但运行有问题,望大拿能够帮忙解决
加载证书时间出现如下错误:
java.io.IOException: DER input, Integer tag error
at sun.security.util.DerInputStream.getInteger(DerInputStream.java:151)
at com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1202)
at java.security.KeyStore.load(KeyStore.java:1183)
at com.caibeike.tps.utils.HttpTookit.doSSLPostP12(HttpTookit.java:86)
at com.caibeike.tps.finance.controller.RefundController.submitTenRefundBatch(RefundController.java:184)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
我的代码:
KeyStore keyStore = KeyStore.getInstance("PKCS12");
FileInputStream instream = new FileInputStream(p12FilePath);
char[] pwd = p12Pwd.toCharArray();
try {
keyStore.load(instream, pwd);
} catch(Exception e){
e.printStackTrace();
} finally {
instream.close();
}
// Trust own CA and all self-signed certs
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, p12Pwd.toCharArray()).build();
// Allow TLSv1 protocol only
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null,
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
try {
HttpGet httpget = new HttpGet(urlStr);
System.out.println("executing request" + httpget.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httpget);
try {
HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
String text;
while ((text = bufferedReader.readLine()) != null) {
System.out.println(text);
}
}
EntityUtils.consume(entity);
} finally {
response.close();
}
} finally {
httpclient.close();
}
相关阅读:
关于ajax动态创建结构相同的页面
a标签里面包含div、p标签是否符合W3C标准?W3C标准中的语义化指的是什么?
判断ID为标准,写入数据~~
CodeIgniter 是否支持PDO查询?给个例子
ThinkPHP 验证
js 设置cookie 后 重启浏览器 cookie消失 , expire 已添加
Python 查看曾经用过的命令列表
thinkphp中控制器的划分有什么规范吗?
node.js express node-fetch
通过下拉框绑定Js函数来切换内容,为什么在弹出框中内容只能叠加,不能切换
用canvas画一个面积图。但是不需要坐标系,鼠标hover可以变色
某些网页总是自动重定向, 如何排查问题出现在哪里?
微支付 NativeCall 商户后台返回的数据字段结构不合法
CSS 三列等高布局的疑问 margin负补偿
redis的increase操作,支持的最大值是多少?
js限制文本输入框只能输入数字
MySQL,`column` like '一些文字' 是否就等于 `column` = '一些文字',有什么区别是呢?
laravel5.2,上传文件失败
如何用Pythonic的方法求一个字符的往后两位字符?
哪儿可以下载到很多mysql数据;