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 e74a58d..7027386 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 @@ -6,11 +6,9 @@ import com.alibaba.fastjson2.JSONObject; import com.ruoyi.business.domain.BusStoreInfo; 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.business.service.IMeituanService; 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; @@ -36,9 +34,6 @@ public class MeituanController { @Autowired private IBusStoreInfoService busStoreInfoService; - @Autowired - private IBusCookieService cookieService; - @Autowired private IMeituanService iMeituanService; /** @@ -67,7 +62,7 @@ public class MeituanController { */ @GetMapping("/getOrders") public R orders() { - return cookieService.orderInfo(); + return iMeituanService.orderInfo(); } @@ -135,25 +130,6 @@ public class MeituanController { @GetMapping("/getComments") public R comments() { String result = iMeituanService.getComments(); - //commScore=1 好评;commScore=0 全部(即订单量);五星好评取返回结果orderCommentScore=5 -// String url = "https://waimaieapp.meituan.com/gw/customer/comment/list"; -// Map params = new HashMap<>(); -// params.put("ignoreSetRouterProxy",true); -// params.put("acctId","196975850"); -// params.put("wmPoiId","21737990"); -// params.put("token","08Y-B6R3RJh0vWW3sunjIls8g5ks282V0XDqw0_8uK2I*"); -// params.put("appType",3); -// params.put("commScore",1); -// params.put("commType",-1); -// params.put("hasContent",-1); -// params.put("periodType",4); -// params.put("beginTime",1719676800); -// params.put("endTime",1719676800); -// params.put("onlyAuditNotPass",0); -// params.put("pageNum",1); -// params.put("pageSize",10); -// params.put("source",1); -// String result = HttpClientUtilT.doGet(url,null,params); return R.ok(result); } 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 deleted file mode 100644 index 12e92f9..0000000 --- a/ruoyi-system/src/main/java/com/ruoyi/business/service/IBusCookieService.java +++ /dev/null @@ -1,23 +0,0 @@ -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/IMeituanService.java b/ruoyi-system/src/main/java/com/ruoyi/business/service/IMeituanService.java index ee48cb9..dab5ddd 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/business/service/IMeituanService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/business/service/IMeituanService.java @@ -1,7 +1,12 @@ package com.ruoyi.business.service; +import com.ruoyi.common.core.domain.R; + public interface IMeituanService { String getComments(); String getScore(); + + 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 deleted file mode 100644 index f6e7e55..0000000 --- a/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/BusCookieServiceImpl.java +++ /dev/null @@ -1,146 +0,0 @@ -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; - } -} diff --git a/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/MeituanServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/MeituanServiceImpl.java index e480db1..53846ae 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/MeituanServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/MeituanServiceImpl.java @@ -1,15 +1,27 @@ package com.ruoyi.business.service.impl; +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.mapper.BusStoreInfoMapper; import com.ruoyi.business.service.IMeituanService; +import com.ruoyi.common.core.domain.R; import com.ruoyi.common.utils.HttpClientUtilT; +import org.apache.http.HttpEntity; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.mime.MultipartEntityBuilder; +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.stereotype.Service; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; @Service public class MeituanServiceImpl implements IMeituanService { @@ -17,6 +29,9 @@ public class MeituanServiceImpl implements IMeituanService { @Autowired private BusStoreInfoMapper busStoreInfoMapper; + @Autowired + private StringRedisTemplate redisTemplate; + @Override public String getComments() { BusStoreInfo busStoreInfo = new BusStoreInfo(); @@ -39,6 +54,112 @@ public class MeituanServiceImpl implements IMeituanService { return "ok"; } + @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; + } + /** * 获取评分 * @return