From 1c31f7b2b9331755f2370ebf9e8febadfc358b9b Mon Sep 17 00:00:00 2001 From: wangshuai Date: Mon, 29 Jul 2024 16:38:45 +0800 Subject: [PATCH] =?UTF-8?q?1;=20=E9=9B=86=E6=88=90=E7=A7=81=E5=AF=86?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E6=96=B9=E6=B3=95=E9=85=8D=E7=BD=AE=20?= =?UTF-8?q?=E5=BC=95=E5=85=A5=E5=BE=85=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MeituanController.java | 6 +- .../ruoyi/common/config/ProxyProperties.java | 7 +- .../business/service/IMeituanService.java | 6 +- .../service/impl/MeituanServiceImpl.java | 111 ++++++++++++------ 4 files changed, 83 insertions(+), 47 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 d176fc4..c64f421 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 @@ -102,9 +102,9 @@ public class MeituanController { @ApiOperation("getStoreName") @GetMapping("/getStoreName") public R getStoreName(String cookie) { - String name = iMeituanService.getStoreName(cookie); + String name = iMeituanService.getStoreName(cookie,""); if(StringUtils.isEmpty(name)){ - name = iMeituanService.getStoreNameApi(cookie); + name = iMeituanService.getStoreNameApi(cookie,""); } return R.ok(name); } @@ -117,7 +117,7 @@ public class MeituanController { @GetMapping("/getPriPhone") public void priPhone(String orderId, String cookie) { List list = new ArrayList<>(); - iMeituanService.priPhoneInfo(list, cookie); + iMeituanService.priPhoneInfo(list, cookie,""); } @ApiOperation("getMtgsig") 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 f55cf08..5ec9b43 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 @@ -63,7 +63,7 @@ public class ProxyProperties { private String secretKeySM; - private String getUrl() { + public String getUrl() { try { // 请求参数 int num = 1; // 提取数量 @@ -112,10 +112,11 @@ public class ProxyProperties { String code = jsonObject.getString(("code")); if ("0".equals(code)) { int count = jsonObject.getJSONObject("data").getInteger(proxy); - if (count >= 0) { - System.out.println(jsonObject.getJSONObject("data").getInteger(proxy).toString()); + if (count > 600) { + System.out.println("剩余:"+count); return true; } + System.out.println("不足,剩余:"+jsonObject.getJSONObject("data").getInteger(proxy).toString()); } } finally { response.close(); 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 165c7b0..9fa4bc4 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 @@ -42,7 +42,7 @@ public interface IMeituanService { * @param cookie * @return */ - void priPhoneInfo(List list, String cookie); + void priPhoneInfo(List list, String cookie, String getUrl); /** * 获取mtgsig @@ -53,9 +53,9 @@ public interface IMeituanService { */ String mtgsigInfo(String orderId,String regionId,String regionVersion,String dfpid); - String getStoreName(String cookie); + String getStoreName(String cookie, String getUrl); - String getStoreNameApi(String cookie); + String getStoreNameApi(String cookie, String getUrl); void getReturnInfo(Long id); 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 e179894..8604aa6 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 @@ -106,15 +106,16 @@ public class MeituanServiceImpl implements IMeituanService { if(list1.size() == 0){ return "授权失败,代理账号不存在!"; } + String getUrl = proxyProperties.getUrl(); Date date = new Date(); if (list.size() == 0) { storeInfo.setBindId(list1.get(0).getId()); storeInfo.setBindUser(cookie.getUserName()); storeInfo.setStoreAccount(cookie.getAccount()); storeInfo.setStorePassword(cookie.getPassword()); - String name = getStoreName(cookie.getCookie()); + String name = getStoreName(cookie.getCookie(),getUrl); if(StringUtils.isEmpty(name)){ - name = getStoreNameApi(cookie.getCookie()); + name = getStoreNameApi(cookie.getCookie(),getUrl); } storeInfo.setStoreName(name); storeInfo.setStoreCookie(cookie.getCookie()); @@ -159,9 +160,9 @@ public class MeituanServiceImpl implements IMeituanService { storeInfo.setBindUser(cookie.getUserName()); storeInfo.setStoreAccount(cookie.getAccount()); storeInfo.setStorePassword(cookie.getPassword()); - String name = getStoreName(cookie.getCookie()); + String name = getStoreName(cookie.getCookie(),getUrl); if(StringUtils.isEmpty(name)){ - name = getStoreNameApi(cookie.getCookie()); + name = getStoreNameApi(cookie.getCookie(),getUrl); } storeInfo.setStoreName(name); storeInfo.setStoreCookie(cookie.getCookie()); @@ -284,7 +285,7 @@ public class MeituanServiceImpl implements IMeituanService { */ public boolean yesterdayCountOne(BusStoreInfo storeInfo){ - CloseableHttpClient httpClient = proxyHttpClient(); + CloseableHttpClient httpClient = proxyHttpClient(proxyProperties.getUrl()); String wmPoiId = valueFromCookie("wmPoiId", storeInfo.getStoreCookie()); String url = "https://waimaieapp.meituan.com/gw/bizdata/single/business/overview"; Map params = new HashMap<>(); @@ -358,8 +359,8 @@ public class MeituanServiceImpl implements IMeituanService { public R orderInfo(String wmPoiId, String date, String cookie) { //根据date,查询前一天的key,如果有,则删除 int pageNum = 1; - - JSONObject jsonObject = merchantOrders(pageNum, date, cookie); + String getUrl = proxyProperties.getUrl(); + JSONObject jsonObject = merchantOrders(getUrl,pageNum, date, cookie); String code = jsonObject.getString("code"); if ("0".equals(code)) { JSONArray array = jsonObject.getJSONObject("data").getJSONArray("wmOrderList"); @@ -411,7 +412,7 @@ public class MeituanServiceImpl implements IMeituanService { recipientBindedPhone = order0.getString("recipient_bindedPhone"); - orderCount = getOrderCountByType(wmOrderViewId,cookie); + orderCount = getOrderCountByType(getUrl,wmOrderViewId,cookie); } @@ -476,12 +477,12 @@ public class MeituanServiceImpl implements IMeituanService { if (list.size() > 0) { List newList = list.stream().collect(Collectors.toMap(BusOrderInfo::getOrderNo, p->p,(p1, p2)->p1)).values().stream().collect(Collectors.toList()); - priPhoneInfo(newList,cookie); + priPhoneInfo(newList,cookie,getUrl); } pageNum += 1; - JSONObject jo = merchantOrders(pageNum, date, cookie); + JSONObject jo = merchantOrders(getUrl,pageNum, date, cookie); if ("0".equals(jo.getString("code"))) { array = jo.getJSONObject("data").getJSONArray("wmOrderList"); } else if ("1001".equals(jo.getString("code"))) { @@ -506,8 +507,8 @@ public class MeituanServiceImpl implements IMeituanService { return R.fail(jsonObject.getString("msg")); } - private String getOrderCountByType(String wmOrderViewId,String cookie){ - CloseableHttpClient httpClient = proxyHttpClient(); + private String getOrderCountByType(String getUrl, String wmOrderViewId,String cookie){ + CloseableHttpClient httpClient = proxyHttpClient(getUrl); String url = "https://e.waimai.meituan.com/gw/phf/v2/order/receive/processed/r/orderAsyncInfos/v3"; Map params = new HashMap<>(); params.put("region_id", valueFromCookie("region_id",cookie)); @@ -541,7 +542,7 @@ public class MeituanServiceImpl implements IMeituanService { return null; } - private JSONObject merchantOrders(int pageNum, String date, String cookie) { + private JSONObject merchantOrders(String getUrl, 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", valueFromCookie("region_id", cookie)); @@ -567,7 +568,7 @@ public class MeituanServiceImpl implements IMeituanService { httpPost.setHeader("Host","waimaieapp.meituan.com"); httpPost.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"); - CloseableHttpClient client = proxyHttpClient(); + CloseableHttpClient client = proxyHttpClient(getUrl); // CloseableHttpClient client = HttpClientBuilder.create().build(); HttpEntity responseEntity; String resp = null; @@ -584,7 +585,7 @@ public class MeituanServiceImpl implements IMeituanService { } @Override - public String getStoreName(String cookie){ + public String getStoreName(String cookie,String getUrl){ String url = "https://e.waimai.meituan.com/v2/index/homePage"; Map params = new LinkedHashMap<>(); params.put("region_id", valueFromCookie("region_id", cookie)); @@ -596,7 +597,7 @@ public class MeituanServiceImpl implements IMeituanService { HttpGet request = new HttpGet(url); request.setHeader("Cookie",cookie); request.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"); - CloseableHttpClient client = proxyHttpClient(); + CloseableHttpClient client = proxyHttpClient(getUrl); String result = null; try { result = EntityUtils.toString(client.execute(request).getEntity()); @@ -617,7 +618,7 @@ public class MeituanServiceImpl implements IMeituanService { } @Override - public String getStoreNameApi(String cookie){ + public String getStoreNameApi(String cookie,String getUrl){ String url = "https://e.waimai.meituan.com/api/v2/account/homePage"; Map params = new LinkedHashMap<>(); params.put("region_id", valueFromCookie("region_id", cookie)); @@ -630,7 +631,7 @@ public class MeituanServiceImpl implements IMeituanService { HttpGet request = new HttpGet(url); request.setHeader("Cookie",cookie); request.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"); - CloseableHttpClient client = proxyHttpClient(); + CloseableHttpClient client = proxyHttpClient(getUrl); String result = null; try { result = EntityUtils.toString(client.execute(request).getEntity()); @@ -656,7 +657,7 @@ public class MeituanServiceImpl implements IMeituanService { */ @Override @Transactional(rollbackFor = Exception.class) - public void priPhoneInfo(List ls, String cookie) { + public void priPhoneInfo(List ls, String cookie,String getUrl) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); List lsList = ls.stream().filter(x -> x.getPrivcyPhone() != null && x.getRecipientPhone() != null && x.getRecipientBindedPhone() != null).collect(Collectors.toList()); @@ -687,7 +688,7 @@ public class MeituanServiceImpl implements IMeituanService { httpPost.setEntity(entity); httpPost.setHeader("Cookie", cookie); - CloseableHttpClient client = proxyHttpClient(); + CloseableHttpClient client = proxyHttpClient(getUrl); String code = null; JSONObject jsonObject = new JSONObject(); @@ -749,7 +750,7 @@ public class MeituanServiceImpl implements IMeituanService { @Override @Transactional(rollbackFor = Exception.class) public String mtgsigInfo(String orderId, String regionId, String regionVersion,String dfpid) { - CloseableHttpClient httpClient = proxyHttpClient(); + CloseableHttpClient httpClient = proxyHttpClient(proxyProperties.getUrl()); String url = "http://43.140.224.18:12000/get_mtgsig"; HttpPost httpPost = new HttpPost(url); httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); @@ -850,7 +851,7 @@ public class MeituanServiceImpl implements IMeituanService { */ @Transactional(rollbackFor = Exception.class) public Boolean getScoreOne(BusStoreInfo store) { - CloseableHttpClient httpClient = proxyHttpClient(); + CloseableHttpClient httpClient = proxyHttpClient(proxyProperties.getUrl()); String wmPoiId = valueFromCookie("wmPoiId", store.getStoreCookie()); String url = "https://waimaieapp.meituan.com/gw/customer/comment/scores"; Map params = new HashMap<>(); @@ -930,7 +931,7 @@ public class MeituanServiceImpl implements IMeituanService { request.setHeader("Cookie",store.getStoreCookie()); String result = null; try { - CloseableHttpClient httpClient = proxyHttpClient(); + CloseableHttpClient httpClient = proxyHttpClient(proxyProperties.getUrl()); result = EntityUtils.toString(httpClient.execute(request).getEntity()); if (StringUtils.isEmpty(result)) { System.out.println(result); @@ -982,23 +983,57 @@ public class MeituanServiceImpl implements IMeituanService { return url; } - private CloseableHttpClient proxyHttpClient() { - String proxyHost = proxyProperties.getProxyAddr(); - int proxyPort = proxyProperties.getProxyPort(); - String username = proxyProperties.getAccount(); - String password = proxyProperties.getPwd(); - HttpHost proxy = new HttpHost(proxyHost, proxyPort); + private CloseableHttpClient proxyHttpClient(String ipPort) { +// String proxyHost = proxyProperties.getProxyAddr(); +// int proxyPort = proxyProperties.getProxyPort(); +// String username = proxyProperties.getAccount(); +// String password = proxyProperties.getPwd(); +// 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(); +//// CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(config).build(); +// return httpClient; + +// String ipPort = proxyProperties.getUrl(); + // JDK 8u111版本后,目标页面为HTTPS协议,启用proxy用户密码鉴权 + System.setProperty("jdk.http.auth.tunneling.disabledSchemes", ""); + + String ip = ipPort.split(":")[0]; + int port = Integer.valueOf(ipPort.split(":")[1]); + HttpHost proxy = new HttpHost(ip, port); CredentialsProvider credsProvider = new BasicCredentialsProvider(); - credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), - new UsernamePasswordCredentials(username, password)); + credsProvider.setCredentials(new AuthScope(ip, port), + new UsernamePasswordCredentials(proxyProperties.getAccountSM(), proxyProperties.getPwdSM())); RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); - CloseableHttpClient httpClient = HttpClients - .custom() - .setDefaultRequestConfig(config) - .setDefaultCredentialsProvider(credsProvider) - .build(); -// CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(config).build(); - return httpClient; + CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).setDefaultRequestConfig(config).build(); + return httpclient; +// try { +// URL url = new URL(pageUrl); +// HttpHost target = new HttpHost(url.getHost(), url.getDefaultPort(), url.getProtocol()); +// HttpHost proxy = new HttpHost(proxyIp, proxyPort); +// +// RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); +// HttpGet httpget = new HttpGet(url.getPath()); +// httpget.setConfig(config); +// httpget.addHeader("Accept-Encoding", "gzip"); // 使用gzip压缩传输数据让访问更快 +// httpget.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36"); +// CloseableHttpResponse response = httpclient.execute(target, httpget); +// try { +// System.out.println(response.getStatusLine()); +// System.out.println(EntityUtils.toString(response.getEntity())); +// } finally { +// response.close(); +// } +// } finally { +// httpclient.close(); +// } } }