资源简介

亲测,需要注意的地方在博客中有:http://blog.csdn.net/goligory/article/details/79274416

资源截图

代码片段和文件信息

package com.xiaojubianli.driver.biz.utils.pay;

import com.jpay.util.xmlHelper;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContexts;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import javax.net.ssl.SSLContext;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.util.Map;

/**
 * This example demonstrates how to create secure connections with a custom SSL
 * context.
 */
public class ClientCustomSSL {
    public Map doRefund(String url String dataHttpServletRequest request) throws Exception {
        /**
         * 注意PKCS12证书 是从微信商户平台-》账户设置-》 API安全 中下载的
         */
        String path=this.getClass().getClassLoader().getResource(“/“).getPath();
        String pathStr=path+ “apiclient_cert.p12“;
        System.out.println(“pathstr-->“+pathStr);
        KeyStore keyStore  = KeyStore.getInstance(“PKCS12“);
        FileInputStream instream = new FileInputStream(new File(pathStr));//P12文件目录
        try {
            /**
             * 此处要改
             * */
            keyStore.load(instream RefundUtil.mch_id.toCharArray());//这里写密码..默认是你的MCHID
        } finally {
            instream.close();
        }
        // Trust own CA and all self-signed certs
        /**
         * 此处要改
         * */
        SSLContext sslcontext = SSLContexts.custom()
                .loadKeyMaterial(keyStore RefundUtil.mch_id.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 {
            HttpPost httpost = new HttpPost(url); // 设置响应头信息
            httpost.addHeader(“Connection“ “keep-alive“);
            httpost.addHeader(“Accept“ “*/*“);
            httpost.addHeader(“Content-Type“ “application/x-www-form-urlencoded; charset=UTF-8“);
            httpost.addHeader(“Host“ “api.mch.weixin.qq.com“);
            httpost.addHeader(“X-Requested-With“ “xmlHttpRequest“);
            httpost.addHeader(“Cache-Control“ “max-age=0“);
            httpost.addHeader(“User-Agent“ “Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) “);
            httpost.setEntity(new StringEntity(data “UTF-8“));
            CloseableHttpResponse response = httpclient

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1985  2018-02-01 16:54  Sha1Util.java

     文件       3672  2018-02-01 16:54  TenpayUtil.java

     文件       3655  2018-02-01 16:54  ClientCustomSSL.java

     文件       1179  2018-02-01 16:54  MD5Util.java

     文件       2577  2018-02-06 22:05  RefundUtil.java

     文件       6399  2018-02-01 16:54  RequestHandler.java

----------- ---------  ---------- -----  ----

                19467                    6


评论

共有 条评论

相关资源