From 83182686adf47fd3facde6ba621455631bb9d2a7 Mon Sep 17 00:00:00 2001 From: Lenovo Date: Thu, 4 Jul 2024 10:38:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MeituanController.java | 107 +------------ .../business/service/IBusCookieService.java | 23 +++ .../service/impl/BusCookieServiceImpl.java | 146 ++++++++++++++++++ 3 files changed, 172 insertions(+), 104 deletions(-) create mode 100644 ruoyi-system/src/main/java/com/ruoyi/business/service/IBusCookieService.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/business/service/impl/BusCookieServiceImpl.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/business/controller/MeituanController.java b/ruoyi-admin/src/main/java/com/ruoyi/business/controller/MeituanController.java index 956301d..118187f 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/business/controller/MeituanController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/business/controller/MeituanController.java @@ -4,9 +4,9 @@ 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.IBusCookieService; import com.ruoyi.business.service.IBusStoreInfoService; import com.ruoyi.common.core.domain.R; 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.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; /** * 调用美团接口 @@ -40,7 +36,7 @@ public class MeituanController { private IBusStoreInfoService busStoreInfoService; @Autowired - private StringRedisTemplate redisTemplate; + private IBusCookieService cookieService; /** * 获取cookies @@ -62,110 +58,13 @@ public class MeituanController { 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 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 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 */ @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 merDayseq = Optional.ofNullable(redisTemplate.opsForValue().get(key)); - - List 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("获取订单信息失败"); + return cookieService.orderInfo(); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/business/service/IBusCookieService.java b/ruoyi-system/src/main/java/com/ruoyi/business/service/IBusCookieService.java new file mode 100644 index 0000000..12e92f9 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/business/service/IBusCookieService.java @@ -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(); + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/BusCookieServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/BusCookieServiceImpl.java new file mode 100644 index 0000000..f6e7e55 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/BusCookieServiceImpl.java @@ -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 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 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 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; + } +}