获取订单

This commit is contained in:
Lenovo 2024-07-03 11:28:45 +08:00
parent 4fee2b0002
commit dbcc47aa8b
6 changed files with 285 additions and 533 deletions

View File

@ -1,10 +1,15 @@
package com.ruoyi.business.controller; package com.ruoyi.business.controller;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.business.domain.BusStoreInfo;
import com.ruoyi.business.domain.OrderInfo;
import com.ruoyi.business.domain.PriPhoneInfo;
import com.ruoyi.business.domain.SysCookie; import com.ruoyi.business.domain.SysCookie;
import com.ruoyi.business.utils.HttpClientUtilT; import com.ruoyi.business.service.IBusStoreInfoService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.HttpClientUtilT;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
@ -15,11 +20,14 @@ import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap; import java.io.IOException;
import java.util.LinkedHashMap; import java.time.Year;
import java.util.Map; import java.util.*;
import java.util.stream.Collectors;
/** /**
* 调用美团接口 * 调用美团接口
@ -28,23 +36,32 @@ import java.util.Map;
@RequestMapping("/mt") @RequestMapping("/mt")
public class MeituanController { public class MeituanController {
@Autowired
private IBusStoreInfoService busStoreInfoService;
@Autowired
private StringRedisTemplate redisTemplate;
/** /**
* 获取cookies * 获取cookies
* @param cookie * @param cookie
* @return * @return
*/ */
@PostMapping(value = "/cookies") @PostMapping(value = "/cookies")
public AjaxResult cookie(@RequestBody SysCookie cookie) public R cookie(@RequestBody SysCookie cookie)
{ {
return AjaxResult.success(); BusStoreInfo storeInfo = new BusStoreInfo();
storeInfo.setBindUser(cookie.getUserName());
storeInfo.setStoreAccount(cookie.getAccount());
storeInfo.setStorePassword(cookie.getPassword());
storeInfo.setStoreName(cookie.getWmPoiName());
storeInfo.setStoreCookie(cookie.getCookie());
storeInfo.setPlatformType(String.valueOf(cookie.getBingType()));
storeInfo.setBindTime(new Date());
return R.ok(busStoreInfoService.insertBusStoreInfo(storeInfo));
} }
/** private JSONObject merchantOrders(int pageNum,String date,String cookie){
* 获取订单
* @return
*/
@GetMapping("/getOrders")
public R orders() {
String url = "https://e.waimai.meituan.com/gw/api/order/mix/history/list/common"; String url = "https://e.waimai.meituan.com/gw/api/order/mix/history/list/common";
Map<String,Object> params = new LinkedHashMap<>(); Map<String,Object> params = new LinkedHashMap<>();
params.put("region_id","1000510100"); params.put("region_id","1000510100");
@ -57,18 +74,97 @@ public class MeituanController {
param = param + stringObjectEntry.getKey() + "=" + stringObjectEntry.getValue()+"&"; param = param + stringObjectEntry.getKey() + "=" + stringObjectEntry.getValue()+"&";
} }
url = url + param.substring(0, param.length()-1); url = url + param.substring(0, param.length()-1);
Map<String,String> headers = new HashMap<>();
headers.put("Cookie", "WEBDFPID=81x675y2y0x156y20z8194xvv5622uv180938x0x565979585zu21vx7-2034987530564-1719627530564QGCGCKGfd79fef3d01d5e9aadc18ccd4d0c95072413; _lxsdk_cuid=19061b46258c8-0a575a85246371-d373666-1fa400-19061b4625873; _lxsdk=19061b46258c8-0a575a85246371-d373666-1fa400-19061b4625873; device_uuid=!f681d2ae-d8e3-44ae-abed-9319cef9b9a1; uuid_update=true; shopCategory=food; JSESSIONID=1uja6towq16yyjlh5bsieyjib; acctId=196975850; token=08Y-B6R3RJh0vWW3sunjIls8g5ks282V0XDqw0_8uK2I*; wmPoiId=21737990; isOfflineSelfOpen=0; city_id=510100; isChain=0; ignore_set_router_proxy=false; region_id=1000510100; region_version=1717637457; bsid=owwHans2BfoYdNrDqfvWbv2A2saE_AOD_UtRrtJNH0nhZDvBSKHje0DOtzsvg4RQ1sA0nGCkn25eIU2f8BViXA; city_location_id=510100; location_id=510107; has_not_waimai_poi=0; cityId=210100; provinceId=210000; set_info=%7B%22wmPoiId%22%3A%2221737990%22%2C%22region_id%22%3A%221000510100%22%2C%22region_version%22%3A1717637457%7D; wpush_server_url=wss://wpush.meituan.com; pushToken=08Y-B6R3RJh0vWW3sunjIls8g5ks282V0XDqw0_8uK2I*; setPrivacyTime=1_20240701; logan_session_token=9i1ql2qeonn9g01klg1m; _lxsdk_s=1906ce6f1b5-623-dde-89d%7C%7C75"); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
Map<String,Object> body = new HashMap<>(); builder.addTextBody("tag","complete");
body.put("tag","complete"); builder.addTextBody("startDate",date);
body.put("tartDate","2024-06-28"); builder.addTextBody("endDate",date);
body.put("endDate","2024-06-28"); builder.addTextBody("pageNum",String.valueOf(pageNum));
body.put("pageNum",1); builder.addTextBody("pageSize","10");
body.put("pageSize",10); builder.addTextBody("pageGray","1");
body.put("pageGray",1); HttpClient client = HttpClientBuilder.create().build();
String bodyString = JSON.toJSONString(body); HttpPost httpPost = new HttpPost(url);
String result = HttpClientUtilT.doPostJson(url,headers,bodyString); HttpEntity entity = builder.build();
return R.ok(result); httpPost.setEntity(entity);
// httpPost.setHeader("Cookie","WEBDFPID=81x675y2y0x156y20z8194xvv5622uv180938x0x565979585zu21vx7-2034987530564-1719627530564QGCGCKGfd79fef3d01d5e9aadc18ccd4d0c95072413; _lxsdk_cuid=19061b46258c8-0a575a85246371-d373666-1fa400-19061b4625873; _lxsdk=19061b46258c8-0a575a85246371-d373666-1fa400-19061b4625873; device_uuid=!f681d2ae-d8e3-44ae-abed-9319cef9b9a1; uuid_update=true; pushToken=08Y-B6R3RJh0vWW3sunjIls8g5ks282V0XDqw0_8uK2I*; shopCategory=food; JSESSIONID=17xh2gwbrxsun1rfcihmpq8qvx; acctId=196975850; token=0kw5y1iHPZlyzyFwPKIvYXEn15f2YTeJ-Ib-Vvnf8CVA*; wmPoiId=21737990; isOfflineSelfOpen=0; city_id=510100; isChain=0; ignore_set_router_proxy=false; region_id=1000510100; region_version=1717637457; bsid=JOYX5FuZ82Ng28_UmiNZbCRpG1cje_gx80ZmZEoy-QZa1feZmr2u5fSNfQt3otmx0U5-f1CzvuY_7B_I4oAO3g; city_location_id=510100; location_id=510107; has_not_waimai_poi=0; cityId=210100; provinceId=210000; set_info=%7B%22wmPoiId%22%3A%2221737990%22%2C%22region_id%22%3A%221000510100%22%2C%22region_version%22%3A1717637457%7D; wpush_server_url=wss://wpush.meituan.com; logan_session_token=p80b8gguagwg91fkep63; setPrivacyTime=1_20240702; _lxsdk_s=19072812c83-a0d-0a7-c43%7C%7C62");
httpPost.setHeader("Cookie",cookie);
HttpEntity responseEntity;
String resp;
try {
responseEntity = client.execute(httpPost).getEntity();
resp = EntityUtils.toString(responseEntity);
} catch (IOException e) {
throw new RuntimeException(e);
}
JSONObject jsonObject = JSONObject.parseObject(resp);
return jsonObject;
}
/**
* 获取订单
* @return
*/
@GetMapping("/getOrders")
public R orders() {
int pageNum = 1;
JSONObject jsonObject = merchantOrders(pageNum,"2024-06-28",
"WEBDFPID=81x675y2y0x156y20z8194xvv5622uv180938x0x565979585zu21vx7-2034987530564-1719627530564QGCGCKGfd79fef3d01d5e9aadc18ccd4d0c95072413; _lxsdk_cuid=19061b46258c8-0a575a85246371-d373666-1fa400-19061b4625873; _lxsdk=19061b46258c8-0a575a85246371-d373666-1fa400-19061b4625873; device_uuid=!f681d2ae-d8e3-44ae-abed-9319cef9b9a1; uuid_update=true; pushToken=08Y-B6R3RJh0vWW3sunjIls8g5ks282V0XDqw0_8uK2I*; shopCategory=food; JSESSIONID=17xh2gwbrxsun1rfcihmpq8qvx; acctId=196975850; token=0kw5y1iHPZlyzyFwPKIvYXEn15f2YTeJ-Ib-Vvnf8CVA*; wmPoiId=21737990; isOfflineSelfOpen=0; city_id=510100; isChain=0; ignore_set_router_proxy=false; region_id=1000510100; region_version=1717637457; bsid=JOYX5FuZ82Ng28_UmiNZbCRpG1cje_gx80ZmZEoy-QZa1feZmr2u5fSNfQt3otmx0U5-f1CzvuY_7B_I4oAO3g; city_location_id=510100; location_id=510107; has_not_waimai_poi=0; cityId=210100; provinceId=210000; set_info=%7B%22wmPoiId%22%3A%2221737990%22%2C%22region_id%22%3A%221000510100%22%2C%22region_version%22%3A1717637457%7D; wpush_server_url=wss://wpush.meituan.com; logan_session_token=p80b8gguagwg91fkep63; setPrivacyTime=1_20240702; _lxsdk_s=19072812c83-a0d-0a7-c43%7C%7C62");
String code = jsonObject.getString(("code"));
if ("0".equals(code)) {
JSONArray array = jsonObject.getJSONObject("data").getJSONArray("wmOrderList");
while ("0".equals(code) && array != null && array.size() > 0) {
String key = "wmPoiId" + "2024-06-28";
Optional<String> merDayseq = Optional.ofNullable(redisTemplate.opsForValue().get(key));
List<OrderInfo> list = new ArrayList<>();
for (int i = 0; i < array.size(); i++) {
OrderInfo orderInfo = new OrderInfo();
Object o = array.get(i);
JSONObject oj = JSONObject.parseObject(JSON.toJSONString(o));
JSONObject order0 = oj.getJSONObject("orderInfo");
JSONObject order1 = order0.getJSONObject("orderInfo");
JSONObject expectTimeVo = order1.getJSONObject("expectTimeVo");
String daySeq = order1.getString("dayseq");
String wmOrderViewId = order1.getString("wmOrderViewId");
String expectTime = expectTimeVo.getString("expectTimeFmt");
String statusDesc = order1.getString("statusDesc");
if (merDayseq.get() == null) {
redisTemplate.opsForValue().set(key, daySeq);
} else {
String redisDaySeq = redisTemplate.opsForValue().get(key);
if (Integer.valueOf(daySeq) > Integer.valueOf(redisDaySeq)) {
redisTemplate.opsForValue().set(key, daySeq);
}
if (Integer.valueOf(daySeq) == Integer.valueOf(merDayseq.get())) {
break;
}
}
orderInfo.setDaySeq(daySeq);
orderInfo.setWmOrderViewId(wmOrderViewId);
orderInfo.setExpectTimeFmt(expectTime);
orderInfo.setStatusDesc(statusDesc);
list.add(orderInfo);
}
if (list.size() > 0) {
list.stream().sorted(Comparator.comparing(OrderInfo::getDaySeq)).collect(Collectors.toList());
for (OrderInfo orderInfo : list) {
System.out.println(orderInfo.getDaySeq() + "," + orderInfo.getWmOrderViewId() + "," + orderInfo.getExpectTimeFmt() + "," + orderInfo.getStatusDesc());
}
return R.ok(JSON.toJSON(list));
}
pageNum += 1;
JSONObject jo = merchantOrders(pageNum, "2024-06-28",
"WEBDFPID=81x675y2y0x156y20z8194xvv5622uv180938x0x565979585zu21vx7-2034987530564-1719627530564QGCGCKGfd79fef3d01d5e9aadc18ccd4d0c95072413; _lxsdk_cuid=19061b46258c8-0a575a85246371-d373666-1fa400-19061b4625873; _lxsdk=19061b46258c8-0a575a85246371-d373666-1fa400-19061b4625873; device_uuid=!f681d2ae-d8e3-44ae-abed-9319cef9b9a1; uuid_update=true; pushToken=08Y-B6R3RJh0vWW3sunjIls8g5ks282V0XDqw0_8uK2I*; shopCategory=food; JSESSIONID=17xh2gwbrxsun1rfcihmpq8qvx; acctId=196975850; token=0kw5y1iHPZlyzyFwPKIvYXEn15f2YTeJ-Ib-Vvnf8CVA*; wmPoiId=21737990; isOfflineSelfOpen=0; city_id=510100; isChain=0; ignore_set_router_proxy=false; region_id=1000510100; region_version=1717637457; bsid=JOYX5FuZ82Ng28_UmiNZbCRpG1cje_gx80ZmZEoy-QZa1feZmr2u5fSNfQt3otmx0U5-f1CzvuY_7B_I4oAO3g; city_location_id=510100; location_id=510107; has_not_waimai_poi=0; cityId=210100; provinceId=210000; set_info=%7B%22wmPoiId%22%3A%2221737990%22%2C%22region_id%22%3A%221000510100%22%2C%22region_version%22%3A1717637457%7D; wpush_server_url=wss://wpush.meituan.com; logan_session_token=p80b8gguagwg91fkep63; setPrivacyTime=1_20240702; _lxsdk_s=19072812c83-a0d-0a7-c43%7C%7C62");
code = jo.getString(("code"));
array = jo.getJSONObject("data").getJSONArray("wmOrderList");
}
}
return R.fail("获取订单信息失败");
} }
@ -92,19 +188,41 @@ public class MeituanController {
for (Map.Entry<String, Object> stringObjectEntry : params.entrySet()) { for (Map.Entry<String, Object> stringObjectEntry : params.entrySet()) {
param = param + stringObjectEntry.getKey() + "=" + stringObjectEntry.getValue()+"&"; param = param + stringObjectEntry.getKey() + "=" + stringObjectEntry.getValue()+"&";
} }
param = param.substring(0, param.length()-1); url = url + param.substring(0, param.length()-1);
url = url + param;
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("searchItem","2001141341103646099"); builder.addTextBody("searchItem","2001141341103646099");
HttpClient client = HttpClientBuilder.create().build(); HttpClient client = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url); HttpPost httpPost = new HttpPost(url);
HttpEntity entity = builder.build(); HttpEntity entity = builder.build();
httpPost.setEntity(entity); httpPost.setEntity(entity);
httpPost.setHeader("Cookie","WEBDFPID=81x675y2y0x156y20z8194xvv5622uv180938x0x565979585zu21vx7-2034987530564-1719627530564QGCGCKGfd79fef3d01d5e9aadc18ccd4d0c95072413; _lxsdk_cuid=19061b46258c8-0a575a85246371-d373666-1fa400-19061b4625873; _lxsdk=19061b46258c8-0a575a85246371-d373666-1fa400-19061b4625873; device_uuid=!f681d2ae-d8e3-44ae-abed-9319cef9b9a1; uuid_update=true; shopCategory=food; JSESSIONID=1uja6towq16yyjlh5bsieyjib; acctId=196975850; token=08Y-B6R3RJh0vWW3sunjIls8g5ks282V0XDqw0_8uK2I*; wmPoiId=21737990; isOfflineSelfOpen=0; city_id=510100; isChain=0; ignore_set_router_proxy=false; region_id=1000510100; region_version=1717637457; bsid=owwHans2BfoYdNrDqfvWbv2A2saE_AOD_UtRrtJNH0nhZDvBSKHje0DOtzsvg4RQ1sA0nGCkn25eIU2f8BViXA; city_location_id=510100; location_id=510107; has_not_waimai_poi=0; cityId=210100; provinceId=210000; set_info=%7B%22wmPoiId%22%3A%2221737990%22%2C%22region_id%22%3A%221000510100%22%2C%22region_version%22%3A1717637457%7D; wpush_server_url=wss://wpush.meituan.com; pushToken=08Y-B6R3RJh0vWW3sunjIls8g5ks282V0XDqw0_8uK2I*; setPrivacyTime=1_20240701; logan_session_token=9i1ql2qeonn9g01klg1m; _lxsdk_s=1906ce6f1b5-623-dde-89d%7C%7C75"); httpPost.setHeader("Cookie","WEBDFPID=81x675y2y0x156y20z8194xvv5622uv180938x0x565979585zu21vx7-2034987530564-1719627530564QGCGCKGfd79fef3d01d5e9aadc18ccd4d0c95072413; _lxsdk_cuid=19061b46258c8-0a575a85246371-d373666-1fa400-19061b4625873; _lxsdk=19061b46258c8-0a575a85246371-d373666-1fa400-19061b4625873; device_uuid=!f681d2ae-d8e3-44ae-abed-9319cef9b9a1; uuid_update=true; pushToken=08Y-B6R3RJh0vWW3sunjIls8g5ks282V0XDqw0_8uK2I*; shopCategory=food; JSESSIONID=17xh2gwbrxsun1rfcihmpq8qvx; acctId=196975850; token=0kw5y1iHPZlyzyFwPKIvYXEn15f2YTeJ-Ib-Vvnf8CVA*; wmPoiId=21737990; isOfflineSelfOpen=0; city_id=510100; isChain=0; ignore_set_router_proxy=false; region_id=1000510100; region_version=1717637457; bsid=JOYX5FuZ82Ng28_UmiNZbCRpG1cje_gx80ZmZEoy-QZa1feZmr2u5fSNfQt3otmx0U5-f1CzvuY_7B_I4oAO3g; city_location_id=510100; location_id=510107; has_not_waimai_poi=0; cityId=210100; provinceId=210000; set_info=%7B%22wmPoiId%22%3A%2221737990%22%2C%22region_id%22%3A%221000510100%22%2C%22region_version%22%3A1717637457%7D; wpush_server_url=wss://wpush.meituan.com; logan_session_token=p80b8gguagwg91fkep63; setPrivacyTime=1_20240702; _lxsdk_s=19072812c83-a0d-0a7-c43%7C%7C62");
HttpResponse response = client.execute(httpPost); HttpResponse response = client.execute(httpPost);
HttpEntity responseEntity = response.getEntity(); HttpEntity responseEntity = response.getEntity();
String resp = EntityUtils.toString(responseEntity); String resp = EntityUtils.toString(responseEntity);
return R.ok(resp);
JSONObject jsonObject = JSONObject.parseObject(resp);
String code = jsonObject.getString(("code"));
if ("0".equals(code)) {
JSONArray array = jsonObject.getJSONArray("wmOrderList");
List<PriPhoneInfo> list = new ArrayList<>();
for (Object o : array) {
PriPhoneInfo phoneInfo = new PriPhoneInfo();
JSONObject oj = JSONObject.parseObject(JSON.toJSONString(o));
String wmOrderViewId = oj.getString("wm_order_id_view");
String privacyPhone = oj.getString("privacy_phone");
phoneInfo.setPricyPhone(privacyPhone);
phoneInfo.setOrderId(wmOrderViewId);
list.add(phoneInfo);
}
if (list.size() > 0) {
for (PriPhoneInfo phoneInfo : list) {
System.out.println(phoneInfo.getOrderId() + "," + phoneInfo.getPricyPhone());
}
return R.ok(JSON.toJSON(list));
}
}
return R.fail("获取手机号码失败");
} }
/** /**
@ -184,4 +302,12 @@ public class MeituanController {
return R.ok(result); return R.ok(result);
} }
private String valueFromCookie(String key,String text) {
String s = text.substring(text.indexOf(key), text.length());
String value = s.substring(s.indexOf("=")+1,s.indexOf(";"));
return value;
}
} }

View File

@ -1,469 +0,0 @@
package com.ruoyi.business.utils;
import org.apache.commons.io.IOUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.ServiceUnavailableRetryStrategy;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.*;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* @author lixiaohua
* @since 2019-03-18
*/
public class HttpClientUtilT {
/**
* 编码格式发送编码格式统一用UTF-8
*/
private static final String ENCODING = "UTF-8";
/**
* 设置连接超时时间单位毫秒
*/
private static final int CONNECT_TIMEOUT = 500000;
/**
* 请求获取数据的超时时间(即响应时间)单位毫秒
*/
private static final int SOCKET_TIMEOUT = 500000;
private static final int REQ_TIMEOUT = 100000;
private static PoolingHttpClientConnectionManager cm = null;
static {
cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(10);//多线程调用注意配置根据线程数设定
cm.setDefaultMaxPerRoute(50);
}
public static CloseableHttpClient getHttpClient() {
// CloseableHttpClient httpClient = HttpClients.createDefault();
ServiceUnavailableRetryStrategy serviceUnavailableRetryStrategy = new ServiceUnavailableRetryStrategy() {
/**
* retry逻辑
*/
@Override
public boolean retryRequest(HttpResponse response, int executionCount, HttpContext context) {
if (executionCount <= 3)
return true;
else
return false;
}
/**
* retry间隔时间
*/
@Override
public long getRetryInterval() {
return 20000;
}
};
/**
* evictExpiredConnections: 定期回收过期链接
* setConnectTimeout设置连接超时时间单位毫秒
* setConnectionRequestTimeout设置从connect Manager(连接池)获取Connection
* 超时时间单位毫秒这个属性是新加的属性因为目前版本是可以共享连接池的
* setSocketTimeout请求获取数据的超时时间(即响应时间)单位毫秒 如果访问一个接口多少时间内无法返回数据就直接放弃此次调用
*/
CloseableHttpClient httpClient = HttpClients.custom()
.setRetryHandler(new DefaultHttpRequestRetryHandler())
.setConnectionManager(cm)
.evictExpiredConnections()
.evictIdleConnections(1, TimeUnit.SECONDS)
.setConnectionTimeToLive(1, TimeUnit.SECONDS)
.setDefaultRequestConfig(RequestConfig
.custom()
.setSocketTimeout(SOCKET_TIMEOUT)
.setConnectionRequestTimeout(REQ_TIMEOUT)
.setConnectTimeout(CONNECT_TIMEOUT)
.build())
.build();
return httpClient;
}
/**
* 发送get请求带请求头和请求参数
*
* @param url 请求地址
* @param headers 请求头集合
* @param params 请求参数集合
* @return
* @throws Exception
*/
public static String doGet(String url, Map<String, String> headers, Map<String, Object> params) {
// 创建httpClient对象
CloseableHttpClient httpClient = getHttpClient();
// 创建httpResponse对象
CloseableHttpResponse httpResponse = null;
// 创建访问的地址
URIBuilder uriBuilder = null;
// 创建http对象
HttpGet httpGet = null;
try {
uriBuilder = new URIBuilder(url);
if (params != null && params.size() > 0) {
Set<Entry<String, Object>> entrySet = params.entrySet();
for (Entry<String, Object> entry : entrySet) {
uriBuilder.setParameter(entry.getKey(), entry.getValue().toString());
}
}
httpGet = new HttpGet(uriBuilder.build());
} catch (URISyntaxException e) {
e.printStackTrace();
}
// 设置请求头
packageHeader(headers, httpGet);
// 执行请求并获得响应结果
return getHttpClientResult(httpResponse, httpClient, httpGet);
}
/**
* 发送get请求带请求头和请求参数
*
* @param url 请求地址
* @param headers 请求头集合
* @param params 请求参数集合
* @return
* @throws Exception
*/
public static void doGet(String url, Map<String, String> headers
, Map<String, Object> params, HttpServletResponse servletResponse) {
// 创建httpClient对象
CloseableHttpClient httpClient = getHttpClient();
// 创建httpResponse对象
CloseableHttpResponse httpResponse = null;
// 创建访问的地址
URIBuilder uriBuilder = null;
// 创建http对象
HttpGet httpGet = null;
try {
uriBuilder = new URIBuilder(url);
if (params != null && params.size() > 0) {
Set<Entry<String, Object>> entrySet = params.entrySet();
for (Entry<String, Object> entry : entrySet) {
uriBuilder.setParameter(entry.getKey(), entry.getValue().toString());
}
}
httpGet = new HttpGet(uriBuilder.build());
} catch (URISyntaxException e) {
e.printStackTrace();
}
// 设置请求头
packageHeader(headers, httpGet);
// 执行请求并获得响应结果
getHttpClientResult(httpResponse, httpClient, httpGet, servletResponse);
}
/**
* post json
*
* @param url
* @param json
* @return
*/
public static String doPostByte(String url, Map<String, String> headers, byte[] json) {
// 创建httpClient对象
CloseableHttpClient httpClient = getHttpClient();
// 创建http对象
HttpPost httpPost = new HttpPost(url);
// 设置请求头
packageHeader(headers, httpPost);
// 创建请求内容
ByteArrayEntity entity = new ByteArrayEntity(json);
httpPost.setEntity(entity);
// 创建httpResponse对象
CloseableHttpResponse httpResponse = null;
// 执行请求并获得响应结果
return getHttpClientResult(httpResponse, httpClient, httpPost);
}
/**
* post headers json
*
* @param url
* @param headers
* @param json
* @return
*/
public static void doPostByte(String url, Map<String, String> headers
, byte[] json, HttpServletResponse servletResponse) {
// 创建httpClient对象
CloseableHttpClient httpClient = getHttpClient();
// 创建http对象
HttpPost httpPost = new HttpPost(url);
// 设置请求头
packageHeader(headers, httpPost);
// 创建请求内容
ByteArrayEntity entity = new ByteArrayEntity(json);
httpPost.setEntity(entity);
// 创建httpResponse对象
CloseableHttpResponse httpResponse = null;
// 执行请求并获得响应结果
getHttpClientResult(httpResponse, httpClient, httpPost, servletResponse);
}
/**
* post json
*
* @param url
* @param json
* @return
*/
public static String doPostJson(String url, Map<String, String> headers, String json) {
// 创建httpClient对象
CloseableHttpClient httpClient = getHttpClient();
// 创建http对象
HttpPost httpPost = new HttpPost(url);
// 设置请求头
packageHeader(headers, httpPost);
// 创建请求内容
StringEntity entity = new StringEntity(json, "utf-8");
httpPost.setEntity(entity);
// 创建httpResponse对象
CloseableHttpResponse httpResponse = null;
// 执行请求并获得响应结果
return getHttpClientResult(httpResponse, httpClient, httpPost);
}
/**
* post json
*
* @param url
* @param json
* @return
*/
public static void doPostJson(String url, Map<String, String> headers, String json, HttpServletResponse servletResponse) {
// 创建httpClient对象
CloseableHttpClient httpClient = getHttpClient();
// 创建http对象
HttpPost httpPost = new HttpPost(url);
// 设置请求头
packageHeader(headers, httpPost);
// 创建请求内容
StringEntity entity = new StringEntity(json, "utf-8");
httpPost.setEntity(entity);
// 创建httpResponse对象
CloseableHttpResponse httpResponse = null;
// 执行请求并获得响应结果
getHttpClientResult(httpResponse, httpClient, httpPost, servletResponse);
}
/**
* post form 上传 file
*
* @param url
* @param headers
* @param params
* @param multipartRequest
* @return
*/
public static void doPostToFile(String url, Map<String, String> headers
, Map<String, Object> params, MultipartRequest multipartRequest, HttpServletResponse servletResponse) {
// 创建httpClient对象
CloseableHttpClient httpClient = getHttpClient();
// 创建http对象
HttpPost httpPost = new HttpPost(url);
// 设置请求头
packageHeader(headers, httpPost);
httpPost.removeHeaders(HttpHeaders.CONTENT_TYPE);
packageParam(multipartRequest, params, httpPost);
// 创建httpResponse对象
CloseableHttpResponse httpResponse = null;
// 执行请求并获得响应结果
getHttpClientResult(httpResponse, httpClient, httpPost, servletResponse);
}
/**
* Description: 获得响应结果
*
* @param httpResponse
* @param httpClient
* @param httpMethod
* @return
* @throws Exception
*/
public static String getHttpClientResult(CloseableHttpResponse httpResponse
, CloseableHttpClient httpClient, HttpRequestBase httpMethod) {
// 获取返回结果
String content = "";
// 执行请求
try {
httpResponse = httpClient.execute(httpMethod);
if (httpResponse != null && httpResponse.getStatusLine() != null) {
if (httpResponse.getEntity() != null) {
content = EntityUtils.toString(httpResponse.getEntity(), ENCODING);
}
}
return content;
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("内部服务异常!");
} finally {
IOUtils.closeQuietly(httpResponse);
httpMethod.releaseConnection();
}
}
public static void getHttpClientResult(CloseableHttpResponse httpResponse
, CloseableHttpClient httpClient, HttpRequestBase httpMethod, HttpServletResponse servletResponse) {
// 执行请求
try {
httpResponse = httpClient.execute(httpMethod);
setHeader(httpResponse, servletResponse);
HttpEntity entity = httpResponse.getEntity();
OutputStream out = servletResponse.getOutputStream();
entity.writeTo(out);
out.flush();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("内部服务异常!");
} finally {
IOUtils.closeQuietly(httpResponse);
httpMethod.releaseConnection();
}
}
/**
* Description: 封装请求头
*
* @param header
* @param httpMethod
*/
public static void packageHeader(Map<String, String> header, HttpRequestBase httpMethod) {
// 封装请求头
if (header != null && header.size() > 0) {
Set<Entry<String, String>> entrySet = header.entrySet();
for (Entry<String, String> entry : entrySet) {
// 设置到请求头到HttpRequestBase对象中
// 有中文时: httpMethod.setHeader(entry.getKey(), URLEncoder.encode(entry.getValue(), "utf-8"));
httpMethod.setHeader(entry.getKey(), entry.getValue());
}
}
httpMethod.removeHeaders(HttpHeaders.CONTENT_LENGTH);
}
/**
* 将CloseableHttpResponse的响应头设置到HttpServletResponse上
*
* @param response
* @param servletResponse
*/
private static void setHeader(CloseableHttpResponse response, HttpServletResponse servletResponse) {
Header[] headers = response.getAllHeaders();
for (Header header : headers) {
System.out.println(header.getName());
if (header.getName().contains("Content-Type")
|| header.getName().equalsIgnoreCase("content-disposition")
|| header.getName().contains("Content-Length")) {
servletResponse.setHeader(header.getName(), header.getValue());
}
}
}
/**
* Description: 封装请求参数
*
* @param params
* @param httpMethod
* @throws UnsupportedEncodingException
*/
public static void packageParam(MultipartRequest multipartRequest
, Map<String, Object> params, HttpEntityEnclosingRequestBase httpMethod) {
try {
// 封装请求参数
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setCharset(Charset.forName("utf-8"));
//加上此行代码解决返回中文乱码问题
builder.setMode(HttpMultipartMode.RFC6532);
String fileName;
for (Entry<String, MultipartFile> entry : multipartRequest.getFileMap().entrySet()) {
MultipartFile multipartFile = entry.getValue();
fileName = multipartFile.getOriginalFilename();
System.out.println("文件表单上传======" + fileName + "=====");
// 文件流
builder.addBinaryBody(entry.getKey(), multipartFile.getInputStream(), ContentType.MULTIPART_FORM_DATA, fileName);
}
// 封装参数
if (params != null) {
for (String key : params.keySet()) {
System.out.println("文件表单上传======" + key + "=====" + params.get(key));
builder.addTextBody(key, params.get(key).toString(), ContentType.MULTIPART_FORM_DATA);
}
}
HttpEntity entity = builder.build();
httpMethod.setEntity(entity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException("转码异常!");
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("文件转码异常!");
}
}
}

View File

@ -9,7 +9,7 @@ import com.ruoyi.common.core.domain.BaseEntity;
/** /**
* 店铺信息对象 bus_store_info * 店铺信息对象 bus_store_info
* *
* @author ruoyi * @author ruoyi
* @date 2024-07-02 * @date 2024-07-02
*/ */
@ -31,6 +31,12 @@ public class BusStoreInfo extends BaseEntity
/** 店铺名称 */ /** 店铺名称 */
@Excel(name = "店铺名称") @Excel(name = "店铺名称")
private String storeName; private String storeName;
@Excel(name = "店铺账号")
private String storeAccount;
@Excel(name = "店铺密码")
private String storePassword;
@Excel(name = "店铺cookie")
private String storeCookie;
/** 店铺归属 */ /** 店铺归属 */
@Excel(name = "店铺归属") @Excel(name = "店铺归属")
@ -86,156 +92,180 @@ public class BusStoreInfo extends BaseEntity
@Excel(name = "归属销售绑定时间", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "归属销售绑定时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date saleBindTime; private Date saleBindTime;
public void setId(Long id) public void setId(Long id)
{ {
this.id = id; this.id = id;
} }
public Long getId() public Long getId()
{ {
return id; return id;
} }
public void setPlatformType(String platformType) public void setPlatformType(String platformType)
{ {
this.platformType = platformType; this.platformType = platformType;
} }
public String getPlatformType() public String getPlatformType()
{ {
return platformType; return platformType;
} }
public void setStoreCode(String storeCode) public void setStoreCode(String storeCode)
{ {
this.storeCode = storeCode; this.storeCode = storeCode;
} }
public String getStoreCode() public String getStoreCode()
{ {
return storeCode; return storeCode;
} }
public void setStoreName(String storeName) public void setStoreName(String storeName)
{ {
this.storeName = storeName; this.storeName = storeName;
} }
public String getStoreName() public String getStoreName()
{ {
return storeName; return storeName;
} }
public void setStoreBelong(String storeBelong) public void setStoreBelong(String storeBelong)
{ {
this.storeBelong = storeBelong; this.storeBelong = storeBelong;
} }
public String getStoreBelong() public String getStoreBelong()
{ {
return storeBelong; return storeBelong;
} }
public void setGrantStatus(String grantStatus) public void setGrantStatus(String grantStatus)
{ {
this.grantStatus = grantStatus; this.grantStatus = grantStatus;
} }
public String getGrantStatus() public String getGrantStatus()
{ {
return grantStatus; return grantStatus;
} }
public void setReturnVisitStatus(String returnVisitStatus) public void setReturnVisitStatus(String returnVisitStatus)
{ {
this.returnVisitStatus = returnVisitStatus; this.returnVisitStatus = returnVisitStatus;
} }
public String getReturnVisitStatus() public String getReturnVisitStatus()
{ {
return returnVisitStatus; return returnVisitStatus;
} }
public void setBindId(Long bindId) public void setBindId(Long bindId)
{ {
this.bindId = bindId; this.bindId = bindId;
} }
public Long getBindId() public Long getBindId()
{ {
return bindId; return bindId;
} }
public void setBindUser(String bindUser) public void setBindUser(String bindUser)
{ {
this.bindUser = bindUser; this.bindUser = bindUser;
} }
public String getBindUser() public String getBindUser()
{ {
return bindUser; return bindUser;
} }
public void setBindTime(Date bindTime) public void setBindTime(Date bindTime)
{ {
this.bindTime = bindTime; this.bindTime = bindTime;
} }
public Date getBindTime() public Date getBindTime()
{ {
return bindTime; return bindTime;
} }
public void setUpdateId(Long updateId) public void setUpdateId(Long updateId)
{ {
this.updateId = updateId; this.updateId = updateId;
} }
public Long getUpdateId() public Long getUpdateId()
{ {
return updateId; return updateId;
} }
public void setUpdateUser(Date updateUser) public void setUpdateUser(Date updateUser)
{ {
this.updateUser = updateUser; this.updateUser = updateUser;
} }
public Date getUpdateUser() public String getStoreAccount() {
return storeAccount;
}
public void setStoreAccount(String storeAccount) {
this.storeAccount = storeAccount;
}
public String getStorePassword() {
return storePassword;
}
public void setStorePassword(String storePassword) {
this.storePassword = storePassword;
}
public String getStoreCookie() {
return storeCookie;
}
public void setStoreCookie(String storeCookie) {
this.storeCookie = storeCookie;
}
public Date getUpdateUser()
{ {
return updateUser; return updateUser;
} }
public void setSelfDeliveryStatus(String selfDeliveryStatus) public void setSelfDeliveryStatus(String selfDeliveryStatus)
{ {
this.selfDeliveryStatus = selfDeliveryStatus; this.selfDeliveryStatus = selfDeliveryStatus;
} }
public String getSelfDeliveryStatus() public String getSelfDeliveryStatus()
{ {
return selfDeliveryStatus; return selfDeliveryStatus;
} }
public void setReturnVisitUserRange(String returnVisitUserRange) public void setReturnVisitUserRange(String returnVisitUserRange)
{ {
this.returnVisitUserRange = returnVisitUserRange; this.returnVisitUserRange = returnVisitUserRange;
} }
public String getReturnVisitUserRange() public String getReturnVisitUserRange()
{ {
return returnVisitUserRange; return returnVisitUserRange;
} }
public void setSaleBindId(Long saleBindId) public void setSaleBindId(Long saleBindId)
{ {
this.saleBindId = saleBindId; this.saleBindId = saleBindId;
} }
public Long getSaleBindId() public Long getSaleBindId()
{ {
return saleBindId; return saleBindId;
} }
public void setSaleBindName(String saleBindName) public void setSaleBindName(String saleBindName)
{ {
this.saleBindName = saleBindName; this.saleBindName = saleBindName;
} }
public String getSaleBindName() public String getSaleBindName()
{ {
return saleBindName; return saleBindName;
} }
public void setSaleBindTime(Date saleBindTime) public void setSaleBindTime(Date saleBindTime)
{ {
this.saleBindTime = saleBindTime; this.saleBindTime = saleBindTime;
} }
public Date getSaleBindTime() public Date getSaleBindTime()
{ {
return saleBindTime; return saleBindTime;
} }
@ -247,6 +277,9 @@ public class BusStoreInfo extends BaseEntity
.append("platformType", getPlatformType()) .append("platformType", getPlatformType())
.append("storeCode", getStoreCode()) .append("storeCode", getStoreCode())
.append("storeName", getStoreName()) .append("storeName", getStoreName())
.append("storeAccount", getStoreAccount())
.append("storePassword", getStorePassword())
.append("storeCookie", getStoreCookie())
.append("storeBelong", getStoreBelong()) .append("storeBelong", getStoreBelong())
.append("grantStatus", getGrantStatus()) .append("grantStatus", getGrantStatus())
.append("returnVisitStatus", getReturnVisitStatus()) .append("returnVisitStatus", getReturnVisitStatus())

View File

@ -0,0 +1,40 @@
package com.ruoyi.business.domain;
public class OrderInfo {
private String expectTimeFmt;
private String statusDesc;
private String wmOrderViewId;
private String daySeq;
public String getExpectTimeFmt() {
return expectTimeFmt;
}
public void setExpectTimeFmt(String expectTimeFmt) {
this.expectTimeFmt = expectTimeFmt;
}
public String getDaySeq() {
return daySeq;
}
public void setDaySeq(String daySeq) {
this.daySeq = daySeq;
}
public String getStatusDesc() {
return statusDesc;
}
public void setStatusDesc(String statusDesc) {
this.statusDesc = statusDesc;
}
public String getWmOrderViewId() {
return wmOrderViewId;
}
public void setWmOrderViewId(String wmOrderViewId) {
this.wmOrderViewId = wmOrderViewId;
}
}

View File

@ -0,0 +1,22 @@
package com.ruoyi.business.domain;
public class PriPhoneInfo {
private String orderId;
private String pricyPhone;
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public String getPricyPhone() {
return pricyPhone;
}
public void setPricyPhone(String pricyPhone) {
this.pricyPhone = pricyPhone;
}
}