订单信息

This commit is contained in:
Lenovo 2024-07-04 10:38:22 +08:00
parent 9170847216
commit 83182686ad
3 changed files with 172 additions and 104 deletions

View File

@ -4,9 +4,9 @@ import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.business.domain.BusStoreInfo; import com.ruoyi.business.domain.BusStoreInfo;
import com.ruoyi.business.domain.OrderInfo;
import com.ruoyi.business.domain.PriPhoneInfo; import com.ruoyi.business.domain.PriPhoneInfo;
import com.ruoyi.business.domain.SysCookie; import com.ruoyi.business.domain.SysCookie;
import com.ruoyi.business.service.IBusCookieService;
import com.ruoyi.business.service.IBusStoreInfoService; import com.ruoyi.business.service.IBusStoreInfoService;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.HttpClientUtilT; import com.ruoyi.common.utils.HttpClientUtilT;
@ -21,13 +21,9 @@ 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.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.io.IOException;
import java.time.Year;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* 调用美团接口 * 调用美团接口
@ -40,7 +36,7 @@ public class MeituanController {
private IBusStoreInfoService busStoreInfoService; private IBusStoreInfoService busStoreInfoService;
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private IBusCookieService cookieService;
/** /**
* 获取cookies * 获取cookies
@ -62,110 +58,13 @@ public class MeituanController {
return R.ok(busStoreInfoService.insertBusStoreInfo(storeInfo)); return R.ok(busStoreInfoService.insertBusStoreInfo(storeInfo));
} }
private JSONObject merchantOrders(int pageNum,String date,String cookie){
String url = "https://e.waimai.meituan.com/gw/api/order/mix/history/list/common";
Map<String,Object> params = new LinkedHashMap<>();
params.put("region_id","1000510100");
params.put("region_version","1717637457");
params.put("yodaReady","h5");
params.put("csecplatform",4);
params.put("csecversion","2.4.0");
String param = "?";
for (Map.Entry<String, Object> stringObjectEntry : params.entrySet()) {
param = param + stringObjectEntry.getKey() + "=" + stringObjectEntry.getValue()+"&";
}
url = url + param.substring(0, param.length()-1);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("tag","complete");
builder.addTextBody("startDate",date);
builder.addTextBody("endDate",date);
builder.addTextBody("pageNum",String.valueOf(pageNum));
builder.addTextBody("pageSize","10");
builder.addTextBody("pageGray","1");
HttpClient client = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
HttpEntity entity = builder.build();
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 * @return
*/ */
@GetMapping("/getOrders") @GetMapping("/getOrders")
public R orders() { public R orders() {
int pageNum = 1; return cookieService.orderInfo();
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("获取订单信息失败");
} }

View File

@ -0,0 +1,23 @@
package com.ruoyi.business.service;
import com.ruoyi.business.domain.BusAgentInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import java.util.List;
/**
* 代理管理Service接口
*
* @author ruoyi
* @date 2024-07-03
*/
public interface IBusCookieService
{
/**
* 获取订单
* @return
*/
R orderInfo();
}

View File

@ -0,0 +1,146 @@
package com.ruoyi.business.service.impl;
import com.ruoyi.business.service.IBusCookieService;
import com.ruoyi.common.core.domain.R;
import org.springframework.stereotype.Service;
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.service.IBusStoreInfoService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.HttpClientUtilT;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
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 java.io.IOException;
import java.time.Year;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class BusCookieServiceImpl implements IBusCookieService {
@Autowired
private StringRedisTemplate redisTemplate;
@Override
public R orderInfo() {
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=on7soe32fcruh809e5hfls7z; acctId=196975850; token=0pU06uu_iGAHgwhFO85t0G6PZxaoBiSNFdZyi2pS2mG0*; wmPoiId=21737990; isOfflineSelfOpen=0; city_id=510100; isChain=0; ignore_set_router_proxy=false; region_id=1000510100; region_version=1717637457; bsid=19mI8ZOraG-XXNAMJ2qmJEDbBIf97CFoQ_ndkcmZM0iBR9UKTpOcERrZsXLftuuJUJ6l1nOl3Q5pc0lul3KOWw; 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; setPrivacyTime=1_20240704; wpush_server_url=wss://wpush.meituan.com; logan_session_token=h11r1rr8yb4n872vhlsr; _lxsdk_s=1907b53fb56-164-582-76a%7C%7C62");
String code = jsonObject.getString("code");
if ("0".equals(code)) {
JSONArray array = jsonObject.getJSONObject("data").getJSONArray("wmOrderList");
boolean flag = false;
String key = "wmPoiId" + "2024-06-28";
String lastDayseq = Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse(null);
while (array != null && array.size() > 0) {
if (flag){
break;
}
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");
String redisDaySeq = Optional.ofNullable(redisTemplate.opsForValue().get(key)).orElse(null);
if (redisDaySeq == null) {
redisTemplate.opsForValue().set(key, daySeq);
} else {
if (Integer.valueOf(daySeq) > Integer.valueOf(redisDaySeq)) {
redisTemplate.opsForValue().set(key, daySeq);
}
if (daySeq.equals(lastDayseq)) {
flag = true;
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());
}
}
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=on7soe32fcruh809e5hfls7z; acctId=196975850; token=0pU06uu_iGAHgwhFO85t0G6PZxaoBiSNFdZyi2pS2mG0*; wmPoiId=21737990; isOfflineSelfOpen=0; city_id=510100; isChain=0; ignore_set_router_proxy=false; region_id=1000510100; region_version=1717637457; bsid=19mI8ZOraG-XXNAMJ2qmJEDbBIf97CFoQ_ndkcmZM0iBR9UKTpOcERrZsXLftuuJUJ6l1nOl3Q5pc0lul3KOWw; 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; setPrivacyTime=1_20240704; wpush_server_url=wss://wpush.meituan.com; logan_session_token=h11r1rr8yb4n872vhlsr; _lxsdk_s=1907b53fb56-164-582-76a%7C%7C62");
if("0".equals(jo.getString("code"))){
array = jo.getJSONObject("data").getJSONArray("wmOrderList");
} else {
System.out.println(jo.getString("msg"));
break;
}
}
return R.ok();
}
return R.fail(jsonObject.getString("msg"));
}
private JSONObject merchantOrders(int pageNum,String date,String cookie){
String url = "https://e.waimai.meituan.com/gw/api/order/mix/history/list/common";
Map<String,Object> params = new LinkedHashMap<>();
params.put("region_id","1000510100");
params.put("region_version","1717637457");
params.put("yodaReady","h5");
params.put("csecplatform",4);
params.put("csecversion","2.4.0");
String param = "?";
for (Map.Entry<String, Object> stringObjectEntry : params.entrySet()) {
param = param + stringObjectEntry.getKey() + "=" + stringObjectEntry.getValue()+"&";
}
url = url + param.substring(0, param.length()-1);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("tag","complete");
builder.addTextBody("startDate",date);
builder.addTextBody("endDate",date);
builder.addTextBody("pageNum",String.valueOf(pageNum));
builder.addTextBody("pageSize","10");
builder.addTextBody("pageGray","1");
HttpClient client = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
HttpEntity entity = builder.build();
httpPost.setEntity(entity);
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;
}
}