From 3024ccc78266db89a1f4e79cc55ee92ef6bea767 Mon Sep 17 00:00:00 2001 From: wangshuai Date: Sat, 6 Jul 2024 11:19:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E6=88=90=E5=BF=AB=E4=BB=A3=E7=90=86?= =?UTF-8?q?=20ip=E6=B1=A0=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 12 ++- .../ruoyi/common/config/ProxyProperties.java | 43 +++++++++ .../service/impl/TestProxyOKHttpClient.java | 94 +++++++++++++++++++ .../ruoyi/business/service/impl/test2.java | 69 ++++++++++++++ ruoyi-ui/src/views/market/slave/index.vue | 10 +- 5 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/config/ProxyProperties.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/business/service/impl/TestProxyOKHttpClient.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/business/service/impl/test2.java diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 88f5274..be9b2b7 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -136,4 +136,14 @@ tencent: templateId: 2200612 smsSdkAppId: 1400921153 region: ap-beijing - smsUrl: sms.tencentcloudapi.com \ No newline at end of file + smsUrl: sms.tencentcloudapi.com + +clientIP: + proxyAddr: q335.kdltpspro.com + proxyPort: 15818 + account: t12023179565372 + pwd: nffm6c11 + accountSecretId: uadb4a2pwopd613sxr89 + accountsecretKey: 2xib03rq8uqh15x230ea9emjasiu3exv + secretId: o7fnvzz6211s5ymtw3nq + secretKey: qg2ehv53xazqj0fa5zer3dcssoj311ff 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 new file mode 100644 index 0000000..56839b3 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/ProxyProperties.java @@ -0,0 +1,43 @@ +package com.ruoyi.common.config; + +import com.tencentcloudapi.common.Credential; +import com.tencentcloudapi.common.profile.ClientProfile; +import com.tencentcloudapi.common.profile.HttpProfile; +import com.tencentcloudapi.sms.v20210111.SmsClient; +import lombok.Data; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Data +@Configuration +public class ProxyProperties { + +// clientIP: +// proxyAddr: q335.kdltpspro.com +// proxyPort: 15818 +// account: t12023179565372 +// pwd: nffm6c11 +// accountSecretId: uadb4a2pwopd613sxr89 +// accountsecretKey: 2xib03rq8uqh15x230ea9emjasiu3exv +// secretId: o7fnvzz6211s5ymtw3nq +// secretKey: qg2ehv53xazqj0fa5zer3dcssoj311ff + + @Value("${clientIP.proxyAddr}") + private String proxyAddr; + @Value("${clientIP.proxyPort}") + private String proxyPort; + @Value("${clientIP.account}") + private String account; + @Value("${clientIP.pwd}") + private String pwd; + @Value("${clientIP.accountSecretId}") + private String accountSecretId; + @Value("${clientIP.accountsecretKey}") + private String accountsecretKey; + @Value("${clientIP.secretId}") + private String secretId; + @Value("${clientIP.secretKey}") + private String secretKey; + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/TestProxyOKHttpClient.java b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/TestProxyOKHttpClient.java new file mode 100644 index 0000000..7ba450b --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/TestProxyOKHttpClient.java @@ -0,0 +1,94 @@ +package com.ruoyi.business.service.impl; + +import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +public class TestProxyOKHttpClient { + public static void main(String[] args) throws Exception { + String pageUrl = "https://waimaieapp.meituan.com/gw/customer/comment/scores"; // 要访问的目标网页 + String proxyIp = "q335.kdltpspro.com"; // 隧道服务器域名 + int proxyPort = 15818; // 端口号 + // 用户名密码, 若已添加白名单则不需要添加 +// private static String username = "t12023179565372"; +// private static String password = "nffm6c11"; + String ck = "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=dkj01s9yo2h2q99aetsthoq3; acctId=196975850; token=0eq1KL_sB7ri93DJ5E3VcEjEWxjBRjeEsXmkjhWmF3bo*; wmPoiId=21737990; isOfflineSelfOpen=0; city_id=510100; isChain=0; ignore_set_router_proxy=false; region_id=1000510100; region_version=1717637457; bsid=XexDMsEVbmI6WgjNSDW-gwTDf1RtcW1Pkmjt8mV3rmsf3lqyuwluHfeuFrPPZ_2JX9I8z7LBpBdpaBthMwykUw; 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=r97sfva90wzsyia113hr; setPrivacyTime=1_20240706; _lxsdk_s=19085cff3a6-850-391-417%7C%7C182"; + + // JDK 8u111版本后,目标页面为HTTPS协议,启用proxy用户密码鉴权 + System.setProperty("jdk.http.auth.tunneling.disabledSchemes", ""); + + CredentialsProvider credsProvider = new BasicCredentialsProvider(); +// credsProvider.setCredentials(new AuthScope(proxyIp, proxyPort), +// new UsernamePasswordCredentials(null, null)); + CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); + try { + URL url = new URL(pageUrl); + HttpHost target = new HttpHost(url.getHost(), url.getDefaultPort(), url.getProtocol()); + HttpHost proxy = new HttpHost(proxyIp, proxyPort); + + /* + httpclient各个版本设置超时都略有不同, 此处对应版本4.5.6 + setConnectTimeout:设置连接超时时间 + setConnectionRequestTimeout:设置从connect Manager获取Connection 超时时间 + setSocketTimeout:请求获取数据的超时时间 + */ + RequestConfig config = RequestConfig.custom().setProxy(proxy).setConnectTimeout(6000) + .setConnectionRequestTimeout(2000).setSocketTimeout(6000).build(); + URIBuilder uriBuilder = new URIBuilder(); + uriBuilder.setHost(url.getPath()); + Map params = new HashMap<>(); + uriBuilder.setParameter("ignoreSetRouterProxy","true"); + uriBuilder.setParameter("acctId",valueFromCookie("acctId",ck)); + uriBuilder.setParameter("wmPoiId",valueFromCookie("wmPoiId",ck)); + uriBuilder.setParameter("token",valueFromCookie("token",ck)); + uriBuilder.setParameter("appType","3"); + uriBuilder.setParameter("source","1"); +// params.put("acctId",valueFromCookie("acctId",store.getStoreCookie())); +// params.put("wmPoiId",valueFromCookie("wmPoiId",store.getStoreCookie())); +// params.put("token",valueFromCookie("token",store.getStoreCookie())); +// params.put("appType",3); +// params.put("source",1); + + HttpGet httpget = new HttpGet(uriBuilder.build()); + + httpget.setConfig(config); + httpget.addHeader("Accept-Encoding", "gzip"); // 使用gzip压缩传输数据让访问更快 + httpget.addHeader("Connection", "close"); + 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"); + +// String url = "https://waimaieapp.meituan.com/gw/customer/comment/scores"; + + + + 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(); + } + } + + // 解析Cookie + private static String valueFromCookie(String key,String text) { + String s = text.substring(text.indexOf(key), text.length()); + String value = s.substring(s.indexOf("=")+1,s.indexOf(";")); + return value; + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/test2.java b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/test2.java new file mode 100644 index 0000000..97b985b --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/business/service/impl/test2.java @@ -0,0 +1,69 @@ +package com.ruoyi.business.service.impl; + +import okhttp3.*; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Proxy; + +public class test2 { + public static void main(String args[]) throws IOException { + // 目标网站 + String targetUrl = "https://waimaieapp.meituan.com/gw/customer/comment/scores"; + String ck = "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=dkj01s9yo2h2q99aetsthoq3; acctId=196975850; token=0eq1KL_sB7ri93DJ5E3VcEjEWxjBRjeEsXmkjhWmF3bo*; wmPoiId=21737990; isOfflineSelfOpen=0; city_id=510100; isChain=0; ignore_set_router_proxy=false; region_id=1000510100; region_version=1717637457; bsid=XexDMsEVbmI6WgjNSDW-gwTDf1RtcW1Pkmjt8mV3rmsf3lqyuwluHfeuFrPPZ_2JX9I8z7LBpBdpaBthMwykUw; 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=r97sfva90wzsyia113hr; setPrivacyTime=1_20240706; _lxsdk_s=19085cff3a6-850-391-417%7C%7C182"; + + + // 用户名密码, 若已添加白名单则不需要添加 +// final String username = "t12023179565372"; +// final String password = "nffm6c11"; + + String ip = "q335.kdltpspro.com"; // 代理服务器IP + int port = 15818; + + Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(ip, port)); + + Authenticator authenticator = new Authenticator() { + @Override + public Request authenticate(Route route, Response response) throws IOException { +// String credential = Credentials.basic(username, password); + return response.request().newBuilder() +// .header("Proxy-Authorization", credential) + .build(); + } + };// 初始化HTTP请求的URL + HttpUrl.Builder urlBuilder = HttpUrl.parse(targetUrl).newBuilder(); + + // 添加查询参数 + urlBuilder.addQueryParameter("ignoreSetRouterProxy","true"); + urlBuilder.addQueryParameter("acctId",valueFromCookie("acctId",ck)); + urlBuilder.addQueryParameter("wmPoiId",valueFromCookie("wmPoiId",ck)); + urlBuilder.addQueryParameter("token",valueFromCookie("token",ck)); + urlBuilder.addQueryParameter("appType","3"); + urlBuilder.addQueryParameter("source","1"); + + // 构建完整的请求URL + String url = urlBuilder.build().toString(); + + OkHttpClient client = new OkHttpClient.Builder() + .proxy(proxy) + .proxyAuthenticator(authenticator) + .build(); + + Request request = new Request.Builder() + .url(url) + .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36") + .addHeader("Connection","close") + .build(); + + + Response response = client.newCall(request).execute(); + System.out.println(response.body().string()); + + } + + // 解析Cookie + private static String valueFromCookie(String key,String text) { + String s = text.substring(text.indexOf(key), text.length()); + String value = s.substring(s.indexOf("=")+1,s.indexOf(";")); + return value; + } +} diff --git a/ruoyi-ui/src/views/market/slave/index.vue b/ruoyi-ui/src/views/market/slave/index.vue index 20879b1..ed12a5b 100644 --- a/ruoyi-ui/src/views/market/slave/index.vue +++ b/ruoyi-ui/src/views/market/slave/index.vue @@ -17,6 +17,15 @@ + + 新增 + 导出