httpClient忽略https的证书认证

news2024/12/28 2:28:37

忽略https证书认证代码:

 /**
     * 创建模拟客户端(针对 https 客户端禁用 SSL 验证)
     * @return
     * @throws Exception
     */
    public static CloseableHttpClient createHttpClientWithNoSsl() throws Exception {
        // Create a trust manager that does not validate certificate chains
        TrustManager[] trustAllCerts = new TrustManager[]{
                new X509TrustManager() {
                    @Override
                    public X509Certificate[] getAcceptedIssuers() {
                        return null;
                    }

                    @Override
                    public void checkClientTrusted(X509Certificate[] certs, String authType) {
                        // don't check
                    }

                    @Override
                    public void checkServerTrusted(X509Certificate[] certs, String authType) {
                        // don't check
                    }
                }
        };

        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(null, trustAllCerts, null);
        LayeredConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(ctx);
        return HttpClients.custom()
                .setSSLSocketFactory(sslSocketFactory)
                .build();
    }

一、Get请求

接口地址及参数:https://xxx.xxx.com/api/v3/technicians?input_data={“list_info”:{“search_fields”:{“email_id”:“wjjia@iflytek.com”}}}

postman调用示例:

在这里插入图片描述

java代码实现:

OAPropUtil.technician_info_url = https://xxx.xxx.com/api/v3/technicians

String url = OAPropUtil.technician_info_url+"?input_data="+ URLEncoder.encode(JSON.toJSONString(listInfo),"UTF-8");

headerMap.put("authtoken", "12345");
            headerMap.put("Content-type", "application/json;charset=UTF-8");
            String resultStr = OAUtil.getWithHeaderIgnoreSSL(url,headerMap);
  
  public static String getWithHeaderIgnoreSSL(String url,Map<String, String> headerMap) throws Exception {
        CloseableHttpClient httpclient = createHttpClientWithNoSsl();
        HttpGet get = new HttpGet(url);
        // 设置请求头信息
        if (headerMap != null && headerMap.size() > 0) {
            for (String key : headerMap.keySet()) {
                get.addHeader(key, headerMap.get(key));
            }
        }
        RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(1000)
                .setSocketTimeout(20000).setConnectTimeout(3000).build();
        get.setConfig(requestConfig);
        HttpResponse response = httpclient.execute(get);
        try {
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == HttpStatus.SC_OK) {
                //4.解析响应,获取数据
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    return EntityUtils.toString(entity,"UTF-8");
                } else {
                    System.out.println("statusCode[" + statusCode + "],url[" + url + "]");
                }
            }
        } catch (HttpException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } catch (IOException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        }
        return null;
    }          

post示例一:
在这里插入图片描述

Map<String, String> param = new HashMap<>();
                            param.put("input_data", JSON.toJSONString(request));
                            Map<String,String> itsmHeader = new HashMap<>();
                            itsmHeader.put("authtoken", "12345");
                            itsmHeader.put("Content-type", "application/x-www-form-urlencoded;charset=utf-8");
                            
 String ticketStr = OAUtil.postWithHeaderIgnoreSSL(url, param, itsmHeader);

 public static String postWithHeaderIgnoreSSL(String url, Map<String,String> param, Map<String, String> headerMap) throws Exception {
        CloseableHttpClient httpclient = createHttpClientWithNoSsl();
        HttpPost post = new HttpPost(url);
        // 设置请求头信息
        if (headerMap != null && headerMap.size() > 0) {
            for (String key : headerMap.keySet()) {
                post.addHeader(key, headerMap.get(key));
            }
        }
        List<org.apache.http.NameValuePair> nameValuePairList = new ArrayList<>();
        if (param != null) {
            for (String key : param.keySet()) {
                nameValuePairList.add(new BasicNameValuePair(key, param.get(key)));
            }
        }
        try {
            RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(1000)
                    .setSocketTimeout(20000).setConnectTimeout(3000).build();
            post.setConfig(requestConfig);

            HttpEntity entity = new UrlEncodedFormEntity(nameValuePairList, "UTF-8");
            //设置请求参数
            post.setEntity(entity);
            HttpResponse response = httpclient.execute(post);
            int statusCode = response.getStatusLine().getStatusCode();
            String res = EntityUtils.toString(response.getEntity(),"UTF-8");
            if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED){
                //返回json格式
                post.releaseConnection();
                return res;
            } else {
                System.out.println("response《" + res + "》,url[" + url + "],json[" + param + "]");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (post != null)
                post.releaseConnection();
            if (httpclient != null){
                try {
                    httpclient.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }

HttpClient工具类范例

/*
 *
 * Copyright (C) 1999-2012 IFLYTEK Inc.All Rights Reserved.
 *
 * FileName:OAUtil.java
 *
 * Description:
 *
 * History:
 * Version   Author      Date            Operation
 * 1.0	  jfzhao   2014年11月4日上午10:41:12	       Create
 */
package com.iflytek.oa.util;

import com.alibaba.fastjson.JSON;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
import org.apache.http.conn.ssl.*;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import weaver.system.code.CodeBuild;
import weaver.workflow.request.RequestManager;

import javax.net.ssl.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.cert.X509Certificate;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * @author jfzhao
 * @version 1.0
 */
public class OAUtil {
    /**
     * @param s oa内存储的EASID
     * @return easID
     * @description 由于OA不允许人员直接挂靠在公司下,
     * 所以原EAS中直接挂靠公司的人员归属的部门EASID为EAS公司ID加other字样构成
     * @author jfzhao
     * @create 2014年11月4日上午10:45:23
     * @version 1.0
     */
    public static String subEASID(String s) {
        if (s.endsWith("other")) {
            return s.substring(0, s.length() - "other".length());
        } else {
            return s;
        }
    }

    /**
     * @param requestManager 请求对象
     * @description 创建单据编码
     * @author jfzhao
     * @create 2014年12月4日下午4:16:54
     * @version 1.0
     */
    public static void createNumber(RequestManager requestManager) {
        int formID = requestManager.getFormid();
        int isBill = requestManager.getIsbill();
        int workFlowID = requestManager.getWorkflowid();
        int creater = requestManager.getCreater();
        int requestID = requestManager.getRequestid();
        int createrType = requestManager.getCreatertype();
        CodeBuild cbuild = new CodeBuild(formID, String.valueOf(isBill),
                workFlowID, creater, createrType);
        cbuild.getFlowCodeStr(requestID, isBill, formID, workFlowID, creater,
                createrType);
    }

    /**
     * @param url        地址
     * @param valuePairs 参数
     * @return 返回的信息
     * @throws Exception 异常信息
     * @description post方法
     * @author zhsong
     * @create 2015年11月2日下午4:21:43
     * @version 1.0
     */
    public static String post(String url, NameValuePair[] valuePairs) throws Exception {
        HttpClient httpclient = new HttpClient(new HttpClientParams(), new SimpleHttpConnectionManager(true));
        PostMethod postMethod = new UTF8PostMethod(url);
        postMethod.setRequestBody(valuePairs);
        HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
        // 设置连接超时时间(单位毫秒) 
        managerParams.setConnectionTimeout(3000);
        managerParams.setSoTimeout(35000);
        try {
            int statusCode = httpclient.executeMethod(postMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return postMethod.getResponseBodyAsString();
            }
        } catch (HttpException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } catch (IOException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } finally {
            //20181119 添加释放连接
            postMethod.releaseConnection();
        }
        return null;
    }

    public static String authorizationPost(String token, String url, NameValuePair[] valuePairs) throws Exception {
        HttpClient httpclient = new HttpClient(new HttpClientParams(), new SimpleHttpConnectionManager(true));
        PostMethod postMethod = new UTF8PostMethod(url);
        postMethod.setRequestBody(valuePairs);
        postMethod.setRequestHeader("token", token);
        HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
        // 设置连接超时时间(单位毫秒)
        managerParams.setConnectionTimeout(3000);
        managerParams.setSoTimeout(35000);
        try {
            int statusCode = httpclient.executeMethod(postMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return postMethod.getResponseBodyAsString();
            }
        } catch (HttpException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } catch (IOException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } finally {
            //20181119 添加释放连接
            postMethod.releaseConnection();
        }
        return null;
    }

    public static class UTF8PostMethod extends PostMethod {
        public UTF8PostMethod(String url) {
            super(url);
        }

        @Override
        public String getRequestCharSet() {
            return "UTF-8";
        }
    }

    /**
     * @param url
     * @param valuePairs
     * @return
     * @throws Exception
     * @desc get方式
     * @author chaozhou6
     * @date 2018年3月27日 下午10:31:10
     */
    public static String get(String url, NameValuePair[] valuePairs) throws Exception {

        String params = nameValuePairToString(valuePairs);
        HttpClient httpclient = new HttpClient();
        GetMethod getMethod = new UTF8GetMethod(url + "?" + params);
        HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
        // 设置连接超时时间(单位毫秒) 
        managerParams.setConnectionTimeout(3000);
        // 设置返回超时时间(单位毫秒)
        managerParams.setSoTimeout(35000);
        try {
            int statusCode = httpclient.executeMethod(getMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return getMethod.getResponseBodyAsString();
            }
        } catch (HttpException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } catch (IOException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        }
        return null;
    }

    public static String get(String url) throws Exception {
        HttpClient httpclient = new HttpClient();
        GetMethod getMethod = new UTF8GetMethod(url);
        getMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
        HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
        // 设置连接超时时间(单位毫秒)
        managerParams.setConnectionTimeout(3000);
        // 设置返回超时时间(单位毫秒)
        managerParams.setSoTimeout(20000);
        try {
            int statusCode = httpclient.executeMethod(getMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return getMethod.getResponseBodyAsString();
            }
        } catch (HttpException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } catch (IOException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        }
        return null;
    }

    /**
     * @param valuePairs
     * @return
     * @desc NameValuePair转为get方式参数
     * @author chaozhou6
     * @date 2018年3月27日 下午11:09:45
     */
    private static String nameValuePairToString(NameValuePair[] valuePairs) {
        String params = "";
        if (valuePairs != null && valuePairs.length > 0) {
            for (NameValuePair nameValuePair : valuePairs) {
                params += nameValuePair.getName() + "=" + nameValuePair.getValue() + "&";
            }
            params = params.substring(0, params.length() - 1);
        }
        return params;
    }

    public static class UTF8GetMethod extends GetMethod {
        public UTF8GetMethod(String url) {
            super(url);
        }

        @Override
        public String getRequestCharSet() {
            return "UTF-8";
        }
    }

    /**
     * @param logtype
     * @return
     * @description oa nodetype对应汉字说明
     * @author zhsong
     * @create 2016年3月23日上午9:38:53
     * @version 1.0
     */
    public static String getHandle(String logtype) {
        if (null != logtype && !"".equals(logtype)) {
            String ret = "";
            char[] ch = logtype.toCharArray();
            if (ch != null && ch.length == 1) {
                char t = logtype.toCharArray()[0];
                switch (t) {
                    case '0':
                        ret = "批准";
                        break;
                    case '1':
                        ret = "保存";
                        break;
                    case '2':
                        ret = "提交";
                        break;
                    case '3':
                        ret = "退回";
                        break;
                    case '4':
                        ret = "重新打开";
                        break;
                    case '5':
                        ret = "删除";
                        break;
                    case '6':
                        ret = "激活";
                        break;
                    case '7':
                        ret = "转发";
                        break;
                    case '9':
                        ret = "批注";
                        break;
                    case 'e':
                        ret = "强制归档";
                        break;
                    case 't':
                        ret = "抄送";
                        break;
                    case 's':
                        ret = "督办";
                        break;
                    default:
                        ret = "";
                        break;
                }
            }
            return ret;
        }
        return null;
    }

    /**
     * @param htmlStr
     * @return
     * @description 过滤
     * @author lqxiong
     * @create 2016年11月23日上午9:42:36
     * @version 1.0
     */
    public static String delHTMLTag(String htmlStr) {
        if (null == htmlStr) {
            return "";
        }
        String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // 定义script的正则表达式
        String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式
        String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
        String regEx_space = "\\s*|\t|\r|\n";// 定义空格回车换行符

        Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
        Matcher m_script = p_script.matcher(htmlStr);
        htmlStr = m_script.replaceAll(""); // 过滤script标签

        Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
        Matcher m_style = p_style.matcher(htmlStr);
        htmlStr = m_style.replaceAll(""); // 过滤style标签

        Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
        Matcher m_html = p_html.matcher(htmlStr);
        htmlStr = m_html.replaceAll(""); // 过滤html标签

        Pattern p_space = Pattern.compile(regEx_space, Pattern.CASE_INSENSITIVE);
        Matcher m_space = p_space.matcher(htmlStr);
        htmlStr = m_space.replaceAll(""); // 过滤空格回车换行符

        htmlStr = htmlStr.replaceAll("&nbsp;", " ");

        // 返回文本字符串
        return htmlStr.trim();
    }

    /**
     * desc OA远程调用接口方法
     * author mhhuang2
     *
     * @param url            接口地址
     * @param nameValuePairs 接口参数
     * @return
     * @throws
     * @date 2017年6月5日 下午3:36:50
     */
    public static String remoteInvoke(String url, NameValuePair[] nameValuePairs) {
        String result = null;
        try {
            result = post(url, nameValuePairs);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (null != result) {
            result = result.trim();
        }
        return result;
    }

    /**
     * @param authenticationCode (new sun.misc.BASE64Encoder()).encode("用户名:密码".getBytes())
     * @param url                访问地址
     * @param jsonContent        json串
     * @return
     * @description 基于HttpClient的Basic认证方案的Patch请求方式
     * @author ckyang
     * @create 2017年6月21日上午10:46:08
     * @version 1.0
     */
    public static Map<String, String> BasicAuthorizationPatch(String authenticationCode, String url, String jsonContent) {
        Map<String, String> map = new HashMap<String, String>();
        String responseResult = "";
        String exceptionMessage = "";
        int statusCode = 404;

        HttpClient httpClient = new HttpClient();
        PostMethod method = new UTF8PostMethod(url);

//		RequestEntity requestEntity = new StringRequestEntity(text); //中文乱码

        RequestEntity requestEntity = null;

        try {
            requestEntity = new StringRequestEntity(jsonContent, "application/vnd.oracle.adf.resourceitem+json", "UTF-8");
//			requestEntity = new StringRequestEntity(jsonContent, "application/vnd.oracle.adf.resourceitem+json", "iso-8859-1");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        method.setRequestEntity(requestEntity);

        method.setRequestHeader("x-http-method-override", "PATCH"); //patch方式访问需要加这个设置,post访问方式不加这个设置
        //application/vnd.oracle.adf.action+json
        //application/vnd.oracle.adf.resourceitem+json
//		method.setRequestHeader("Content-Type","application/vnd.oracle.adf.action+json");
        method.setRequestHeader("Content-Type", "application/vnd.oracle.adf.resourceitem+json");
        //用户名密码:YANGHONGBO:Hand1234
//		method.setRequestHeader("Authorization", " Basic " + (new sun.misc.BASE64Encoder()).encode("YANGHONGBO:Hand1234".getBytes()));
        method.setRequestHeader("Authorization", " Basic " + authenticationCode);

        try {
            statusCode = httpClient.executeMethod(method);
            //responseResult = method.getResponseBodyAsString(); //中文乱码

            String charset = "UTF-8";
            InputStream ins = method.getResponseBodyAsStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(ins, charset)); //按指定的字符集构建文件流
            StringBuffer sbf = new StringBuffer();
            String line = "";
            while ((line = br.readLine()) != null) {
                sbf.append(line);
            }
            br.close();

            responseResult = sbf.toString().trim();
        } catch (Exception e) {
            exceptionMessage = e.getMessage();
            e.printStackTrace();
        }

        map.put("responseResult", responseResult);
        map.put("exceptionMessage", exceptionMessage);
        map.put("statusCode", statusCode + "");
        map.put("statusText", HttpStatus.getStatusText(statusCode));

        return map;
    }

    /**
     * @param authStr  OA调用CRM接口认证用户名/参数
     * @param destUrl  访问地址
     * @param postData soap串
     * @return
     * @description 通过soap方式传输数据
     * @author lqxiong
     * @create 2017年8月9日16:46:33
     * @version 1.0
     */
    public static Map<String, String> httpPost(String destUrl, String postData, String authStr) throws Exception {
        Map<String, String> response = new HashMap<String, String>();
        int responseCode = 404;
        String responseMessage = "网络异常";

        URL url = new URL(destUrl);
        HttpURLConnection.setFollowRedirects(true);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        if (null != conn) {
            conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setUseCaches(false);
//        	conn.setFollowRedirects(true);
            conn.setAllowUserInteraction(false);
            conn.setRequestMethod("POST");

            //byte[] authBytes = authStr.getBytes("UTF-8");
            //String auth = com.sun.org.apache.xml.internal.security.utils.Base64.encode(authBytes);
            //conn.setRequestProperty("Authorization", "Basic " + auth);

            if (StringUtils.isNotBlank(authStr)) {
                conn.setRequestProperty("Authorization", "Basic " + authStr);
            }

            OutputStream out = conn.getOutputStream();
            OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
            writer.write(postData);
            writer.close();
            out.close();

            responseCode = conn.getResponseCode();
//        	System.out.println("connection status: " + conn.getResponseCode());
//        	System.out.println("connection response: " + conn.getResponseMessage());

            InputStream in = conn.getInputStream();
            InputStreamReader iReader = new InputStreamReader(in, "UTF-8");
            BufferedReader bReader = new BufferedReader(iReader);

            String line;
            responseMessage = "";
            while ((line = bReader.readLine()) != null) {
                responseMessage += line;
            }
            iReader.close();
            bReader.close();
            in.close();
            conn.disconnect();
        }

        response.put("responseCode", String.valueOf(responseCode));
        response.put("responseMessage", responseMessage);

        return response;
    }

    /**
     * @param url
     * @param json
     * @return
     * @desc post方式
     * @author chaozhou6
     * @date 2017年11月13日 上午10:34:22
     */
    public static String post(String url, String json) {
        HttpClient httpclient = new HttpClient();
        PostMethod postMethod = new UTF8PostMethod(url);
        postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
        try {
            HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
            // 设置连接超时时间(单位毫秒)
            managerParams.setConnectionTimeout(3000);
            managerParams.setSoTimeout(90000);
            RequestEntity requestEntity = new StringRequestEntity(json, "application/json", "UTF-8");
            postMethod.setRequestEntity(requestEntity);
            int statusCode = httpclient.executeMethod(postMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return postMethod.getResponseBodyAsString();
            } else {
                System.out.println("statusCode[" + statusCode + "],url[" + url + "],json[" + json + "]");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            postMethod.releaseConnection();
        }
        return null;
    }

    /**
     * 同步PS请求
     *
     * @param url
     * @param json
     * @return
     * @author junliang3
     * @date 2022/2/17 10:23
     */
    public static String postForPS(String url, String json) {
        HttpClient httpclient = new HttpClient();
        PostMethod postMethod = new UTF8PostMethod(url);
        postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
        try {
            HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
            // 设置连接超时时间(单位毫秒)
            managerParams.setConnectionTimeout(3000);
            managerParams.setSoTimeout(90000);
            RequestEntity requestEntity = new StringRequestEntity(json, "text/json", "UTF-8");
            postMethod.setRequestEntity(requestEntity);
            int statusCode = httpclient.executeMethod(postMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return postMethod.getResponseBodyAsString();
            } else {
                System.out.println("statusCode[" + statusCode + "],url[" + url + "],json[" + json + "]");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            postMethod.releaseConnection();
        }
        return null;
    }

    /**
     * @param token
     * @param url
     * @param json
     * @return
     * @description 向大E传递数据
     */
    public static String authorizationHttpPost(String token, String url, String json) {
        HttpClient httpClient = new HttpClient();
        PostMethod method = new UTF8PostMethod(url);
        try {
            HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager().getParams();
            // 设置连接超时时间(单位毫秒)
            managerParams.setConnectionTimeout(3000);
            managerParams.setSoTimeout(20000);

            RequestEntity requestEntity = new StringRequestEntity(json, "application/json", "UTF-8");
            method.setRequestEntity(requestEntity);
            method.setRequestHeader("Authorization", "Bearer  " + token);
            int statusCode = httpClient.executeMethod(method);
            if (statusCode == HttpStatus.SC_OK) {
                return method.getResponseBodyAsString();
            } else {
                System.out.println("statusCode[" + statusCode + "],url[" + url + "],json[" + json + "]");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            method.releaseConnection();
        }
        return null;
    }

    public static String httpPostHead(String token, String url, String json) {
        HttpClient httpClient = new HttpClient();
        PostMethod method = new UTF8PostMethod(url);
        try {
            HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager().getParams();
            // 设置连接超时时间(单位毫秒)
            managerParams.setConnectionTimeout(3000);
            managerParams.setSoTimeout(20000);

            RequestEntity requestEntity = new StringRequestEntity(json, "application/json", "UTF-8");
            method.setRequestEntity(requestEntity);
            method.setRequestHeader("Authorization", token);
            int statusCode = httpClient.executeMethod(method);
            if (statusCode == HttpStatus.SC_OK) {
                return method.getResponseBodyAsString();
            } else {
                System.out.println("statusCode[" + statusCode + "],url[" + url + "],json[" + json + "]");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            method.releaseConnection();
        }
        return null;
    }


    /**
     * @param url
     * @return
     * @description
     * @author lqxiong
     * @create 2018年7月11日下午6:06:36
     * @version 1.0
     */
    public static String post(String url) {
        try {
            HttpClient httpclient = new HttpClient();
            PostMethod postMethod = new UTF8PostMethod(url);

            int statusCode = httpclient.executeMethod(postMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return postMethod.getResponseBodyAsString();
            } else {
                System.out.println("statusCode[" + statusCode + "],url[" + url + "]");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * @param workcode
     * @return
     * @desc 员工工号转换
     * @author chaozhou6
     * @date 2017年11月6日 下午12:22:26
     */
    public static String workcodeConversion(String workcode) {
        String workcodeTemp = "";
        workcodeTemp = workcode.replace("BD", "BEST");
        workcodeTemp = workcodeTemp.replace("JD", "WHJD");
        workcodeTemp = workcodeTemp.replace("BB", "BBXF");
        workcodeTemp = workcodeTemp.replace("BZ", "BZXF");
        workcodeTemp = workcodeTemp.replace("FY", "FYSM");
        workcodeTemp = workcodeTemp.replace("HB", "HBXF");
        workcodeTemp = workcodeTemp.replace("HN", "HNXF");
        workcodeTemp = workcodeTemp.replace("JL", "JLKX");
        workcodeTemp = workcodeTemp.replace("SZ", "SZXF");
        workcodeTemp = workcodeTemp.replace("XY", "XYXF");
        workcodeTemp = workcodeTemp.replace("JC", "XFJC");
        return workcodeTemp;
    }

    /**
     * @return
     * @description 将多个oaid按照域账号顺序排序
     * @author lqxiong
     * @create 2018年3月29日下午3:40:51
     * @version 1.0
     */
    public static String sortoaIds(String loginIds, Map<String, String> oaIdsMap) {
        String oaIds = "";
        if (StringUtils.isNotBlank(loginIds)) {
            String[] loginIdsArray = loginIds.split(",");
            if (null != oaIdsMap && !oaIdsMap.isEmpty()) {
                String temp = "";
                for (int i = 0; i < loginIdsArray.length; i++) {
                    //按照传入的域账号顺序,取出oaid
                    temp = loginIdsArray[i];
                    if (null != oaIdsMap.get(temp) && !oaIdsMap.get(temp).isEmpty()) {
                        oaIds += oaIdsMap.get(temp) + ",";
                    }
                }
                oaIds = oaIds.substring(0, oaIds.length() - 1);
            }
        }
        return oaIds;
    }

    /**
     * @param url
     * @param json
     * @return
     * @desc post方式
     * @author chaozhou6
     * @date 2017年11月13日 上午10:34:22
     */
    public static String postWithResultCharset(String url, String json) {
        HttpClient httpclient = new HttpClient();
        PostMethod postMethod = new UTF8PostMethod(url);
        postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
        try {
            HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
            // 设置连接超时时间(单位毫秒)
            managerParams.setConnectionTimeout(3000);
            managerParams.setSoTimeout(20000);
            RequestEntity requestEntity = new StringRequestEntity(json, "application/json", "UTF-8");
            postMethod.setRequestEntity(requestEntity);
            int statusCode = httpclient.executeMethod(postMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return postMethod.getResponseBodyAsString();
            } else {
                System.out.println("statusCode[" + statusCode + "],url[" + url + "],json[" + json + "]");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            postMethod.releaseConnection();
        }
        return null;
    }

    /**
     * @param url
     * @param valuePairs
     * @return
     * @throws Exception
     * @desc get方式
     * @author chaozhou6
     * @date 2018年3月27日 下午10:31:10
     */
    public static String getWithResultCharset(String url, NameValuePair[] valuePairs) throws Exception {

        String params = nameValuePairToString(valuePairs);
        HttpClient httpclient = new HttpClient();
        GetMethod getMethod = new UTF8GetMethod(url + "?" + params);
        getMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
        HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
        // 设置连接超时时间(单位毫秒)
        managerParams.setConnectionTimeout(3000);
        try {
            int statusCode = httpclient.executeMethod(getMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return getMethod.getResponseBodyAsString();
            }
        } catch (HttpException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } catch (IOException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        }
        return null;
    }

    /**
     * get请求携带请求头
     *
     * @param url        地址
     * @param valuePairs 参数
     * @param headerMap  请求头信息
     * @return String
     * @throws Exception
     * @desc get方式
     * @author lewang4
     * @date 2021-12-03
     */
    public static String getWithHeader(String url, NameValuePair[] valuePairs, Map<String, String> headerMap) throws Exception {

        String params = nameValuePairToString(valuePairs);
        HttpClient httpclient = new HttpClient();
        GetMethod getMethod = new UTF8GetMethod(url + "?" + params);

        // 设置请求头信息
        if (headerMap != null && headerMap.size() > 0) {
            for (String key : headerMap.keySet()) {
                getMethod.setRequestHeader(key, headerMap.get(key));
            }
        }
        HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
        // 设置连接超时时间(单位毫秒)
        managerParams.setConnectionTimeout(3000);
        try {
            int statusCode = httpclient.executeMethod(getMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return getMethod.getResponseBodyAsString();
            }
        } catch (HttpException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } catch (IOException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        }
        return null;
    }

    /**
     * post方法
     *
     * @param url       地址
     * @param json      参数
     * @param headerMap 请求头信息
     * @return 返回的信息
     * @author zhsong
     * @create 2015年11月2日下午4:21:43
     */
    public static String postWithHeader(String url, String json, Map<String, String> headerMap) {
        HttpClient httpclient = new HttpClient();
        PostMethod postMethod = new UTF8PostMethod(url);

        // 设置请求头信息
        if (headerMap != null && headerMap.size() > 0) {
            for (String key : headerMap.keySet()) {
                postMethod.setRequestHeader(key, headerMap.get(key));
            }
        }

        postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");

        try {
            HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
            // 设置连接超时时间(单位毫秒)
            managerParams.setConnectionTimeout(3000);
            managerParams.setSoTimeout(20000);
            RequestEntity requestEntity = new StringRequestEntity(json, "application/json", "UTF-8");
            postMethod.setRequestEntity(requestEntity);
            int statusCode = httpclient.executeMethod(postMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return postMethod.getResponseBodyAsString();
            } else {
                System.out.println("statusCode[" + statusCode + "],url[" + url + "],json[" + json + "]");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            postMethod.releaseConnection();
        }
        return null;
    }

    /**
     * 反写OTC系统
     *
     * @param url  地址
     * @param json 数据
     * @return string
     * @author junliang3
     * @date 2022/5/24 10:39
     */
    public static String postToOTC(String url, String json) {
        HttpClient httpclient = new HttpClient();
        PostMethod postMethod = new UTF8PostMethod(url);
        postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
        try {
            HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
            // 设置连接超时时间(单位毫秒)
            managerParams.setConnectionTimeout(3000);
            managerParams.setSoTimeout(90000);
            RequestEntity requestEntity = new StringRequestEntity(json, "application/json", "UTF-8");
            postMethod.setRequestEntity(requestEntity);
            postMethod.setRequestHeader("sign", OAPropUtil.contract_synOTC_sign);
            int statusCode = httpclient.executeMethod(postMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return postMethod.getResponseBodyAsString();
            } else {
                System.out.println("statusCode[" + statusCode + "],url[" + url + "],json[" + json + "]");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            postMethod.releaseConnection();
        }
        return null;
    }

    /**
     * @param url        地址
     * @param valuePairs 参数
     * @return 返回的信息
     * @throws Exception 异常信息
     * @description post方法
     * @author zhsong
     * @create 2015年11月2日下午4:21:43
     * @version 1.0
     */
    public static String postToFF(String url, NameValuePair[] valuePairs) throws Exception {
        HttpClient httpclient = new HttpClient(new HttpClientParams(), new SimpleHttpConnectionManager(true));
        PostMethod postMethod = new UTF8PostMethod(url);
        postMethod.setRequestBody(valuePairs);
        postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
        HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
        // 设置连接超时时间(单位毫秒)
        managerParams.setConnectionTimeout(3000);
        managerParams.setSoTimeout(35000);
        try {
            int statusCode = httpclient.executeMethod(postMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return postMethod.getResponseBodyAsString();
            }
        } catch (HttpException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } catch (IOException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } finally {
            //20181119 添加释放连接
            postMethod.releaseConnection();
        }
        return null;
    }

    public static String postToXF(String url, NameValuePair[] valuePairs) throws Exception {
        HttpClient httpclient = new HttpClient(new HttpClientParams(), new SimpleHttpConnectionManager(true));
        PostMethod postMethod = new UTF8PostMethod(url);
        postMethod.setRequestBody(valuePairs);
        postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
        HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
        // 设置连接超时时间(单位毫秒)
        managerParams.setConnectionTimeout(3000);
        managerParams.setSoTimeout(35000);
        byte[] b = JSON.toJSONString(valuePairs).getBytes("utf-8");
        InputStream is = new ByteArrayInputStream(b, 0, b.length);
        RequestEntity requestEntity = new InputStreamRequestEntity(is, b.length,
                "text/xml; charset=utf-8");
        postMethod.setRequestEntity(requestEntity);
        try {
            int statusCode = httpclient.executeMethod(postMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return postMethod.getResponseBodyAsString();
            }
        } catch (HttpException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } catch (IOException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } finally {
            //20181119 添加释放连接
            postMethod.releaseConnection();
        }
        return null;
    }

    /**
     * post请求携带请求头
     *
     * @param url        地址
     * @param valuePairs 参数
     * @param headerMap  请求头信息
     * @return String
     * @throws Exception
     * @desc post 方式
     * @author rfzhou3
     * @date 2022-12-19
     */
    public static String postWithHeader(String url, NameValuePair[] valuePairs, Map<String, String> headerMap) throws Exception {
        HttpClient httpclient = new HttpClient(new HttpClientParams(), new SimpleHttpConnectionManager(true));
        PostMethod postMethod = new OAUtil.UTF8PostMethod(url);
        // 设置请求头信息
        if (headerMap != null && headerMap.size() > 0) {
            for (String key : headerMap.keySet()) {
                postMethod.setRequestHeader(key, headerMap.get(key));
            }
        }
        postMethod.setRequestBody(valuePairs);
        HttpConnectionManagerParams managerParams = httpclient.getHttpConnectionManager().getParams();
        // 设置连接超时时间(单位毫秒)
        managerParams.setConnectionTimeout(3000);
        managerParams.setSoTimeout(10000);
        try {
            int statusCode = httpclient.executeMethod(postMethod);
            if (statusCode == HttpStatus.SC_OK) {
                return postMethod.getResponseBodyAsString();
            }
        } catch (IOException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } finally {
            postMethod.releaseConnection();
        }
        return null;
    }

    public static NameValuePair[] convertMap2NameValuePairs(Map<String, String> data) {
        Set<Map.Entry<String, String>> entrySet = data.entrySet();
        int size = entrySet.size();
        NameValuePair[] nameValuePairs = new NameValuePair[size];
        List<NameValuePair> nameValuePairList = new ArrayList<>();
        for (Map.Entry<String, String> entry : entrySet) {
            String key = entry.getKey();
            String value = entry.getValue();
            NameValuePair nameValuePair = new NameValuePair(key, value);
            nameValuePairList.add(nameValuePair);
        }
        for (int i = 0; i < nameValuePairList.size(); i++) {
            nameValuePairs[i] = nameValuePairList.get(i);
        }
        return nameValuePairs;
    }

    public static String getWithHeaderIgnoreSSL(String url,Map<String, String> headerMap) throws Exception {
        CloseableHttpClient httpclient = createHttpClientWithNoSsl();
        HttpGet get = new HttpGet(url);
        // 设置请求头信息
        if (headerMap != null && headerMap.size() > 0) {
            for (String key : headerMap.keySet()) {
                get.addHeader(key, headerMap.get(key));
            }
        }
        RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(1000)
                .setSocketTimeout(20000).setConnectTimeout(3000).build();
        get.setConfig(requestConfig);
        HttpResponse response = httpclient.execute(get);
        try {
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == HttpStatus.SC_OK) {
                //4.解析响应,获取数据
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    return EntityUtils.toString(entity,"UTF-8");
                } else {
                    System.out.println("statusCode[" + statusCode + "],url[" + url + "]");
                }
            }
        } catch (HttpException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        } catch (IOException e) {
            e.printStackTrace();
            throw new Exception("网络异常!");
        }
        return null;
    }

    public static String postWithHeaderIgnoreSSL(String url, String json, Map<String, String> headerMap) throws Exception {
        CloseableHttpClient httpclient = createHttpClientWithNoSsl();
        HttpPost post = new HttpPost(url);
        // 设置请求头信息
        if (headerMap != null && headerMap.size() > 0) {
            for (String key : headerMap.keySet()) {
                post.addHeader(key, headerMap.get(key));
            }
        }
        post.setHeader("Content-type", "application/json;charset=utf-8");
        try {
            RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(1000)
                    .setSocketTimeout(20000).setConnectTimeout(3000).build();
            post.setConfig(requestConfig);
            StringEntity s = new StringEntity(json,"UTF-8");
            s.setContentEncoding("UTF-8");
            //发送json数据需要设置contentType
            s.setContentType("application/json");
            //设置请求参数
            post.setEntity(s);
            HttpResponse response = httpclient.execute(post);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == HttpStatus.SC_OK){
                //返回json格式
                String res = EntityUtils.toString(response.getEntity(),"UTF-8");
                post.releaseConnection();
                return res;
            } else {
                System.out.println("statusCode[" + statusCode + "],url[" + url + "],json[" + json + "]");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (post != null)
                post.releaseConnection();
            if (httpclient != null){
                try {
                    httpclient.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
    public static String postIgnoreSSL(String url, String json, Map<String, String> headerMap) throws Exception {
        HttpClientBuilder builder = HttpClients.custom();
        builder.setSSLHostnameVerifier((hostName, sslSession) -> {
            return true; // 证书校验通过
        });
        CloseableHttpClient httpclient = builder.build();
        HttpPost post = new HttpPost(url);
        // 设置请求头信息
        if (headerMap != null && headerMap.size() > 0) {
            for (String key : headerMap.keySet()) {
                post.addHeader(key, headerMap.get(key));
            }
        }
        post.setHeader("Content-type", "application/json;charset=utf-8");
        try {
            RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(1000)
                    .setSocketTimeout(20000).setConnectTimeout(3000).build();
            StringEntity s = new StringEntity(json,"UTF-8");
            s.setContentEncoding("UTF-8");
            //发送json数据需要设置contentType
            s.setContentType("application/json");
            //设置请求参数
            post.setEntity(s);
            HttpResponse response = httpclient.execute(post);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == HttpStatus.SC_OK){
                //返回json格式
                String res = EntityUtils.toString(response.getEntity(),"UTF-8");
                post.releaseConnection();
                return res;
            } else {
                System.out.println("statusCode[" + statusCode + "],url[" + url + "],json[" + json + "]");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (post != null)
                post.releaseConnection();
            if (httpclient != null){
                try {
                    httpclient.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }

    /**
     * 创建模拟客户端(针对 https 客户端禁用 SSL 验证)
     * @return
     * @throws Exception
     */
    public static CloseableHttpClient createHttpClientWithNoSsl() throws Exception {
        // Create a trust manager that does not validate certificate chains
        TrustManager[] trustAllCerts = new TrustManager[]{
                new X509TrustManager() {
                    @Override
                    public X509Certificate[] getAcceptedIssuers() {
                        return null;
                    }

                    @Override
                    public void checkClientTrusted(X509Certificate[] certs, String authType) {
                        // don't check
                    }

                    @Override
                    public void checkServerTrusted(X509Certificate[] certs, String authType) {
                        // don't check
                    }
                }
        };

        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(null, trustAllCerts, null);
        LayeredConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(ctx);
        return HttpClients.custom()
                .setSSLSocketFactory(sslSocketFactory)
                .build();
    }

    /**
     * 跳过ssl验证 form表单提交
     * @param url /
     * @param param /
     * @param headerMap /
     * @return /
     * @throws Exception /
     */
    public static String postWithHeaderIgnoreSSL(String url, Map<String,String> param, Map<String, String> headerMap) throws Exception {
        CloseableHttpClient httpclient = createHttpClientWithNoSsl();
        HttpPost post = new HttpPost(url);
        // 设置请求头信息
        if (headerMap != null && headerMap.size() > 0) {
            for (String key : headerMap.keySet()) {
                post.addHeader(key, headerMap.get(key));
            }
        }
        List<org.apache.http.NameValuePair> nameValuePairList = new ArrayList<>();
        if (param != null) {
            for (String key : param.keySet()) {
                nameValuePairList.add(new BasicNameValuePair(key, param.get(key)));
            }
        }
        try {
            RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(1000)
                    .setSocketTimeout(20000).setConnectTimeout(3000).build();
            post.setConfig(requestConfig);

            HttpEntity entity = new UrlEncodedFormEntity(nameValuePairList, "UTF-8");
            //设置请求参数
            post.setEntity(entity);
            HttpResponse response = httpclient.execute(post);
            int statusCode = response.getStatusLine().getStatusCode();
            String res = EntityUtils.toString(response.getEntity(),"UTF-8");
            if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED){
                //返回json格式
                post.releaseConnection();
                return res;
            } else {
                System.out.println("response《" + res + "》,url[" + url + "],json[" + param + "]");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (post != null)
                post.releaseConnection();
            if (httpclient != null){
                try {
                    httpclient.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1407377.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【C++】初步认识基于C的优化

C祖师爷在使用C语言时感觉到了不方便的一些点&#xff0c;于是一步一步改进优化&#xff0c;最后形成了C 本文将盘点一下基于C的语法优化 目录 命名空间&#xff1a;命名空间定义&#xff1a;命名空间使用&#xff1a; C输入&输出&#xff1a;cout&#xff1a;endl&#…

司铭宇老师:门店服装销售技巧培训:卖衣服销售方法和技巧

门店服装销售技巧培训&#xff1a;卖衣服销售方法和技巧 在服装零售行业&#xff0c;销售方法和技巧对于提升销售业绩和增强顾客满意度至关重要。一个成功的销售人员需要掌握如何吸引顾客、如何展示商品、如何促成交易等多方面的技能。以下是关于卖衣服的销售方法和技巧的详细…

ai智能写作软件有分享吗?分享4款解放双手的软件!

随着人工智能技术的不断发展&#xff0c;AI智能写作软件逐渐成为内容创作者们的新宠。这些软件不仅能够帮助我们快速生成高质量的文本内容&#xff0c;还能在优化搜索引擎排名等方面发挥重要作用。本文将为大家介绍几款常用的AI智能写作软件&#xff0c;让您轻松提升内容创作效…

如何在飞书创建企业ChatGPT智能问答助手应用并实现公网远程访问(1)

文章目录 前言环境列表1.飞书设置2.克隆feishu-chatgpt项目3.配置config.yaml文件4.运行feishu-chatgpt项目5.安装cpolar内网穿透6.固定公网地址7.机器人权限配置8.创建版本9.创建测试企业10. 机器人测试 前言 在飞书中创建chatGPT机器人并且对话&#xff0c;在下面操作步骤中…

Unity | 渡鸦避难所-8 | URP 中利用 Shader 实现角色受击闪白动画

1. 效果预览 当角色受到攻击时&#xff0c;为了增加游戏的视觉效果和反馈&#xff0c;可以添加粒子等动画&#xff0c;也可以使用 Shader 实现受击闪白动画&#xff1a;受到攻击时变为白色&#xff0c;逐渐恢复为正常颜色 本游戏中设定英雄受击时播放粒子效果&#xff0c;怪物…

pytorch实战-6手写数字加法机-迁移学习

1 概述 迁移学习概念&#xff1a;将已经训练好的识别某些信息的网络拿去经过训练识别另外不同类别的信息 优越性&#xff1a;提高了训练模型利用率&#xff0c;解决了数据缺失的问题&#xff08;对于新的预测场景&#xff0c;不需要大量的数据&#xff0c;只需要少量数据即可…

IP代理可以保护信息安全吗?

“随着互联网的普及和发展&#xff0c;网络安全问题已经成为众多企业和个人所面临的严峻挑战。保护信息安全已成为企业的核心竞争力之一&#xff0c;而IP代理正成为实现这一目标的有效手段。” 一、IP代理真的可以保护用户信息安全吗&#xff1f; IP代理作为一种网络工具&…

CSS基本知识总结

目录 一、CSS语法 二、CSS选择器 三、CSS样式表 1.外部样式表 2.内部样式表 3.内联样式 四、CSS背景 1.背景颜色&#xff1a;background-color 2.背景图片&#xff1a;background-image 3.背景大小&#xff1a;background-size 4.背景图片是否重复&#xff1a;backg…

鸿蒙应用开发学习:获取手机位置信息

一、前言 移动应用中经常需要获取设备的位置信息&#xff0c;因此在鸿蒙应用开发学习中&#xff0c;如何获取手机的位置信息是必修课。之前我想偷懒从别人那里复制黏贴代码&#xff0c;于是在百度上搜了一下&#xff0c;可能是我输入的关键字不对&#xff0c;结果没有找到想要…

离线编译 onnxruntime-with-tensortRT

记录为centos7的4090开发机离线编译onnxruntime的过程&#xff0c;因为在离线的环境&#xff0c;所以踩了很多坑。 https://onnxruntime.ai/docs/execution-providers/TensorRT-ExecutionProvider.html 这里根据官网的推荐安装1.15 版本的onnx 因为离线环境&#xff0c;所以很…

10个常考的前端手写题,你全都会吗?(下)

前言 &#x1f4eb; 大家好&#xff0c;我是南木元元&#xff0c;热爱技术和分享&#xff0c;欢迎大家交流&#xff0c;一起学习进步&#xff01; &#x1f345; 个人主页&#xff1a;南木元元 今天接着上篇再来分享一下10个常见的JavaScript手写功能。 目录 1.实现继承 ES5继…

【制作100个unity游戏之23】实现类似七日杀、森林一样的生存游戏2(附项目源码)

本节最终效果演示 文章目录 本节最终效果演示系列目录前言添加小动物模型动画动物AI脚本效果 添加石头石头模型拾取物品效果 源码完结 系列目录 【制作100个unity游戏之23】实现类似七日杀、森林一样的生存游戏1&#xff08;附项目源码&#xff09; 【制作100个unity游戏之23】…

卓振江:我的大数据能力提升之路 | 提升之路系列(二)

导读 为了发挥清华大学多学科优势&#xff0c;搭建跨学科交叉融合平台&#xff0c;创新跨学科交叉培养模式&#xff0c;培养具有大数据思维和应用创新的“π”型人才&#xff0c;由清华大学研究生院、清华大学大数据研究中心及相关院系共同设计组织的“清华大学大数据能力提升项…

x-cmd pkg | perl - 具有强大的文本处理能力的通用脚本语言

目录 介绍首次用户技术特点竞品进一步阅读 介绍 Perl 是一种动态弱类型编程语言。Perl 内部集成了正则表达式的功能&#xff0c;以及巨大的第三方代码库 CPAN;在处理文本领域,是最有竞争力的一门编程语言之一 生态系统&#xff1a;综合 Perl 档案网络 (CPAN) 提供了超过 25,0…

【江科大】STM32:MPU6050介绍

文章目录 MPU6050介绍结构图MPU6050参数硬件电路模块内部结构框图数据帧格式寄存器地址 MPU6050介绍 MPU6050是一个6轴姿态传感器&#xff0c;可以测量芯片自身X、Y、Z轴的加速度、角速度参数&#xff0c;通过数据融合&#xff0c;可进一步得到姿态角&#xff0c;常应用于平衡…

maven配置阿里镜像源

在用户设置settings.xml文件里找到mirrors配置部分&#xff0c;大概在146行&#xff0c;添加如下配置&#xff1a; <mirror><id>alimaven</id><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/groups/public/</u…

防火墙子接口配置

目录 拓扑需求 配置DMZ区域配置IP 总公司IP配置生产区办公区 总公司配置子接口网关生产区网关办公区网关 配置安全策略&#xff08;trust to DMZ&#xff09; 测试 拓扑 需求 配置总公司区域配置DMZ区域配置总公司区域到DMZ区域互通&#xff08;trust to DMZ&#xff09; 配置…

基于springboot+vue的学科竞赛管理系统(前后端分离)

博主主页&#xff1a;猫头鹰源码 博主简介&#xff1a;Java领域优质创作者、CSDN博客专家、公司架构师、全网粉丝5万、专注Java技术领域和毕业设计项目实战 主要内容&#xff1a;毕业设计(Javaweb项目|小程序等)、简历模板、学习资料、面试题库、技术咨询 文末联系获取 研究背景…

实时渲染 -- 几何(Geometry)

几何表示&#xff08;Geometry Representation&#xff09; 隐式表面&#xff08;Implicit Surface&#xff09; 一个函数定义一个隐式几何 f(x,y,z)0。​ 容易判断一个点是在几何体内部&#xff08;f<0&#xff09;还是外部&#xff08;f>0&#xff09; 显式表面&…

【C++】位图+布隆过滤器

位图布隆过滤器 1.位图2.布隆过滤器 喜欢的点赞&#xff0c;收藏&#xff0c;关注一下把&#xff01; 1.位图 问: 给40亿个不重复的无符号整数&#xff0c;没排过序。给一个无符号整数&#xff0c;如何快速判断一个数是否在这40亿个数中。 可能你会想到下面这几种方式&#…