https:
try{ StringBuffer reultBuffer = new StringBuffer(); KeyStore keyStore = KeyStore.getInstance("PKCS12"); FileInputStream instream = new FileInputStream(new File("/home/certificate/apiclient_cert.p12")); String passwordssss=mch_id; keyStore.load(instream, passwordssss.toCharArray()); //证书密码 instream.close(); SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, passwordssss.toCharArray()).build(); //证书密码(初始是商户ID) SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,new String[] { "TLSv1" },null,SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); HttpPost httpPost = new HttpPost("https://fraud.mch.weixin.qq.com/risk/getpublickey"); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); httpPost.setHeader("Content-Type", "text/xml; charset=UTF-8"); httpPost.setEntity(new StringEntity(str_lingqian.toString(),"UTF-8")); CloseableHttpResponse response = null; InputStream inputStream = null; InputStreamReader inputStreamReader = null; BufferedReader bufferedReader = null; try { response = httpclient.execute(httpPost); HttpEntity entity = response.getEntity(); if (entity!=null){ inputStream = entity.getContent(); inputStreamReader = new InputStreamReader(inputStream,"UTF-8"); bufferedReader = new BufferedReader(inputStreamReader); String str = null; while ((str = bufferedReader.readLine()) != null) { reultBuffer.append(str); System.out.println(str); } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally{ httpclient.close(); response.close(); bufferedReader.close(); inputStreamReader.close(); inputStream.close(); inputStream = null; } Document document = DocumentHelper.parseText(reultBuffer.toString()); Element rootElm = document.getRootElement(); if(rootElm.elementText("return_code").toString().equals("SUCCESS") && rootElm.elementText("result_code").toString().equals("SUCCESS") ){ pub_key = rootElm.elementText("pub_key").toString(); System.out.println("pub_key = "+pub_key); }else{ return status; } }catch(Exception e){ e.printStackTrace(); }