package com.winsun.utils;

import com.alibaba.fastjson.JSONException;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
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.SSLContextBuilder;
import org.apache.http.conn.ssl.TrustStrategy;
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 org.json.JSONTokener;

import javax.net.ssl.SSLContext;
import javax.security.cert.CertificateException;
import javax.security.cert.X509Certificate;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;

public class HTTPSClient {
    /**
     * 向指定 URL 发送POST方法的请求
     *
     * @param url   发送请求的 URL
     * @param param 请求参数，请求参数应该是 name1=value1&name2=value2 的形式。
     * @return 所代表远程资源的响应结果
     */
    // 不走代理
    public static String sendPost(String url, String param) {
        String result = "";
        CloseableHttpClient httpClient = HTTPSClient.createSSLClientDefault();
        HttpPost post = new HttpPost(url);
        StringEntity s = new StringEntity(param, "UTF-8"); // 中文乱码在此解决

        s.setContentType("application/json");
        post.setEntity(s);
        HttpResponse res;
        try {
            res = httpClient.execute(post);
            if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                HttpEntity entity = res.getEntity();
                if (entity.getContentLength() > 0) {
                    String charset = EntityUtils.getContentCharSet(entity);
                    org.json.JSONObject response = new org.json.JSONObject(new JSONTokener(new InputStreamReader(entity.getContent(), charset)));
                    result = response.toString();
                    System.out.println(result);
                }
            }

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        } finally {
            try {
                httpClient.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return result;
    }

    /**
     * 向指定 URL 发送POST方法的请求
     *
     * @param url   发送请求的 URL
     * @param param 请求参数，请求参数应该是 name1=value1&name2=value2 的形式。
     * @return 所代表远程资源的响应结果
     */
    // 走代理
    public static String sendPostAgent(String url, String param) {
        String string = "";

        CloseableHttpClient httpClient = HTTPSClient.createSSLClientDefault();
        HttpPost httpPost = new HttpPost(url);
        StringEntity s = new StringEntity(param, "UTF-8"); // 中文乱码在此解决
        s.setContentType("application/json");
        httpPost.setEntity(s);

        try {
            HttpHost proxy = new HttpHost("172.18.101.170", 3128);
            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(200000).setConnectTimeout(200000).setProxy(proxy).build();

            httpPost.setConfig(requestConfig);
            CloseableHttpResponse result = httpClient.execute(httpPost);
            string = EntityUtils.toString(result.getEntity(), "utf-8");

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } finally {
            try {
                httpClient.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return string;
    }

    /**
     * 向指定 URL 发送POST方法的请求
     *
     * @param url   发送请求的 URL
     * @param param 请求参数，请求参数应该是 name1=value1&name2=value2 的形式。
     * @return 所代表远程资源的响应结果
     */
    public static String sendCodePost(String url, String param) {
        String string = "";

        CloseableHttpClient httpClient = HTTPSClient.createSSLClientDefault();
        HttpPost httpPost = new HttpPost(url);
        StringEntity s = new StringEntity(param, "UTF-8"); // 中文乱码在此解决
        //s.setContentEncoding("UTF-8");


        s.setContentType("application/json");
        httpPost.setEntity(s);
        try {
            HttpHost proxy = new HttpHost("172.18.101.170", 3128);
            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(200000).setConnectTimeout(200000).setProxy(proxy).build();

            httpPost.setConfig(requestConfig);
            CloseableHttpResponse result = httpClient.execute(httpPost);
            string = EntityUtils.toString(result.getEntity(), "utf-8");

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } finally {
            try {
                httpClient.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return string;
    }

//	public static String sendCodePost(String url, String param) {
//		String result = "";
//
//		CloseableHttpClient httpClient = HTTPSClient.createSSLClientDefault();
//		HttpPost post = new HttpPost(url);
//		StringEntity s = new StringEntity(param, "UTF-8"); // 中文乱码在此解决
//		//s.setContentEncoding("UTF-8");  
//	
//
//		s.setContentType("application/json");
//		post.setEntity(s);
//		HttpResponse res;
//		try {
//			res = httpClient.execute(post);
//			if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
//				HttpEntity entity = res.getEntity();
//				if (entity.getContentLength() > 0) {
//					String charset = EntityUtils.getContentCharSet(entity);
//					org.json.JSONObject response = new org.json.JSONObject(new JSONTokener(new InputStreamReader(entity.getContent(), charset)));
//					result = response.toString();
//					System.out.println(result);
//				}
//			}
//
//		} catch (ClientProtocolException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		} catch (IllegalStateException e) {
//			e.printStackTrace();
//		} catch (JSONException e) {
//			e.printStackTrace();
//		}finally {
//			try {
//				httpClient.close();
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
//
//		return result;
//	}


    /**
     * 向指定 URL 发送POST方法的请求
     *
     * @param url   发送请求的 URL
     * @param param 请求参数，请求参数应该是 name1=value1&name2=value2 的形式。
     * @return 所代表远程资源的响应结果
     */
    public static String sendPosts(String url, String param) {
        PrintWriter out = null;
        BufferedReader in = null;
        String result = "";
        // 打开和URL之间的连接
        URLConnection conn = null;
        try {
            URL realUrl = new URL(url);
            conn = realUrl.openConnection();
            // 设置通用的请求属性
            ///	conn.setRequestProperty("accept", "*/*");
            //	conn.setRequestProperty("connection", "Keep-Alive");
            //	conn.setRequestProperty("user-agent",
            //			"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 发送POST请求必须设置如下两行
            conn.setDoOutput(true);
            conn.setDoInput(true);
            // 获取URLConnection对象对应的输出流
            out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), "utf-8"));
            // 发送请求参数
            out.print(param);
            // flush输出流的缓冲
            out.flush();
            // 定义BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(
                    conn.getInputStream(), "utf-8"));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            System.out.println("发送 POST 请求出现异常！" + e);
            e.printStackTrace();
        }
        // 使用finally块来关闭输出流、输入流
        finally {
            if (out != null) {
                try {
                    out.close();
                } catch (Exception ex) {
                }
            }
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ex) {
                }
            }
            try {
                if (conn.getInputStream() != null) {
                    conn.getInputStream().close();
                }
            } catch (IOException ex) {
            }

            try {
                if (conn.getOutputStream() != null) {
                    conn.getOutputStream().close();
                }
            } catch (IOException ex) {
            }
        }
        return result;
    }


    // 原方法 不走代理
    public static String sendGet(String url) {
        String result = "";
        HttpClient client = new HttpClient();
        GetMethod getMethod = new GetMethod(url);
        getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 25000);
        try {
            int statusCode = client.executeMethod(getMethod);
            if (statusCode == HttpStatus.SC_OK) {
                result = getMethod.getResponseBodyAsString(); // 出现中文乱码
                // result = new String(getMethod.getResponseBody(),"utf-8");
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }

        return result;
    }

    // 新方法 走代理
    public static String sendGet2(String url) {
        String string = "";
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(url);
        try {
            HttpHost proxy = new HttpHost("172.18.101.170", 3128);
            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(200000).setConnectTimeout(200000).setProxy(proxy).build();
            httpPost.setConfig(requestConfig);
            CloseableHttpResponse result = httpClient.execute(httpPost);
            string = EntityUtils.toString(result.getEntity(), "utf-8");
            ;

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }
        return string;
    }

    /**
     * 发送xml请求到server端
     *
     * @param url       xml请求数据地址
     * @param xmlString 发送的xml数据流
     * @return null发送失败，否则返回响应内容
     * @throws IOException
     */
    public static String sendPostXml(String url, String xmlString) throws IOException {
        //创建httpclient工具对象
        HttpClient client = new HttpClient();
        //创建post请求方法     
        PostMethod myPost = new PostMethod(url);
        //设置请求超时时间
        client.setConnectionTimeout(3000 * 1000);
        String responseString = null;
        InputStream inputStream = null;
        BufferedReader br = null;
        try {
            //设置请求头部类型     
            myPost.setRequestHeader("Content-Type", "text/xml");
            myPost.setRequestHeader("charset", "utf-8");
            //设置请求体，即xml文本内容，一种是直接获取xml内容字符串，一种是读取xml文件以流的形式     
            myPost.setRequestBody(xmlString);
            int statusCode = client.executeMethod(myPost);
            //只有请求成功200了，才做处理  
            if (statusCode == HttpStatus.SC_OK) {
                inputStream = myPost.getResponseBodyAsStream();
                br = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
                StringBuffer stringBuffer = new StringBuffer();
                String str = "";
                while ((str = br.readLine()) != null) {
                    stringBuffer.append(str);
                }
                responseString = stringBuffer.toString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            myPost.releaseConnection();
            if (null != inputStream)
                inputStream.close();

            if (null != br)
                br.close();
        }
        return responseString;
    }

    public static void main(String[] args) throws ClientProtocolException,
            IOException, IllegalStateException, JSONException {

//		String test = "{"
//				+ "\"articles\": ["
//				+	 "{"
//			     +                   "\"thumb_media_id\":\"rmuGybyc35bNvEADz__r_GCnKpu0NNRvFi7wG-4MgiT1B171IgbyJKaeNS95Pi-Y\","
//			     +                   "\"author\":\"xxx\","
//				+		 "\"title\":\"Happy Day\","
//				+		 "\"content_source_url\":\"www.qq.com\","
//				+		"\"content\":\"content\","
//				+		 "\"digest\":\"digest\","
//			    +                    "\"show_cover_pic\":1"
//				+	 "},"
//				+	 "{"
//			     +                   "\"thumb_media_id\":\"rmuGybyc35bNvEADz__r_GCnKpu0NNRvFi7wG-4MgiT1B171IgbyJKaeNS95Pi-Y\","
//			     +                   "\"author\":\"xxx\","
//				+		 "\"title\":\"Happy Day\","
//				+		 "\"content_source_url\":\"www.qq.com\","
//				+		 "\"content\":\"content\","
//				+		 "\"digest\":\"digest\","
//			    +                    "\"show_cover_pic\":0"
//				+	 "}"
//			 +  "]"
//			+"}";


//		String test = "{"
//					+   "\"filter\":{"
//					+      "\"is_to_all\":true"
//					+   "},"
//					+   "\"mpnews\":{"
//					+      "\"media_id\":\"jOhPKihXdmEfo2VXsf1w4mv-eDz2cQl1DyOHrQaHw2srrEFFHuzb8w2aJZyMIE_5\""
//					+   "},"
//					+    "\"msgtype\":\"mpnews\""
//					+"}";

//		String test = "{"
//		+   "\"filter\":{"
//		+      "\"is_to_all\":true"
//		+   "},"
//		+   "\"text\":{"
//		+      "\"content\":\"啊哈哈（30+70）哈哈\""
//		+   "},"
//		+    "\"msgtype\":\"text\""
//		+"}";
//		
//		String id =  "{"
//					+	  "\"msg_id\":1000000019"
//					+ "}";
//		
//		String access = WxInterfacesUtil.getToken("client_credential", WxConfig.APPID, WxConfig.APPSECRET);
        String url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=63jVygxyIkK6oUCeM2YuzZHYLuzrkhSf6eDwmdd2HkXvIxnbfYIzQNMnt7deEWugUUobmyxNrZZa4gEMx1G0wtEJFqofT1sA3yvm9ZVctGPEG0B9DO0L8c3j3cnCC5XtZYRhAEATSL";
//		String urldel = "https://api.weixin.qq.com/cgi-bin/message/mass/delete?access_token=" + access;
//		String urlup = "https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=" + access;
//		
////		
//		String result = sendPosts(url, test);
//		String reul = "";
        //	WxInterfacesUtil.sendMessage_text("dd","dd","dd");

        PropertiesInit pinit = new PropertiesInit();
        pinit.initProperties();

        returnMenu(pinit);
    }

    public static String returnMenu(PropertiesInit ppp) {

//		WxInterfacesUtil.sendGroupMessage_text("", "", "");
        JSONObject button = new JSONObject();

        try {
            String Weixin = ppp.getProperties("Weixin");

            //  part1
            String menu_tdhd = ppp.getProperties("wx_menu_tdhd");
            String menu_grhd = ppp.getProperties("wx_menu_grhd");
            String menu_lshd = ppp.getProperties("wx_menu_lshd");

            String menu_ywdj = ppp.getProperties("wx_menu_ywdj");
            String menu_xscx = ppp.getProperties("wx_menu_xscx");
            String menu_xsgj = ppp.getProperties("wx_menu_xsgj");
            String menu_fhdj = ppp.getProperties("wx_menu_fhdj");

            String menu_userInfo = ppp.getProperties("wx_menu_userInfo");
            String menu_register = ppp.getProperties("wx_menu_register");
            String menu_czzj = ppp.getProperties("wx_menu_czzj");
            String menu_twzf = ppp.getProperties("wx_menu_twzf");
            String menu_yrym = ppp.getProperties("wx_menu_yrym");
            //String menu_blzc = ppp.getProperties("wx_menu_blzc");

            // part2
            menu_tdhd = URLEncoder.encode(menu_tdhd, "UTF-8");
            menu_grhd = URLEncoder.encode(menu_grhd, "UTF-8");
            menu_lshd = URLEncoder.encode(menu_lshd, "UTF-8");

            menu_ywdj = URLEncoder.encode(menu_ywdj, "UTF-8");
            menu_xscx = URLEncoder.encode(menu_xscx, "UTF-8");
            menu_xsgj = URLEncoder.encode(menu_xsgj, "UTF-8");
            menu_fhdj = URLEncoder.encode(menu_fhdj, "UTF-8");

            menu_userInfo = URLEncoder.encode(menu_userInfo, "UTF-8");
            menu_register = URLEncoder.encode(menu_register, "UTF-8");
            menu_czzj = URLEncoder.encode(menu_czzj, "UTF-8");
            menu_twzf = URLEncoder.encode(menu_twzf, "UTF-8");
            menu_yrym = URLEncoder.encode(menu_yrym, "UTF-8");
            //menu_blzc = URLEncoder.encode(menu_blzc, "UTF-8");

            //part3
            menu_tdhd = Weixin.replace("redirect_uri=", "redirect_uri=" + menu_tdhd);
            menu_grhd = Weixin.replace("redirect_uri=", "redirect_uri=" + menu_grhd);
            menu_lshd = Weixin.replace("redirect_uri=", "redirect_uri=" + menu_lshd);


            menu_xsgj = Weixin.replace("redirect_uri=", "redirect_uri=" + menu_xsgj);
            menu_fhdj = Weixin.replace("redirect_uri=", "redirect_uri=" + menu_fhdj);

            menu_ywdj = Weixin.replace("redirect_uri=", "redirect_uri=" + menu_ywdj);
            menu_xscx = Weixin.replace("redirect_uri=", "redirect_uri=" + menu_xscx);

            menu_register = Weixin.replace("redirect_uri=", "redirect_uri=" + menu_register);
            menu_userInfo = Weixin.replace("redirect_uri=", "redirect_uri=" + menu_userInfo);
            menu_czzj = Weixin.replace("redirect_uri=", "redirect_uri=" + menu_czzj);
            menu_twzf = Weixin.replace("redirect_uri=", "redirect_uri=" + menu_twzf);
            menu_yrym = Weixin.replace("redirect_uri=", "redirect_uri=" + menu_yrym);
            //menu_blzc = Weixin.replace("redirect_uri=", "redirect_uri="+ menu_blzc);

            JSONArray menu = new JSONArray();
            JSONArray menuList1 = new JSONArray();
            JSONObject menu1 = new JSONObject();
            menu1.put("name", "活动参与");
            menu1.put("type", "click");

            JSONObject btn11 = new JSONObject();
            btn11.put("name", "个人活动参与");
            btn11.put("key", "m11");
            btn11.put("type", "view");
            btn11.put("url", menu_grhd);

            JSONObject btn12 = new JSONObject();
            btn12.put("name", "团队活动参与");
            btn12.put("key", "m12");
            btn12.put("type", "view");
            btn12.put("url", menu_tdhd);

            JSONObject btn13 = new JSONObject();
            btn13.put("name", "历史活动查询");
            btn13.put("key", "m13");
            btn13.put("type", "view");
            btn13.put("url", menu_lshd);

            JSONObject btn14 = new JSONObject();
            btn14.put("name", "飞行考试");
            btn14.put("key", "m14");
            btn14.put("type", "view");
            btn14.put("url", "https://ks.sojump.hk/jq/15330543.aspx");

            JSONObject btn15 = new JSONObject();
            btn15.put("name", "训练营报名");
            btn15.put("key", "m15");
            btn15.put("type", "view");
            btn15.put("url", "https://jinshuju.net/f/wTrBil");

            menuList1.add(btn11);
            menuList1.add(btn12);
            menuList1.add(btn13);
            menuList1.add(btn14);
            menuList1.add(btn15);
            menu1.put("sub_button", menuList1);

            menu.add(menu1);

            /*********************/
            JSONArray menuList2 = new JSONArray();

            JSONObject menu2 = new JSONObject();
            menu2.put("name", "业务销售");
            menu2.put("key", "m20");

            JSONObject btn21 = new JSONObject();
            btn21.put("name", "业务登记");
            btn21.put("key", "m21");
            btn21.put("type", "view");
            btn21.put("url", menu_ywdj);

//			JSONObject btn22 = new JSONObject();
//			btn22.put("name", "历史销量查询");
//			btn22.put("key", "m22");
//			btn22.put("type", "view");
//			btn22.put("url", menu_xscx);

            JSONObject btn22 = new JSONObject();
            btn22.put("name", "放号登记");
            btn22.put("key", "m22");
            btn22.put("type", "view");
            btn22.put("url", menu_fhdj);

            JSONObject btn23 = new JSONObject();
            btn23.put("name", "网络测速");
            btn23.put("key", "m23");
            btn23.put("type", "view");
            btn23.put("url", "http://tool.cncn.com/cewangsu/");

            JSONObject btn24 = new JSONObject();
            btn24.put("name", "小白卡销售");  // 即销售工具
            btn24.put("key", "m24");
            btn24.put("type", "view");
            btn24.put("url", menu_xsgj);

            JSONObject btn25 = new JSONObject();
            btn25.put("name", "电子传单");
            btn25.put("key", "m25");
            btn25.put("type", "view");
            btn25.put("url", "http://a.xiumi.us/stage/v5/2Zq72/44772355");

            menuList2.add(btn21);
            menuList2.add(btn22);
            menuList2.add(btn23);
            menuList2.add(btn24);
            menuList2.add(btn25);
            menu2.put("sub_button", menuList2);

            /***********************/

            JSONArray menuList3 = new JSONArray();

            JSONObject menu3 = new JSONObject();
            menu3.put("name", "用户管理");
            menu3.put("key", "m30");

            JSONObject btn31 = new JSONObject();
            btn31.put("name", "报名加入");
            btn31.put("key", "m31");
            btn31.put("type", "view");
            btn31.put("url", menu_register);

//			JSONObject btn32 = new JSONObject();
//			btn32.put("name", "部落成员注册");
//			btn32.put("key", "m32");
//			btn32.put("type", "view");
//			btn32.put("url", menu_blzc);

            JSONObject btn32 = new JSONObject();
            btn32.put("name", "个人信息");
            btn32.put("key", "m32");
            btn32.put("type", "view");
            btn32.put("url", menu_userInfo);

            JSONObject btn33 = new JSONObject();
            btn33.put("name", "成长足迹");
            btn33.put("key", "m33");
            btn33.put("type", "view");
            btn33.put("url", menu_czzj);

            JSONObject btn34 = new JSONObject();
            btn34.put("name", "推文转发");
            btn34.put("key", "m34");
            btn34.put("type", "view");
            btn34.put("url", menu_twzf);

            JSONObject btn35 = new JSONObject();
            btn35.put("name", "一人一码");
            btn35.put("key", "m35");
            btn35.put("type", "view");
            btn35.put("url", menu_yrym);

            menuList3.add(btn31);
            menuList3.add(btn32);
            menuList3.add(btn33);
            menuList3.add(btn34);
            menuList3.add(btn35);
            menu3.put("sub_button", menuList3);

            menu.add(menu2);
            menu.add(menu3);

            button.put("button", menu);
            System.out.println(button.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String formateURL(String url) {
        if (url != null) {
            url = "http://open.plus.yixin.im/connect/oauth2/authorize?appid=9e65cdacfb9e4f3b820031d7af01fceb&redirect_uri="
                    + url
                    + "&response_type=code&scope=snsapi_base&state=from_menu";
            return url;
        } else {
            return null;
        }

    }

    public static CloseableHttpClient createSSLClientDefault() {
        try {
            SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(
                    null, new TrustStrategy() {
                        // 信任所有
                        public boolean isTrusted(X509Certificate[] chain,
                                                 String authType) throws CertificateException {
                            return true;
                        }

                        @Override
                        public boolean isTrusted(
                                java.security.cert.X509Certificate[] arg0,
                                String arg1)
                                throws java.security.cert.CertificateException {
                            // TODO Auto-generated method stub
                            return false;
                        }
                    }).build();
            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                    sslContext);
            return HttpClients.custom().setSSLSocketFactory(sslsf).build();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        }
        return HttpClients.createDefault();
    }
}