1; 集成私密代理方法配置 引入待测

This commit is contained in:
wangshuai 2024-07-30 00:42:19 +08:00
parent 0c03f69473
commit e3af04aa1f
3 changed files with 96 additions and 55 deletions

View File

@ -127,7 +127,7 @@ public class MeituanController {
@ApiOperation("getMtgsig")
@GetMapping("/getMtgsig")
public String mtgsig(String orderId,String regionId,String regionVersion,String dfpid) {
return iMeituanService.mtgsigInfo(orderId,regionId,regionVersion,dfpid);
return iMeituanService.mtgsigInfo(null,orderId,regionId,regionVersion,dfpid);
}

View File

@ -113,7 +113,7 @@ public class ProxyProperties {
String code = jsonObject.getString(("code"));
if ("0".equals(code)) {
int count = jsonObject.getJSONObject("data").getInteger(proxy);
if (count > 600) {
if (count > 400) {
System.out.println("剩余:"+count);
return true;
}

View File

@ -35,6 +35,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
@ -106,7 +107,7 @@ public class MeituanServiceImpl implements IMeituanService {
if(list1.size() == 0){
return "授权失败,代理账号不存在!";
}
String getUrl = proxyProperties.getUrl();
String getUrl = null;
Date date = new Date();
if (list.size() == 0) {
storeInfo.setBindId(list1.get(0).getId());
@ -285,7 +286,7 @@ public class MeituanServiceImpl implements IMeituanService {
*/
public boolean yesterdayCountOne(BusStoreInfo storeInfo){
CloseableHttpClient httpClient = proxyHttpClient(proxyProperties.getUrl());
CloseableHttpClient httpClient = proxyHttpClient();
String wmPoiId = valueFromCookie("wmPoiId", storeInfo.getStoreCookie());
String url = "https://waimaieapp.meituan.com/gw/bizdata/single/business/overview";
Map<String, Object> params = new HashMap<>();
@ -359,7 +360,7 @@ public class MeituanServiceImpl implements IMeituanService {
public R orderInfo(String wmPoiId, String date, String cookie) { //根据date,查询前一天的key,如果有则删除
int pageNum = 1;
String getUrl = proxyProperties.getUrl();
String getUrl = null;
JSONObject jsonObject = merchantOrders(getUrl,pageNum, date, cookie);
String code = jsonObject.getString("code");
if ("0".equals(code)) {
@ -507,7 +508,7 @@ public class MeituanServiceImpl implements IMeituanService {
}
private String getOrderCountByType(String getUrl, String wmOrderViewId,String cookie){
CloseableHttpClient httpClient = proxyHttpClient(getUrl);
CloseableHttpClient httpClient = proxyHttpClient();
String url = "https://e.waimai.meituan.com/gw/phf/v2/order/receive/processed/r/orderAsyncInfos/v3";
Map<String, Object> params = new HashMap<>();
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(getUrl);
CloseableHttpClient client = proxyHttpClient();
// CloseableHttpClient client = HttpClientBuilder.create().build();
HttpEntity responseEntity;
String resp = null;
@ -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(getUrl);
CloseableHttpClient client = proxyHttpClient();
String result = null;
try {
result = EntityUtils.toString(client.execute(request).getEntity());
@ -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(getUrl);
CloseableHttpClient client = proxyHttpClient();
String result = null;
try {
result = EntityUtils.toString(client.execute(request).getEntity());
@ -687,7 +688,7 @@ public class MeituanServiceImpl implements IMeituanService {
httpPost.setEntity(entity);
httpPost.setHeader("Cookie", cookie);
CloseableHttpClient client = proxyHttpClient(getUrl);
CloseableHttpClient client = proxyHttpClient();
String code = null;
JSONObject jsonObject = new JSONObject();
@ -747,42 +748,81 @@ public class MeituanServiceImpl implements IMeituanService {
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public String mtgsigInfo(String getUrl, String orderId, String regionId, String regionVersion,String dfpid) {
CloseableHttpClient httpClient = proxyHttpClient(getUrl);
CloseableHttpClient httpClient = proxyHttpClient();
String url = "http://43.140.224.18:12000/get_mtgsig";
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setHeader("Content-Type", "application/json");
Map<String, Object> subUrlParams = new LinkedHashMap<>();
subUrlParams.put("url", "https://e.waimai.meituan.com/v2/order/history/r/search/ajax?");
// subUrlParams.put("url", "https://e.waimai.meituan.com/v2/order/history/r/search/ajax?");
// subUrlParams.put("searchItem", orderId);
// subUrlParams.put("region_id", regionId);
// subUrlParams.put("region_version", regionVersion);
// subUrlParams.put("yodaReady", "h5");
// subUrlParams.put("csecplatform", 4);
// subUrlParams.put("csecversion", "2.4.0");
JSONObject jsonObject = new JSONObject();
jsonObject.put("url","https://e.waimai.meituan.com/v2/order/history/r/search/ajax?searchItem="+orderId+"&region_id="+regionId+"&region_version="+regionVersion+"&yodaReady=h5&csecplatform=4&csecversion=2.4.0");
jsonObject.put("data","");
jsonObject.put("dfpid",dfpid);
jsonObject.put("method","post");
StringEntity entity = new StringEntity(JSONObject.toJSONString(jsonObject), "utf-8");
subUrlParams.put("data", "");
subUrlParams.put("dfpid", dfpid.split("-")[0]);
subUrlParams.put("method", "post");
String urlParam = "";
for (Map.Entry<String, Object> stringObjectEntry : subUrlParams.entrySet()) {
urlParam = urlParam + stringObjectEntry.getKey() + "=" + stringObjectEntry.getValue() + "&";
}
// subUrlParams.put("data", "");
// subUrlParams.put("dfpid", dfpid.split("-")[0]);
// subUrlParams.put("method", "post");
//
// String urlParam = "";
// for (Map.Entry<String, Object> stringObjectEntry : subUrlParams.entrySet()) {
// urlParam = urlParam + stringObjectEntry.getKey() + "=" + stringObjectEntry.getValue() + "&";
// }
String result = null;
try {
StringEntity params = new StringEntity(urlParam.substring(0, urlParam.length() - 1));
httpPost.setEntity(params);
// StringEntity params = new StringEntity(urlParam.substring(0, urlParam.length() - 1));
httpPost.setEntity(entity);
CloseableHttpResponse response = httpClient.execute(httpPost);
result = EntityUtils.toString(response.getEntity());
result = URLEncoder.encode(result,"utf-8")
.replace("+", "%20")
.replace("%21", "!")
.replace("%27", "'")
.replace("%28", "(")
.replace("%29", ")")
.replace("%7E", "~");
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
return URLEncoder.encode(result);
}
return result;
}
// public static void main(String[] args) throws Exception {
// String s = "{\n" +
// "\"a1\": \"1.1\",\n" +
// "\"a2\": 1722262786240,\n" +
// "\"a3\": \"1719555287467YYKUWIAfd79fef3d01d5e9aadc18ccd4d0c95077155\",\n" +
// "\"a5\": \"Hb6DmbOppfh+9/IyVMq4\",\n" +
// "\"a6\": \"hs1.4aOG4x69iuIGtADfqn9IKcXWfqxcu6RKBEt0ULtKkr0Pxmrai6YXTRjzK6Sg7d16jqhHlzuHMnrjVQt4PthJFNw==\",\n" +
// "\"x0\": 4,\n" +
// "\"d1\": \"9cff2c0335b0bb892a1bd01fa94f978f\"\n" +
// "}";
// String ss = URLEncoder.encode(s,"utf-8")
// .replace("+", "%20")
// .replace("%21", "!")
// .replace("%27", "'")
// .replace("%28", "(")
// .replace("%29", ")")
// .replace("%7E", "~");
// System.out.println(ss);
// }
@Override
public void getReturnInfo(Long id) {
getComments(null);
@ -850,7 +890,7 @@ public class MeituanServiceImpl implements IMeituanService {
*/
@Transactional(rollbackFor = Exception.class)
public Boolean getScoreOne(BusStoreInfo store) {
CloseableHttpClient httpClient = proxyHttpClient(proxyProperties.getUrl());
CloseableHttpClient httpClient = proxyHttpClient();
String wmPoiId = valueFromCookie("wmPoiId", store.getStoreCookie());
String url = "https://waimaieapp.meituan.com/gw/customer/comment/scores";
Map<String, Object> params = new HashMap<>();
@ -930,7 +970,7 @@ public class MeituanServiceImpl implements IMeituanService {
request.setHeader("Cookie",store.getStoreCookie());
String result = null;
try {
CloseableHttpClient httpClient = proxyHttpClient(proxyProperties.getUrl());
CloseableHttpClient httpClient = proxyHttpClient();
result = EntityUtils.toString(httpClient.execute(request).getEntity());
if (StringUtils.isEmpty(result)) {
System.out.println(result);
@ -982,37 +1022,38 @@ public class MeituanServiceImpl implements IMeituanService {
return url;
}
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;
private CloseableHttpClient proxyHttpClient() {
// 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(ip, port),
new UsernamePasswordCredentials(proxyProperties.getAccountSM(), proxyProperties.getPwdSM()));
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).setDefaultRequestConfig(config).build();
return httpclient;
// 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(ip, port),
// new UsernamePasswordCredentials(proxyProperties.getAccountSM(), proxyProperties.getPwdSM()));
// RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
// 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());