当前位置: 首页 > news >正文

做的公司网站风格跟样式和别人一样建站模板网站

做的公司网站风格跟样式和别人一样,建站模板网站,番禺企业网站建设,c网站制作其他写法 https://blog.csdn.net/weixin_44372802/article/details/132620809?spm1001.2014.3001.5501 encodeJson 是请求参数的密文格式(大公司都是要对请求参数加密的) ResponseBean 是自己或者对方定义的返回内容参数 public ResponseBean sendByEnc…

其他写法
https://blog.csdn.net/weixin_44372802/article/details/132620809?spm=1001.2014.3001.5501

encodeJson 是请求参数的密文格式(大公司都是要对请求参数加密的)

ResponseBean 是自己或者对方定义的返回内容参数

public ResponseBean sendByEncodeJson(String encodeJson, String interfaceName) throws IOException {//构建完整urlMap<String, String>  urlMap = buildUrl(interfaceName);String url = JpHttpUtils.initUrl(sfUrl, urlMap);log.info("请求地址" + url+"请求报文" + encodeJson);String responseString = JpHttpUtils.post(url, encodeJson);log.info("远程接口响应:" + responseString);//JSON 字符串转换为 SfResponseBean 对象return new Gson().fromJson(responseString, SfResponseBean.class);}
public Map<String, String> buildUrl(String method) throws IOException {Map<String, String> map = new HashMap<>();map.put("appId",appId);map.put("source",source);map.put("appToken",appToken);map.put("userToken",userToken);map.put("method",method);map.put("timestamp",String.valueOf(System.currentTimeMillis()));map.put("v","1.0");return map;}
@Slf4j
public class JpHttpUtils {private static final Logger logger = LoggerFactory.getLogger(JpHttpUtils.class);private static final int SOCKET_TIMEOUT = 30000;// 请求超时时间private static final int CONNECT_TIMEOUT = 30000;// 传输超时时间/*** 发送xml请求到server端** @param url       xml请求数据地址* @param xmlString 发送的xml数据流* @return null发送失败,否则返回响应内容*/public static String sendPost(String url, String xmlString) {StringBuilder retStr = new StringBuilder();// 创建HttpClientBuilderHttpClientBuilder httpClientBuilder = HttpClientBuilder.create();// HttpClientCloseableHttpClient closeableHttpClient = httpClientBuilder.build();HttpPost httpPost = new HttpPost(url);//  设置请求和传输超时时间RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(SOCKET_TIMEOUT).setConnectTimeout(CONNECT_TIMEOUT).build();httpPost.setConfig(requestConfig);try {httpPost.setHeader("Content-Type", "text/xml;charset=UTF-8");StringEntity data = new StringEntity(xmlString, StandardCharsets.UTF_8);httpPost.setEntity(data);CloseableHttpResponse response = closeableHttpClient.execute(httpPost);HttpEntity entity = response.getEntity();if (entity != null) {// 打印响应内容retStr.append(EntityUtils.toString(entity, "UTF-8"));logger.info("response:{}", retStr);}} catch (Exception e) {logger.error("exception in doPostSoap1_1", e);} finally {// 释放资源try {closeableHttpClient.close();} catch (IOException e) {e.printStackTrace();}}return retStr.toString();}public static String sendPostByForm(String url, Map<String,String> formMap) {List<NameValuePair> params=new ArrayList<NameValuePair>();for(Map.Entry<String, String> entry : formMap.entrySet()){params.add(new BasicNameValuePair(entry.getKey(),entry.getValue()));}HttpPost httppost = new HttpPost(url);httppost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");HttpResponse response = null;try {httppost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));HttpClient httpClient =HttpClientBuilder.create().build();response = httpClient.execute(httppost);} catch (IOException e) {e.printStackTrace();}HttpEntity httpEntity = response.getEntity();String result = null;try {result = EntityUtils.toString(httpEntity);} catch (Exception e) {e.printStackTrace();}System.out.println("sendPostByForm response:"+result);return result;}public static String sendPut(String url, String string, Map<String,String> headerMap) {StringBuilder retStr = new StringBuilder();// 创建HttpClientBuilderHttpClientBuilder httpClientBuilder = HttpClientBuilder.create();// HttpClientCloseableHttpClient closeableHttpClient = httpClientBuilder.build();HttpPost httpPost = new HttpPost(url);//  设置请求和传输超时时间RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(SOCKET_TIMEOUT).setConnectTimeout(CONNECT_TIMEOUT).build();httpPost.setConfig(requestConfig);try {httpPost.setHeader("Content-Type", "application/json");if(string!=null){StringEntity data = new StringEntity(string, StandardCharsets.UTF_8);httpPost.setEntity(data);}if (headerMap != null) {for (String key : headerMap.keySet()) {httpPost.setHeader(new BasicHeader(key, headerMap.get(key)));}}CloseableHttpResponse response = closeableHttpClient.execute(httpPost);HttpEntity entity = response.getEntity();if (entity != null) {// 打印响应内容retStr.append(EntityUtils.toString(entity, "UTF-8"));logger.info("response:{}", retStr);}} catch (Exception e) {logger.error("exception in doPostSoap1_1", e);} finally {// 释放资源try {closeableHttpClient.close();} catch (IOException e) {e.printStackTrace();}}return retStr.toString();}public static String doGet(String url, Map<String, String> param) {// 创建Httpclient对象CloseableHttpClient httpclient = HttpClients.createDefault();String resultString = "";CloseableHttpResponse response = null;try {// 创建uriURIBuilder builder = new URIBuilder(url);if (param != null) {for (String key : param.keySet()) {builder.addParameter(key, param.get(key));}}URI uri = builder.build();// 创建http GET请求HttpGet httpGet = new HttpGet(uri);// 执行请求response = httpclient.execute(httpGet);// 判断返回状态是否为200if (response.getStatusLine().getStatusCode() == 200) {resultString = EntityUtils.toString(response.getEntity(), "UTF-8");}} catch (Exception e) {e.printStackTrace();} finally {try {if (response != null) {response.close();}httpclient.close();} catch (IOException e) {e.printStackTrace();}}return resultString;}public static String doGet(String url) {return doGet(url, null);}/*** 带header参数* @param url* @param param* @return*/public static String doGetSetHeader(String url, Map<String, String> param,Map<String, String> headerMap) {// 创建Httpclient对象CloseableHttpClient httpclient = HttpClients.createDefault();String resultString = "";CloseableHttpResponse response = null;try {// 创建uriURIBuilder builder = new URIBuilder(url);// 设置请求的参数if (param != null) {for (String key : param.keySet()) {builder.addParameter(key, param.get(key));}}URI uri = builder.build();// 创建http GET请求HttpGet httpGet = new HttpGet(uri);// 设置 Headerif (headerMap != null) {for (String key : headerMap.keySet()) {httpGet.setHeader(key, headerMap.get(key));}}// 执行请求response = httpclient.execute(httpGet);// 判断返回状态是否为200if (response.getStatusLine().getStatusCode() == 200) {resultString = EntityUtils.toString(response.getEntity(), "UTF-8");}} catch (Exception e) {e.printStackTrace();} finally {try {if (response != null) {response.close();}httpclient.close();} catch (IOException e) {e.printStackTrace();}}return resultString;}public static String doPost(String url, Map<String, String> param) {// 创建Httpclient对象CloseableHttpClient httpClient = HttpClients.createDefault();CloseableHttpResponse response = null;String resultString = "";try {// 创建Http Post请求HttpPost httpPost = new HttpPost(url);// 创建参数列表if (param != null) {List<NameValuePair> paramList = new ArrayList<>();for (String key : param.keySet()) {paramList.add(new BasicNameValuePair(key, param.get(key)));}// 模拟表单UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);httpPost.setEntity(entity);}// 执行http请求response = httpClient.execute(httpPost);resultString = EntityUtils.toString(response.getEntity(), "utf-8");} catch (Exception e) {e.printStackTrace();} finally {try {if(null != response){response.close();}} catch (IOException e) {e.printStackTrace();}}return resultString;}public static String doPost(String url) {return doPost(url, null);}public static String doPostJson(String url, String json) {// 创建Httpclient对象CloseableHttpClient httpClient = HttpClients.createDefault();CloseableHttpResponse response = null;String resultString = "";try {// 创建Http Post请求HttpPost httpPost = new HttpPost(url);// 创建请求内容StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);httpPost.setEntity(entity);// 执行http请求response = httpClient.execute(httpPost);resultString = EntityUtils.toString(response.getEntity(), "utf-8");} catch (Exception e) {e.printStackTrace();} finally {try {if(null != response){response.close();}} catch (IOException e) {e.printStackTrace();}}return resultString;}public static String doPostJson(String url, String json,Map<String,String> headers)  {// 创建Httpclient对象CloseableHttpClient httpClient = HttpClients.createDefault();CloseableHttpResponse response = null;String resultString = "";try {// 创建Http Post请求HttpPost httpPost = new HttpPost(url);for(String  key:headers.keySet()){httpPost.setHeader(key,headers.get(key));}// 创建请求内容StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);httpPost.setEntity(entity);// 执行http请求response = httpClient.execute(httpPost);resultString = EntityUtils.toString(response.getEntity(), "utf-8");} catch (Exception e) {log.error("Exception",e);} finally {try {if(null != response){response.close();}} catch (IOException e) {e.printStackTrace();}}return resultString;}/*** 创建一个SSL信任所有证书的httpClient对象** @return*/public static CloseableHttpClient createSSLClientDefault() {try {SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {// 信任所有@Overridepublic boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {return true;}}).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();}//连接符public static final String SPE3_CONNECT = "&";//赋值符public static final String SPE4_EQUAL = "=";//问号符public static final String SPE5_QUESTION = "?";public static final String SPE1_COMMA = ",";//示意符public static final String SPE2_COLON = ":";public static final String ENCODING = "UTF-8";public static String initUrl(String host, Map<String, String> queries) throws UnsupportedEncodingException {StringBuilder sbUrl = new StringBuilder();sbUrl.append(host);if (null != queries) {StringBuilder sbQuery = new StringBuilder();for (Map.Entry<String, String> query : queries.entrySet()) {if (0 < sbQuery.length()) {sbQuery.append(SPE3_CONNECT);}if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(String.valueOf(query.getValue()))) {sbQuery.append(query.getValue());}if (!StringUtils.isBlank(query.getKey())) {sbQuery.append(query.getKey());if (!StringUtils.isBlank(String.valueOf(query.getValue()))) {sbQuery.append(SPE4_EQUAL);sbQuery.append(URLEncoder.encode(String.valueOf(query.getValue()), ENCODING));}}}if (0 < sbQuery.length()) {sbUrl.append(SPE5_QUESTION).append(sbQuery);}}return sbUrl.toString();}public static final int TIMEOUT = 30000;/*** HTTP -> POST** @param url* @param param* @return* @throws Exception*/public static String post(String url, String param) {String result = null;CloseableHttpClient httpclient = null;CloseableHttpResponse response = null;try {httpclient = HttpClients.createDefault();HttpPost postmethod = new HttpPost(url);RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(TIMEOUT).setConnectTimeout(TIMEOUT).setSocketTimeout(TIMEOUT).build();postmethod.setConfig(requestConfig);postmethod.addHeader("content-type", "application/json");postmethod.setEntity(new StringEntity(param, "UTF-8"));response = httpclient.execute(postmethod);int statusCode = response.getStatusLine().getStatusCode();if (statusCode == HttpStatus.SC_OK) {HttpEntity entity = response.getEntity();if (entity != null) {result = EntityUtils.toString(entity);}}} catch (Exception e) {log.error("post请求异常", e);} finally {try {httpclient.close();} catch (IOException e) {log.error("IOException post请求异常", e);}}return result;}
}
package com.bbyb.transportmonitor.utils.sf;import lombok.Data;import java.io.Serializable;/***  请求实体* @date 2024/5/31 10:02*/
@Data
public class SfResponseBean implements Serializable {/*** 接口状态 200 成功 其它异常*/private String code;private String message;private boolean success;private Model model;private String data;@Dataclass Model  implements Serializable {private String erpOrder;private String code;private String sfOrderNo;}
}
http://www.shuangfujiaoyu.com/news/21555.html

相关文章:

  • 用什么程序做资讯类网站网络营销岗位有哪些
  • 360安全网址百度seo哪家公司好
  • 穷人创业一千元以下的简述网站内容如何优化
  • 网站开发的销售小红书推广引流软件
  • 做非洲出口的网站小程序推广平台
  • 网站建设高端网站软件外包公司排行榜
  • 用axuer 做网站产品原型seo网站制作优化
  • 个人网站制作手绘百度贴吧入口
  • 聊城网站建设费用网站开发流程图
  • 中间商可以做网站吗网站的宣传与推广
  • 营销型网站一站式服务seo策略什么意思
  • 建设食品商购网站nba季后赛最新排名
  • 纪检监察网站建设情况汇报对seo的理解
  • 医保局网站建设中标公告免费网站软件
  • 个性化网站制作怎样创建网站平台
  • wordpress http错误.市场seo是什么意思
  • 哪个网站可以做面料订单有哪些免费网站可以发布广告
  • 麻城网站开发舆情视频
  • sketch可以做网站交互么乐天seo培训中心
  • 嘉兴做网站优化价格网站域名查询
  • 如何做cpa单页网站新闻博客软文自助推广
  • 南京做网站优化哪家好企业内训机构
  • 沈阳三好街做网站公司网站快速收录软件
  • 大连零基础网站建设教学在哪里竞价托管选择微竞价
  • 源码出售网站怎么做刚刚地震最新消息今天
  • 内蒙古网站制作公司惠州seo网站推广
  • windows和linux做网站百度关键词排名十大排名
  • 有源码如何搭建网站百度官方app免费下载
  • 网站开发问题百度知道首页官网
  • 网站建设商务如何做市场推广方案