wzy
2021-01-10 16da0ad1fda1dffa3019425a6887d38ed4217f44
zq-erp/src/main/java/com/matrix/component/wechat/externalInterface/common/HttpsRequest2.java
@@ -56,6 +56,10 @@
    //HTTP请求器
    private CloseableHttpClient httpClient;
    //证书地址
    private String  certLocalPath;
    //商户号
    private String mchId;
    public HttpsRequest2() throws UnrecoverableKeyException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException, IOException {
        init();
@@ -64,9 +68,9 @@
    private void init() throws IOException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyManagementException {
       KeyStore keyStore = KeyStore.getInstance("PKCS12");
       FileInputStream instream = new FileInputStream(new File(WechatConfigure.certLocalPath));//加载本地的证书进行https加密传输
        FileInputStream instream = new FileInputStream(new File(certLocalPath));//加载本地的证书进行https加密传输
        try {
            keyStore.load(instream,WechatConfigure.certPassword.toCharArray());//设置证书密码
            keyStore.load(instream, mchId.toCharArray());//设置证书密码
        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
@@ -76,7 +80,7 @@
        }
        // Trust own CA and all self-signed certs
        SSLContext sslcontext = SSLContexts.custom()
                .loadKeyMaterial(keyStore, WechatConfigure.certPassword.toCharArray())
                .loadKeyMaterial(keyStore, mchId.toCharArray())
                .build();
        // Allow TLSv1 protocol only
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
@@ -199,4 +203,21 @@
    public void setRequestConfig(RequestConfig requestConfig) {
       this.requestConfig = requestConfig;
    }
    public String getMchId() {
        return mchId;
    }
    public void setMchId(String mchId) {
        this.mchId = mchId;
    }
    public String getCertLocalPath() {
        return certLocalPath;
    }
    public void setCertLocalPath(String certLocalPath) {
        this.certLocalPath = certLocalPath;
    }
}