热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

微信支付退款接口调用证书出现错误

PS:代码是copy腾讯提供的demo,但运行有问题,望大拿能够帮忙解决

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();
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    // 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();

    }



   



推荐阅读
author-avatar
是远航呀
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有