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

Commit 54533841 authored by jiangxiulong's avatar jiangxiulong

test

parent ece5d399
...@@ -75,7 +75,7 @@ public class PerformancesExpressController extends BaseController { ...@@ -75,7 +75,7 @@ public class PerformancesExpressController extends BaseController {
@RequiresPermissions("kylin:performancesExpress:placeOrder") @RequiresPermissions("kylin:performancesExpress:placeOrder")
@PostMapping("/placeOrder") @PostMapping("/placeOrder")
@ResponseBody @ResponseBody
public AjaxResult placeOrder(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) { public AjaxResult placeOrder(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) throws Exception {
ResponseDto res = performancesExpressServiceImpl.placeOrder(performanceExpressSearchAdminParam); ResponseDto res = performancesExpressServiceImpl.placeOrder(performanceExpressSearchAdminParam);
try { try {
if (res.isSuccess()) { if (res.isSuccess()) {
......
...@@ -121,7 +121,7 @@ public class PerformancesExpressServiceImpl extends ServiceImpl<KylinOrderExpres ...@@ -121,7 +121,7 @@ public class PerformancesExpressServiceImpl extends ServiceImpl<KylinOrderExpres
return voList; return voList;
} }
public ResponseDto placeOrder(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) { public ResponseDto placeOrder(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) throws Exception {
List<String> ids = performanceExpressSearchAdminParam.getIds(); List<String> ids = performanceExpressSearchAdminParam.getIds();
for (String orderTicketsId : ids) { for (String orderTicketsId : ids) {
// 已经存在未取消的下单数据过滤掉 // 已经存在未取消的下单数据过滤掉
...@@ -155,7 +155,7 @@ public class PerformancesExpressServiceImpl extends ServiceImpl<KylinOrderExpres ...@@ -155,7 +155,7 @@ public class PerformancesExpressServiceImpl extends ServiceImpl<KylinOrderExpres
kylinOrderExpressMapper.insert(kylinOrderExpressPre); kylinOrderExpressMapper.insert(kylinOrderExpressPre);
// 请求下单数据 // 请求下单数据
HashMap<String, Object> hBody = new HashMap<>(); Map<String, String> hBody = new HashMap<>();
hBody.put("custid", custid); hBody.put("custid", custid);
hBody.put("jCompany", jCompany); hBody.put("jCompany", jCompany);
hBody.put("jContact", jContact); hBody.put("jContact", jContact);
...@@ -165,21 +165,21 @@ public class PerformancesExpressServiceImpl extends ServiceImpl<KylinOrderExpres ...@@ -165,21 +165,21 @@ public class PerformancesExpressServiceImpl extends ServiceImpl<KylinOrderExpres
hBody.put("jAddress", jAddress); hBody.put("jAddress", jAddress);
// TODO: 2021/6/30 前端选择 // TODO: 2021/6/30 前端选择
hBody.put("payMethod", 2);// 运费付款方式:0-寄付月结;1-寄付现结;2-收方付;3-第三方付; hBody.put("payMethod", "2");// 运费付款方式:0-寄付月结;1-寄付现结;2-收方付;3-第三方付;
hBody.put("expressType", expressType);// 顺丰特快 hBody.put("expressType", expressType.toString());// 顺丰特快
hBody.put("depositumInfo", depositumInfo); hBody.put("depositumInfo", depositumInfo);
hBody.put("orderId", OrderExpressCode); hBody.put("orderId", OrderExpressCode);
hBody.put("depositumNo", orderInfo.getNumber()); hBody.put("depositumNo", orderInfo.getNumber().toString());
hBody.put("dContact", orderInfo.getExpressContacts()); hBody.put("dContact", orderInfo.getExpressContacts());
hBody.put("dMobile", orderInfo.getExpressPhone()); hBody.put("dMobile", orderInfo.getExpressPhone());
hBody.put("dAddress", orderInfo.getExpressAddress()); hBody.put("dAddress", orderInfo.getExpressAddress());
// 生成签名并请求 // 生成签名并请求
String result = shunfengSignUtils.generateSignatureAndRequest(hBody, "/public/order/v1/placeOrder"); String result = shunfengSignUtils.generateSignatureAndRequestTest(hBody, "/public/order/v1/placeOrder");
System.out.println(result); System.out.println(result);
HashMap hashMap = new HashMap(); HashMap hashMap = new HashMap();
try { try {
...@@ -499,7 +499,7 @@ public class PerformancesExpressServiceImpl extends ServiceImpl<KylinOrderExpres ...@@ -499,7 +499,7 @@ public class PerformancesExpressServiceImpl extends ServiceImpl<KylinOrderExpres
} }
// @Async // @Async
public void batchPlaceOrder(String performanceId) { public void batchPlaceOrder(String performanceId) throws Exception {
int count; int count;
int limitNum = 10; int limitNum = 10;
int mid = 0; int mid = 0;
......
package com.liquidnet.client.admin.zhengzai.kylin.utils;
import com.liquidnet.client.admin.common.utils.StringUtils;
import org.springframework.stereotype.Component;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
/**
* author:
* date:
* time:
* description: HttpClient调用Https接口封装.
*/
@Component
public class HttpClientUtils {
public static HttpResponse doGet(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpGet request = new HttpGet(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
return httpClient.execute(request);
}
/**
* post form
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param bodys
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
Map<String, String> bodys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (bodys != null) {
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
for (String key : bodys.keySet()) {
nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
}
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
request.setEntity(formEntity);
}
return httpClient.execute(request);
}
/**
* Post String
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
String body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, "utf-8"));
}
return httpClient.execute(request);
}
/**
* Post stream
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
/**
* Put String
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
String body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, "utf-8"));
}
return httpClient.execute(request);
}
/**
* Put stream
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
/**
* Delete
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @return
* @throws Exception
*/
public static HttpResponse doDelete(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
return httpClient.execute(request);
}
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
StringBuilder sbUrl = new StringBuilder();
sbUrl.append(host);
if (!StringUtils.isBlank(path)) {
sbUrl.append(path);
}
if (null != querys) {
StringBuilder sbQuery = new StringBuilder();
for (Map.Entry<String, String> query : querys.entrySet()) {
if (0 < sbQuery.length()) {
sbQuery.append("&");
}
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
sbQuery.append(query.getValue());
}
if (!StringUtils.isBlank(query.getKey())) {
sbQuery.append(query.getKey());
if (!StringUtils.isBlank(query.getValue())) {
sbQuery.append("=");
sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
}
}
}
if (0 < sbQuery.length()) {
sbUrl.append("?").append(sbQuery);
}
}
return sbUrl.toString();
}
private static HttpClient wrapClient(String host) {
HttpClient httpClient = new DefaultHttpClient();
if (host.startsWith("https://")) { //根据传来的URL 进行生产对应的Httpclient
sslClient(httpClient);
}
return httpClient;
}
private static void sslClient(HttpClient httpClient) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] xcs, String str) {
}
public void checkServerTrusted(X509Certificate[] xcs, String str) {
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = httpClient.getConnectionManager();
SchemeRegistry registry = ccm.getSchemeRegistry();
registry.register(new Scheme("https", 443, ssf));
} catch (KeyManagementException ex) {
throw new RuntimeException(ex);
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
}
}
\ No newline at end of file
...@@ -10,6 +10,7 @@ import org.apache.commons.codec.binary.Base64; ...@@ -10,6 +10,7 @@ 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.entity.StringEntity; import org.apache.http.entity.StringEntity;
...@@ -23,6 +24,7 @@ import org.springframework.stereotype.Component; ...@@ -23,6 +24,7 @@ import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
/** /**
* <p> * <p>
...@@ -58,6 +60,38 @@ public class ShunfengSignUtils { ...@@ -58,6 +60,38 @@ public class ShunfengSignUtils {
@Autowired @Autowired
private KylinOrderExpressMapper kylinOrderExpressMapper; private KylinOrderExpressMapper kylinOrderExpressMapper;
/**
* 生成签名并请求
* @param hbody 请求body
* @return
*/
public String generateSignatureAndRequestTest(Map<String, String> hbody, String url) throws Exception {
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");
// CloseableHttpClient client = HttpClients.createDefault();
Map<String, String> querys = new HashMap<>();
HttpResponse httpResponse = HttpClientUtils.doPost(URL, url, "", headers, querys, hbody);
System.out.println(httpResponse);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
System.out.println("发送请求成功");
HttpEntity entity = httpResponse.getEntity();
// 发送响应且编码UTF8!!!
return EntityUtils.toString(entity, "utf-8");
}
return "error";
}
/** /**
* 生成签名并请求 * 生成签名并请求
* @param hbody 请求body * @param hbody 请求body
......
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