From 5116c42be434b1f9f6cc84e6e9d25f8f5b4d6384 Mon Sep 17 00:00:00 2001 From: wangshuai Date: Wed, 7 Aug 2024 17:48:50 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=9B=E6=8B=89=E5=8F=96=E8=AE=A2=E5=8D=95u?= =?UTF-8?q?rl=E7=A7=BB=E5=8A=A8=E5=88=B0=E7=BA=BF=E7=A8=8B=E6=B1=A0?= =?UTF-8?q?=E5=A4=96=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MeituanController.java | 2 +- .../ruoyi/common/config/ProxyProperties.java | 2 +- .../business/service/IMeituanService.java | 2 +- .../business/service/impl/AsyncTaskImpl.java | 4 +- .../service/impl/MeituanServiceImpl.java | 47 +++++++++++++++---- 5 files changed, 43 insertions(+), 14 deletions(-) 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 a7b91d1..e1dad79 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 @@ -98,7 +98,7 @@ public class MeituanController { // String ck = "WEBDFPID=1720313779673YKASQECfd79fef3d01d5e9aadc18ccd4d0c95072894-1720313779673-1720313779673YKASQECfd79fef3d01d5e9aadc18ccd4d0c95072894; _lxsdk_cuid=1908ab11622c8-05c631efe52fbf-26031d51-1fa400-1908ab11623c8; _lxsdk=1908ab11622c8-05c631efe52fbf-26031d51-1fa400-1908ab11623c8; device_uuid=!add95b49-6d31-414c-b096-458e40b710e0; uuid_update=true; shopCategory=food; JSESSIONID=166osatxa3vej17siwfi3kfzso; logan_session_token=y5xcyzjk6epwp80j79nx; acctId=160394866; token=0vqM7ZAhWG5gEXioWJq2CpJTDb5vmeQ64StlZHudt6Pk*; wmPoiId=18277065; isOfflineSelfOpen=0; city_id=440100; isChain=0; ignore_set_router_proxy=false; region_id=1000440100; region_version=1687236854; set_info=%7B%22ignoreSetRouterProxy%22%3Afalse%2C%22region_id%22%3A%221000440100%22%2C%22region_version%22%3A1687236854%2C%22wmPoiId%22%3A18277065%7D; bsid=LA-NjGQthUuIAYmATre3dMUaeO3fwl-hrGQwBLxOUSxeJmBKyXpk1tC7WdiUH4UoqHDtHHYPiymWJM5KJ80Vag; city_location_id=440100; location_id=440103; wpush_server_url=wss%3A%2F%2Fwpush.meituan.com; has_not_waimai_poi=0; _lxsdk_s=1908ab11624-5f4-1f2-8a6%7C%7C5"; // String d = "2024-07-07"; // String poiId = "18277065"; - iMeituanService.orderInfo(wmPoiId, date, cookie); + iMeituanService.orderInfo(wmPoiId, date, cookie,""); return R.ok(); } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/ProxyProperties.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/ProxyProperties.java index 54dddd4..09aa46b 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/config/ProxyProperties.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/ProxyProperties.java @@ -125,7 +125,7 @@ public class ProxyProperties { String code = jsonObject.getString(("code")); if ("0".equals(code)) { int count = jsonObject.getJSONObject("data").getInteger(proxy); - if (count > 400) { + if (count > 30) { System.out.println("剩余:"+count); return true; } 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 e4a30ad..93b85a5 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 @@ -35,7 +35,7 @@ public interface IMeituanService { * @param cookie * @return */ - void orderInfo(String wmPoiId, String date, String cookie); + void orderInfo(String wmPoiId, String date, String cookie,String url); /** * 获取号码 diff --git a/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/AsyncTaskImpl.java b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/AsyncTaskImpl.java index 84ab319..9893e04 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/AsyncTaskImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/AsyncTaskImpl.java @@ -34,14 +34,14 @@ public class AsyncTaskImpl { @Async("asyncServiceExecutor") public void executeAsync(List busStoreInfoList, - BusStoreInfoMapper studentService, + String url, CountDownLatch countDownLatch) { try{ log.info("=============start executeAsync============="); LocalDateTime now = LocalDateTime.now(); //异步线程要做的事情 for (BusStoreInfo store : busStoreInfoList) { - iMeituanService.orderInfo(store.getStoreCode(),now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),store.getStoreCookie()); + iMeituanService.orderInfo(store.getStoreCode(),now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),store.getStoreCookie(),url); } log.error("==================end executeAsync==============="); }finally { 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 fd52ea0..51383bb 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 @@ -134,7 +134,7 @@ public class MeituanServiceImpl implements IMeituanService { storeInfo.setGrantStatus("1");//授权登录状态 storeInfo.setReturnVisitStatus("2");// 营销状态 storeInfo.setSelfDeliveryStatus("1");// 1 正常, 2 自配送, 3 删除 - storeInfo.setMarketingChannels("AI");// 默认渠道 sysDictDataMapper.selectDictLabel("bus_default_script","default_script") + storeInfo.setMarketingChannels(sysDictDataMapper.selectDictLabel("bus_default_channel","default_channel")); busStoreInfoService.insertBusStoreInfo(storeInfo); BusStoreDayInfo busStoreDayInfo = new BusStoreDayInfo(); busStoreDayInfo.setStoreId(storeInfo.getId()); @@ -295,12 +295,13 @@ public class MeituanServiceImpl implements IMeituanService { public String orderInfoList() { BusStoreInfo busStoreInfo = new BusStoreInfo(); busStoreInfo.setReturnVisitStatus("1"); + String getUrl = proxyProperties.gettpsUrl(); List busStoreInfoList = busStoreInfoMapper.selectBusStoreInfoList(busStoreInfo); long startTime = System.currentTimeMillis(); // 开始时间 List> list1= SplitListUtils.pagingList(busStoreInfoList,20); //拆分集合 CountDownLatch countDownLatch = new CountDownLatch(list1.size()); for (List list2 : list1) { - asyncTask.executeAsync(list2,busStoreInfoMapper,countDownLatch); + asyncTask.executeAsync(list2,getUrl,countDownLatch); } try { countDownLatch.await(); //保证之前的所有的线程都执行完成,才会走下面的; @@ -389,10 +390,10 @@ public class MeituanServiceImpl implements IMeituanService { * @return */ @Override - public void orderInfo(String wmPoiId, String date, String cookie) { + public void orderInfo(String wmPoiId, String date, String cookie,String getUrl) { try { int pageNum = 1; - String getUrl = proxyProperties.gettpsUrl(); +// String getUrl = proxyProperties.gettpsUrl(); BusStoreInfo storeInfo = new BusStoreInfo(); storeInfo.setStoreCode(wmPoiId); BusStoreInfo storeInfo1 = busStoreInfoMapper.selectBusStoreInfoList(storeInfo).get(0); @@ -585,7 +586,7 @@ public class MeituanServiceImpl implements IMeituanService { jsonObject = JSONObject.parseObject(resp); code = jsonObject.getString(("code")); } catch (Exception e) { - log.error("==============="+orderInfo.getOrderNo()+"私密代理订单解析号码出错:"+e.getMessage()+"==========转换隧道代理"); + log.error("==============="+orderInfo.getOrderNo()+"承接-隧道代理订单解析号码出错:"+e.getMessage()+"==========转换隧道代理"); client = proxyHttpClient(); try { HttpResponse response = client.execute(httpPost); @@ -594,16 +595,26 @@ public class MeituanServiceImpl implements IMeituanService { jsonObject = JSONObject.parseObject(resp); code = jsonObject.getString(("code")); }catch (Exception e1) { - log.error("==============="+orderInfo.getOrderNo()+"隧道代理订单解析号码出错:" + e1.getMessage() + "===========转换本地"); - client = localHttpClient(); + log.error("==============="+orderInfo.getOrderNo()+"隧道代理订单解析号码出错:" + e1.getMessage() + "===========转换私密代理"); + client = proxyHttpClient2(proxyProperties.getUrl()); try { HttpResponse response = client.execute(httpPost); HttpEntity responseEntity = response.getEntity(); String resp = EntityUtils.toString(responseEntity); jsonObject = JSONObject.parseObject(resp); code = jsonObject.getString(("code")); - } catch (Exception e2) { - log.error("==============="+orderInfo.getOrderNo()+"本地订单解析号码出错:================" + e2.getMessage()); + }catch (Exception e2){ + log.error("==============="+orderInfo.getOrderNo()+"私密代理订单解析号码出错:" + e2.getMessage() + "===========转换本地代理"); + client = localHttpClient(); + try { + HttpResponse response = client.execute(httpPost); + HttpEntity responseEntity = response.getEntity(); + String resp = EntityUtils.toString(responseEntity); + jsonObject = JSONObject.parseObject(resp); + code = jsonObject.getString(("code")); + } catch (Exception e3) { + log.error("==============="+orderInfo.getOrderNo()+"本地订单解析号码出错:================" + e3.getMessage()); + } } } } @@ -1123,4 +1134,22 @@ public class MeituanServiceImpl implements IMeituanService { return httpClient; } + private CloseableHttpClient proxyHttpClient2(String ipPort) { + System.setProperty("jdk.http.auth.tunneling.disabledSchemes", ""); + String proxyHost = ipPort.split(":")[0]; + int proxyPort = Integer.valueOf(ipPort.split(":")[1]); + String username = proxyProperties.getAccountSM(); + String password = proxyProperties.getPwdSM(); + HttpHost proxy = new HttpHost(proxyHost, proxyPort); + CredentialsProvider credsProvider = new BasicCredentialsProvider(); + credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), + new UsernamePasswordCredentials(username, password)); + RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); + CloseableHttpClient httpClient = HttpClients + .custom() + .setDefaultRequestConfig(config) + .setDefaultCredentialsProvider(credsProvider) + .build(); + return httpClient; + } }