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

建设银行信用卡网站下载中国纪检监察报价格

建设银行信用卡网站下载,中国纪检监察报价格,小程序网站模板,二手房交易网站排名其他写法 https://blog.csdn.net/weixin_44372802/article/details/132620809?spm1001.2014.3001.5501 encodeJson 是请求参数的密文格式#xff08;大公司都是要对请求参数加密的#xff09; ResponseBean 是自己或者对方定义的返回内容参数 public ResponseBean sendByEnc… 其他写法 https://blog.csdn.net/weixin_44372802/article/details/132620809?spm1001.2014.3001.5501 encodeJson 是请求参数的密文格式大公司都是要对请求参数加密的 ResponseBean 是自己或者对方定义的返回内容参数 public ResponseBean sendByEncodeJson(String encodeJson, String interfaceName) throws IOException {//构建完整urlMapString, 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 MapString, String buildUrl(String method) throws IOException {MapString, 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;charsetUTF-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, MapString,String formMap) {ListNameValuePair paramsnew ArrayListNameValuePair();for(Map.EntryString, 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;charsetutf-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 responseresult);return result;}public static String sendPut(String url, String string, MapString,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, MapString, 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, MapString, String param,MapString, 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, MapString, String param) {// 创建Httpclient对象CloseableHttpClient httpClient HttpClients.createDefault();CloseableHttpResponse response null;String resultString ;try {// 创建Http Post请求HttpPost httpPost new HttpPost(url);// 创建参数列表if (param ! null) {ListNameValuePair 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,MapString,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, MapString, String queries) throws UnsupportedEncodingException {StringBuilder sbUrl new StringBuilder();sbUrl.append(host);if (null ! queries) {StringBuilder sbQuery new StringBuilder();for (Map.EntryString, 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.yingshimen.cn/news/116374/

相关文章:

  • 西安网站公司推广怎么看是哪家做的网站
  • 网站账号注册程序东营网站备案代理公司
  • 招远市建设局网站网站建设明细报价表 xls
  • jsp体育用品网站建设上海学校网站建设
  • 网站高端做中英文网站的
  • 如何设计服装网站规划广州专业网站制作哪家专业
  • 网站提示宏建站网络建立科技开发
  • 1m带宽做网站快不房地产公司排名前十
  • 有一个箭头的做网站的软件dede后台网站主页
  • 做网站的网站网站的建设分析及意义
  • 网站获取qq号码 代码校园网站的建设与管理
  • 网站添加搜索关键字资阳地seo
  • 学习php网站开发海报在线制作免费网站
  • 南京建设公司网站环保网站怎么做
  • app网站建设教程视频教程国外网站流量查询
  • 深圳手机模板建站建设优质网站需要什么
  • 做版面的网站网站建设新方向
  • 做高端品牌网站wordpress 分页静态
  • 免费seo网站网站制作的一般过程
  • 淮北建网站公司网站公司网站
  • 网站开发游戏程序开发知识付费网站源码
  • 网站云空间大小做seo_教你如何选择网站关键词
  • 长沙营销型网站制作wordpress 导航
  • 网站建设的步骤有哪些门户网站名词解释
  • 医疗网站备案要怎么做 需要准备什么材料做微商建自己的网站有用吗
  • 何炅做的代言网站鞍山做网站企业
  • 营销型网站开发网站建设的需求要素
  • 湖州营销网站建设网页设计心得体会600
  • 门户网站属于新媒体吗趣头条自媒体平台
  • weekly做网站适合做网站背景的图片