记得上下班打卡 | git大法好,push需谨慎

Commit 2e700756 authored by jiangxiulong's avatar jiangxiulong

快递 http

parent 0e5faf8f
package com.liquidnet.client.admin.zhengzai.kylin.utils; package com.liquidnet.client.admin.zhengzai.kylin.utils;
import com.liquidnet.client.admin.common.utils.http.HttpUtils;
import com.liquidnet.commons.lang.util.JsonUtils; import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.UserPathDto; import com.liquidnet.service.base.UserPathDto;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -8,20 +7,15 @@ import org.apache.commons.codec.binary.Base64; ...@@ -8,20 +7,15 @@ import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.net.ssl.SSLContext;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -78,56 +72,14 @@ public class ShunfengSignUtils { ...@@ -78,56 +72,14 @@ public class ShunfengSignUtils {
headers.put("Accept", "application/json"); headers.put("Accept", "application/json");
Map<String, String> querys = new HashMap<>(); Map<String, String> querys = new HashMap<>();
try { try {
// HttpResponse httpResponse = HttpClientUtils.doPost(URL, url, "", headers, querys, body);
// HttpEntity httpEntity = new HttpEntity(body, "utf-8");
// HttpEntity httpEntity = new HttpEntity(body, "utf-8");
HttpEntity httpEntity = new StringEntity(body, "utf-8"); HttpEntity httpEntity = new StringEntity(body, "utf-8");
String post = HttpsUtils.post(URL + url, headers, querys, httpEntity); String post = HttpsUtils.post(URL + url, headers, querys, httpEntity);
return post; return post;
// HttpResponse httpResponse = HttpsUtils.post(URL+url, headers, querys, httpEntity);
/*if (httpResponse.getStatusLine().getStatusCode() == 200) {
System.out.println("发送请求成功");
HttpEntity entity = httpResponse.getEntity();
// 发送响应且编码UTF8!!!
return EntityUtils.toString(entity, "utf-8");
}*/
} catch (Exception e) { } catch (Exception e) {
System.out.println("发送请求失败"); System.out.println("发送请求失败");
e.printStackTrace(); e.printStackTrace();
return e.getMessage(); return e.getMessage();
} }
// return null;
}
/**
* 生成签名并请求
* @param hbody 请求body
* @return
*/
public String generateSignatureAndRequestNew2(Map<String, String> hbody, String url) {
long currentTimeMillis = System.currentTimeMillis(); // 时间戳
String timestamp = currentTimeMillis + "";
hbody.put("companyId", APP_ID);
String body = JsonUtils.toJson(hbody);
// 生成签名
String sign = genSign(timestamp,body);
Map<String, String> headers = new HashMap<>();
headers.put("sendAppId", APP_ID);
headers.put("timestamp", timestamp);
headers.put("sign", sign);
headers.put("Content-Type", "application/json;charset=utf-8");
headers.put("Accept", "application/json");
try {
String sss = HttpUtils.sendSSLPost(URL + url, body);
System.out.println("发送请求成功");
System.out.println(sss);
} catch (Exception e) {
System.out.println("发送请求失败");
e.printStackTrace();
return e.getMessage();
}
return null;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment