Browse Source

账户报表调试2

zhaoxian 2 năm trước cách đây
mục cha
commit
61274b3ce9

+ 6 - 6
job-live/src/main/java/cn/com/ctop/job/live/mapper/xml/KuaishouLiveAccountReportDailyMapper.xml

@@ -181,9 +181,9 @@
             #{report.fansT15Roi},
             #{report.fansT30Roi},
             #{report.reportDate},
-            #{report.order_cost},
-            #{report.reco_fans_cost},
-            #{report.conversion_live_event_goods_view_cost}
+            #{report.orderCost},
+            #{report.recoFansCost},
+            #{report.conversionLiveEventGoodsViewCost}
             )
         </foreach>
     </insert>
@@ -369,9 +369,9 @@
             #{report.fansT30Roi},
             #{report.reportDate},
             #{report.hour},
-            #{report.order_cost},
-            #{report.reco_fans_cost},
-            #{report.conversion_live_event_goods_view_cost}
+            #{report.orderCost},
+            #{report.recoFansCost},
+            #{report.conversionLiveEventGoodsViewCost}
             )
         </foreach>
     </insert>

+ 30 - 7
job-live/src/main/java/cn/com/ctop/job/live/service/impl/KuaishouLiveAccountReportDailyServiceImpl.java

@@ -6,12 +6,14 @@ import cn.com.ctop.job.live.service.IKuaishouLiveAccountReportDailyService;
 import cn.com.ctop.job.live.utils.APIUtil;
 import cn.com.ctop.job.live.utils.Check;
 import cn.com.ctop.job.live.utils.DateUtils;
+import cn.com.ctop.job.live.utils.HttpUtil;
 import cn.com.ctop.job.live.utils.KuaishouAPIConstant;
 import cn.com.ctop.job.live.utils.Result;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -30,28 +32,34 @@ import java.util.Map;
 @Service
 public class KuaishouLiveAccountReportDailyServiceImpl implements IKuaishouLiveAccountReportDailyService {
 
+    @Value("${report.start_ip_path}")
+    private String startIpPath;
+
     @Autowired
     private KuaishouLiveAccountReportDailyMapper mapper;
 
     @Override
     public void getKuaishouAccountReport(Long accountId, String token) {
         try {
-            getAccountReport(accountId, token, 1);
+            String yesterday = DateUtils.getSubtractTime(new Date(), 0);
+            long startDate = DateUtils.timeToStamp(yesterday + " 00:00:00");
+            long endDate = DateUtils.timeToStamp(yesterday + " 23:23:59");
+            getAccountReport(accountId, token, startDate, endDate, 1);
+            Thread.sleep(200);
+            sendTips("hourly", accountId, yesterday, yesterday);
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 
-    private void getAccountReport(Long accountId, String token, int pageNum) {
+    private void getAccountReport(Long accountId, String token, long startDate, long endDate, int pageNum) {
         log.info("------getKuaishouAccountReport(获取直播账户日报)---账户:{},---page:{}", accountId, pageNum);
         Result<Object> result = new Result<>();
         Map<String, Object> param = new HashMap<String, Object>();
         param.put("advertiser_id", accountId);
         JSONObject params = new JSONObject();
-        String yesterday = DateUtils.getSubtractTime(new Date(), 0);
-//        String yesterday = "2022-06-14";
-        params.put("start_time", DateUtils.timeToStamp(yesterday + " 00:00:00"));
-        params.put("end_time", DateUtils.timeToStamp(yesterday + " 23:23:59"));
+        params.put("start_time", startDate);
+        params.put("end_time", endDate);
         params.put("view_type", 1);
         params.put("group_type", 1);
         JSONObject pageInfo = new JSONObject();
@@ -75,7 +83,7 @@ public class KuaishouLiveAccountReportDailyServiceImpl implements IKuaishouLiveA
                 mapper.replaceBatch(list);
             }
             if (data.size() == 500) {
-                getAccountReportHour(accountId, token, pageNum + 1);
+                getAccountReport(accountId, token, startDate, endDate, pageNum + 1);
             }
         } else {
             log.error("获取直播账户报表,账户{},{}", accountId, apiResult.toJSONString());
@@ -86,6 +94,9 @@ public class KuaishouLiveAccountReportDailyServiceImpl implements IKuaishouLiveA
     public void getKuaishouAccountHourReport(Long accountId, String token) {
         try {
             getAccountReportHour(accountId, token, 1);
+            Thread.sleep(200);
+            String date = DateUtils.getDate();
+            sendTips("hourly", accountId, date, date);
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -134,4 +145,16 @@ public class KuaishouLiveAccountReportDailyServiceImpl implements IKuaishouLiveA
         }
     }
 
+    //发送提示给宇鹏服务,整理数据
+    private void sendTips(String type, Long accountId, String startDate, String endDate) {
+        /*更新达人数据*/
+        Map<String, Object> param = new HashMap<>();
+        param.put("account_id", accountId);
+        param.put("start_date", startDate.replace("-", ""));
+        param.put("end_date", endDate.replace("-", ""));
+        param.put("date_type", type);
+        Long startTime = System.currentTimeMillis();
+        String url = startIpPath + "webhook/live_account_report";
+        HttpUtil.httpPostRequest(url, param, null);
+    }
 }

+ 962 - 0
job-live/src/main/java/cn/com/ctop/job/live/utils/HttpUtil.java

@@ -0,0 +1,962 @@
+package cn.com.ctop.job.live.utils;
+
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.CookieStore;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.CookieSpecs;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.conn.ssl.TrustStrategy;
+import org.apache.http.cookie.Cookie;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.BasicCookieStore;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.cookie.BasicClientCookie;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.http.util.EntityUtils;
+
+import javax.net.ssl.SSLContext;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+@Slf4j
+public class HttpUtil {
+
+    //发送响应流方法
+    public static void setResponseHeader(HttpServletResponse response, String fileName) {
+        try {
+            fileName = new String(fileName.getBytes(), StandardCharsets.UTF_8);
+            //response.setContentType("application/octet-stream;charset=ISO8859-1");
+            response.setContentType("application/vnd.ms-excel;charset=gb2312");
+
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.addHeader("Pargam", "no-cache");
+            response.addHeader("Cache-Control", "no-cache");
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+    }
+
+    public static JSONObject bytedanceGetRequest(String accessToken, String url, JSONObject params) {
+        // 构造请求
+        HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
+            @Override
+            public String getMethod() {
+                return "GET";
+            }
+        };
+        httpEntity.setHeader("Access-Token", accessToken);
+        CloseableHttpResponse response = null;
+        CloseableHttpClient client = null;
+        try {
+            client = HttpClientBuilder.create().build();
+            httpEntity.setURI(URI.create(url));
+            httpEntity.setEntity(new StringEntity(params.toJSONString(), ContentType.APPLICATION_JSON));
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(12000).setConnectTimeout(12000).build();
+            httpEntity.setConfig(requestConfig);
+            response = client.execute(httpEntity);
+            if (response != null && response.getStatusLine().getStatusCode() == 200) {
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                StringBuilder result = new StringBuilder();
+                String line = "";
+                while ((line = bufferedReader.readLine()) != null) {
+                    result.append(line);
+                }
+                bufferedReader.close();
+                return JSONObject.parseObject(result.toString());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                if (client != null) {
+                    client.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+
+    public static JSONObject bytedancePostRequest(String accessToken, String url, JSONObject params) {
+        // 构造请求
+        HttpPost httpEntity = new HttpPost(url);
+        httpEntity.setHeader("Access-Token", accessToken);
+        CloseableHttpResponse response = null;
+        CloseableHttpClient client = null;
+        try {
+            client = HttpClientBuilder.create().build();
+            httpEntity.setEntity(new StringEntity(params.toJSONString(), ContentType.APPLICATION_JSON));
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(12000).setConnectTimeout(12000).build();
+            httpEntity.setConfig(requestConfig);
+            response = client.execute(httpEntity);
+            if (response != null && response.getStatusLine().getStatusCode() == 200) {
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                StringBuilder result = new StringBuilder();
+                String line = "";
+                while ((line = bufferedReader.readLine()) != null) {
+                    result.append(line);
+                }
+                bufferedReader.close();
+                return JSONObject.parseObject(result.toString());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                if (client != null) {
+                    client.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+
+    public static CookieStore COOKIESTORE = new BasicCookieStore();
+    /**
+     * setProxy(new HttpHost("106.125.239.179", 4245))
+     */
+    public static Map<String, Map<String, String>> fontsMap = new HashMap<>();
+    public static String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36";
+
+    public static CloseableHttpClient createSslClientDefault() {
+        try {
+            SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
+                //信任所有证书
+                @Override
+                public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+                    return true;
+                }
+            }).build();
+            RequestConfig globalConfig = RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(30000).setCookieSpec(CookieSpecs.STANDARD).build();
+            SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(sslContext);
+            return HttpClients.custom().setDefaultCookieStore(COOKIESTORE).setDefaultRequestConfig(globalConfig).setConnectionReuseStrategy((response, context) -> false).setSSLSocketFactory(sslFactory).build();
+        } catch (Exception e) {
+            log.error("处理Https证书异常", e);
+        }
+        return HttpClients.createDefault();
+    }
+
+    public static String httpPostFormRequest(String url, Map<String, Object> param, Map<String, String> headers) {
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        try {
+            HttpPost httppost = new HttpPost(url);
+            if (headers != null) {
+                for (String key : headers.keySet()) {
+                    httppost.setHeader(key, headers.get(key));
+                }
+            }
+            List<NameValuePair> paramList = new ArrayList<NameValuePair>();
+            if (param != null) {
+                for (String key : param.keySet()) {
+                    BasicNameValuePair basicNameValuePair = new BasicNameValuePair(key, String.valueOf(param.get(key)));
+                    paramList.add(basicNameValuePair);
+                }
+                // 第二步:我们发现Entity是一个接口,所以只能找实现类,发现实现类又需要一个集合,集合的泛型是NameValuePair类型
+                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramList);
+                // 第一步:通过setEntity 将我们的entity对象传递过去
+                httppost.setEntity(formEntity);
+            }
+
+            HttpEntity respentity;
+
+            HttpResponse response = httpClient.execute(httppost);
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
+                String newUrl = response.getFirstHeader("Location").getValue();
+                return httpPostFormRequest(newUrl, param, headers);
+            } else if (statusCode == HttpStatus.SC_OK) {
+                respentity = response.getEntity();
+                strReturn = EntityUtils.toString(respentity);
+                return strReturn;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+
+    public static String httpPostParamRequest(String url, Map<String, Object> param, Map<String, String> headers) {
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        try {
+            HttpPost httppost = new HttpPost(url);
+            httppost.setHeader("User-Agent", USER_AGENT);
+            if (headers != null) {
+                for (String key : headers.keySet()) {
+                    httppost.setHeader(key, headers.get(key));
+                }
+            }
+            List<NameValuePair> paramList = new ArrayList<NameValuePair>();
+            for (String key : param.keySet()) {
+                BasicNameValuePair basicNameValuePair = new BasicNameValuePair(key, String.valueOf(param.get(key)));
+                paramList.add(basicNameValuePair);
+            }
+
+            // 第二步:我们发现Entity是一个接口,所以只能找实现类,发现实现类又需要一个集合,集合的泛型是NameValuePair类型
+            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramList);
+            // 第一步:通过setEntity 将我们的entity对象传递过去
+            httppost.setEntity(formEntity);
+            httppost.setEntity(new StringEntity(new Gson().toJson(param), Charset.forName("UTF-8")));
+            HttpEntity respentity;
+
+            HttpResponse response = httpClient.execute(httppost);
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
+                String newUrl = response.getFirstHeader("Location").getValue();
+                return httpPostParamRequest(newUrl, param, headers);
+            } else if (statusCode == HttpStatus.SC_OK) {
+                respentity = response.getEntity();
+                strReturn = EntityUtils.toString(respentity);
+                return strReturn;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+
+    public static String httpPostRequest(String url, Map<String, Object> param, Map<String, String> headers) {
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        try {
+            HttpPost httppost = new HttpPost(url);
+            httppost.setHeader("User-Agent", USER_AGENT);
+            httppost.addHeader("Content-Type", "application/json");
+            if (headers != null && headers.size() > 0) {
+                for (String key : headers.keySet()) {
+                    httppost.setHeader(key, headers.get(key));
+                }
+            }
+            if (param != null && param.size() > 0) {
+                httppost.setEntity(new StringEntity(new Gson().toJson(param), Charset.forName("UTF-8")));
+            }
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(300 * 1000).setConnectTimeout(300 * 1000).build();
+            httppost.setConfig(requestConfig);
+            HttpEntity respentity;
+
+            HttpResponse response = httpClient.execute(httppost);
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
+                String newUrl = response.getFirstHeader("Location").getValue();
+                return httpPostRequest(newUrl, param, headers);
+            } else if (statusCode == HttpStatus.SC_OK) {
+                respentity = response.getEntity();
+                strReturn = EntityUtils.toString(respentity);
+                return strReturn;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+
+    public static String httpPostNoParamRequest(String url) {
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        try {
+            HttpPost httppost = new HttpPost(url);
+            httppost.setHeader("User-Agent", USER_AGENT);
+            httppost.addHeader("Content-Type", "application/json");
+            HttpEntity respentity;
+            HttpResponse response = httpClient.execute(httppost);
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
+                String newUrl = response.getFirstHeader("Location").getValue();
+                return httpPostNoParamRequest(newUrl);
+            } else if (statusCode == HttpStatus.SC_OK) {
+                respentity = response.getEntity();
+                strReturn = EntityUtils.toString(respentity);
+                return strReturn;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+
+
+    public static String httpPostRequestTest(String url, String body, Map<String, String> headers) {
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        try {
+            HttpPost httppost = new HttpPost(url);
+            httppost.setHeader("User-Agent", USER_AGENT);
+            httppost.addHeader("Content-Type", "application/json");
+            if (!Check.isNull(headers)) {
+                for (String key : headers.keySet()) {
+                    httppost.setHeader(key, headers.get(key));
+                }
+            }
+
+            httppost.setEntity(new StringEntity(body, Charset.forName("UTF-8")));
+            HttpEntity respentity;
+
+            HttpResponse response = httpClient.execute(httppost);
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
+                String newUrl = response.getFirstHeader("Location").getValue();
+                return httpPostRequestTest(newUrl, body, headers);
+            } else if (statusCode == HttpStatus.SC_OK) {
+                respentity = response.getEntity();
+                strReturn = EntityUtils.toString(respentity);
+                return strReturn;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+
+
+    public static String kuaiShouhttpPostRequest(String url, String body, Map<String, String> headers) {
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        try {
+            HttpPost httppost = new HttpPost(url);
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(120000).setConnectTimeout(120000).build();
+            httppost.setConfig(requestConfig);
+            if (!Check.isNullMap(headers)) {
+                for (String key : headers.keySet()) {
+                    httppost.setHeader(key, headers.get(key));
+                }
+            }
+
+            httppost.setHeader("User-Agent", USER_AGENT);
+            if (!Check.isNull(body)) {
+                httppost.setEntity(new StringEntity(body, Charset.forName("UTF-8")));
+            }
+            HttpEntity respentity;
+            HttpResponse response = httpClient.execute(httppost);
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode == HttpStatus.SC_OK) {
+                respentity = response.getEntity();
+                strReturn = EntityUtils.toString(respentity);
+                return strReturn;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+
+
+    public static String httpPostRequest(String url, JSONObject params, Map<String, String> headers) {
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        try {
+            HttpPost httppost = new HttpPost(url);
+            httppost.setHeader("User-Agent", USER_AGENT);
+            httppost.addHeader("Content-Type", "application/json");
+            for (String key : headers.keySet()) {
+                httppost.setHeader(key, headers.get(key));
+            }
+            httppost.setEntity(new StringEntity(params.toJSONString(), Charset.forName("UTF-8")));
+            HttpEntity respentity;
+
+            HttpResponse response = httpClient.execute(httppost);
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
+                String newUrl = response.getFirstHeader("Location").getValue();
+                return httpPostRequest(newUrl, params, headers);
+            } else if (statusCode == HttpStatus.SC_OK) {
+                respentity = response.getEntity();
+                strReturn = EntityUtils.toString(respentity);
+                return strReturn;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+
+    public static String postKuaishouVideoUrl(String url, String uid, String photoId) {
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        String paramBody = "{\"operationName\":\"FeedQuery\",\"variables\":{\"principalId\":\"" + uid + "\",\"photoId\":\"" + photoId + "\"},\"query\":\"query FeedQuery($principalId: String, $photoId: String) {\\n  feedById(principalId: $principalId, photoId: $photoId) {\\n    currentWork {\\n                 timestamp\\n           __typename\\n    }\\n       __typename\\n  }\\n}\\n\"}";
+        try {
+            HttpPost httppost = new HttpPost(url);
+            httppost.setHeader("User-Agent", USER_AGENT);
+            httppost.addHeader("Content-Type", "application/json");
+//            for (String key : headers.keySet()) {
+//                httppost.setHeader(key, headers.get(key));
+//            }
+            httppost.setEntity(new StringEntity(paramBody, Charset.forName("UTF-8")));
+            HttpEntity respentity;
+
+            HttpResponse response = httpClient.execute(httppost);
+            int statusCode = response.getStatusLine().getStatusCode();
+
+            respentity = response.getEntity();
+            strReturn = EntityUtils.toString(respentity);
+            return strReturn;
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+
+    public static String getKuaishouShareUrl(String url) {
+        HttpClient httpClient = HttpClientBuilder.create().build();
+        HttpResponse response = null;
+        HttpGet httpGet = new HttpGet(url);
+        httpGet.setConfig(RequestConfig.custom().setRedirectsEnabled(false).build());
+        String result = null;
+        try {
+            httpGet.setHeader("User-Agent", USER_AGENT);
+            httpGet.setHeader("Accept-Encoding", "gzip, deflate, br");
+            httpGet.setHeader("Connection", "keep-alive");
+            httpGet.setHeader("Host", "yongzhou.s.gifshow.com");
+            httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
+            httpGet.setHeader("Upgrade-Insecure-Requests", "1");
+            httpGet.setHeader("Accept-Language", "zh-CN,zh;q=0.9");
+            response = httpClient.execute(httpGet);
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
+                String newUrl = response.getFirstHeader("Location").getValue();
+                return newUrl;
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    public static String httpGetRequest(String url) {
+        HttpClient httpClient = createSslClientDefault();
+        HttpResponse response = null;
+        HttpGet httpGet = new HttpGet(url);
+        String result = null;
+        try {
+            httpGet.setHeader("User-Agent", USER_AGENT);
+            response = httpClient.execute(httpGet);
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
+                String newUrl = response.getFirstHeader("Location").getValue();
+                return httpGetRequest(newUrl);
+            } else if (statusCode == HttpStatus.SC_OK) {
+                BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                String line = null;
+                StringBuilder builder = new StringBuilder();
+                while ((line = reader.readLine()) != null) {
+                    builder.append(line);
+                }
+                result = builder.toString();
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    public static String httpRequest(String url, String strParams) throws Exception {
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        try {
+
+            HttpPost httppost = new HttpPost(url);
+            httppost.addHeader("Content-Type", "application/json");
+            httppost.setEntity(new StringEntity(strParams, Charset.forName("UTF-8")));
+            HttpEntity respentity;
+            HttpResponse response = httpClient.execute(httppost);
+            respentity = response.getEntity();
+            strReturn = EntityUtils.toString(respentity);
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+
+    public static String httpRequest(String url, CookieStore cookies, Map<String, String> parameterMap) throws Exception {
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        try {
+            HttpPost httppost = new HttpPost(url);
+            httppost.setHeader("Content-Type", "application/json");
+            UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(
+                    getParam(parameterMap), "UTF-8");
+            httppost.setEntity(postEntity);
+            HttpEntity respentity;
+            HttpResponse response = httpClient.execute(httppost);
+            respentity = response.getEntity();
+            strReturn = EntityUtils.toString(respentity);
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+
+    public static List<NameValuePair> getParam(Map parameterMap) {
+        List<NameValuePair> param = new ArrayList<>();
+        Iterator it = parameterMap.entrySet().iterator();
+        while (it.hasNext()) {
+            Map.Entry parmEntry = (Map.Entry) it.next();
+            param.add(new BasicNameValuePair((String) parmEntry.getKey(),
+                    (String) parmEntry.getValue()));
+        }
+        return param;
+    }
+
+    public static HttpClient getHttpclient() {
+        RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(180000).setConnectTimeout(30000)
+                .setConnectionRequestTimeout(30000).setStaleConnectionCheckEnabled(true).build();
+        CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
+        return httpclient;
+    }
+
+    public static String callingGraph(String url, String json) {
+        HttpClient httpClient = createSslClientDefault();
+        HttpResponse response = null;
+        HttpPost httpPost = new HttpPost(url);
+        List<Cookie> list = COOKIESTORE.getCookies();
+        httpPost.setHeader("Content-Type", "application/json");
+        String result = null;
+
+        try {
+            StringEntity entity = new StringEntity(json, "utf-8");
+            httpPost.setHeader("User-Agent", USER_AGENT);
+            httpPost.setEntity(entity);
+            response = httpClient.execute(httpPost);
+            BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+            String line = null;
+            StringBuilder builder = new StringBuilder();
+            while ((line = reader.readLine()) != null) {
+                builder.append(line);
+            }
+            result = builder.toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    public static Map<String, Integer> KUAISHOUNUMBERMAP;
+
+    public static Integer getKuaishouNumber(String key) {
+        if (KUAISHOUNUMBERMAP == null) {
+            KUAISHOUNUMBERMAP = new HashMap<>();
+//            kuaishouNumberMap.put("32.0#-6.0#526.0#729.0",0);//735
+//            kuaishouNumberMap.put("98.0#13.0#363.0#726.0",1);//713
+//            kuaishouNumberMap.put("32.0#13.0#527.0#732.0",2);//719
+//            kuaishouNumberMap.put("25.0#-6.0#525.0#730.0",3);//736
+//            kuaishouNumberMap.put("26.0#13.0#536.0#731.0",4);//718
+//            kuaishouNumberMap.put("33.0#-5.0#526.0#717.0",5);//722
+//            kuaishouNumberMap.put("39.0#-5.0#530.0#732.0",6);//737
+//            kuaishouNumberMap.put("38.0#13.0#536.0#717.0",7);//704
+//            kuaishouNumberMap.put("33.0#-7.0#525.0#731.0",8);//738
+//            kuaishouNumberMap.put("37.0#-7.0#521.0#730.0",9);//737
+            KUAISHOUNUMBERMAP.put("494.0#735.0", 0);
+            KUAISHOUNUMBERMAP.put("265.0#713.0", 1);
+            KUAISHOUNUMBERMAP.put("495.0#719.0", 2);
+            KUAISHOUNUMBERMAP.put("500.0#736.0", 3);
+            KUAISHOUNUMBERMAP.put("510.0#718.0", 4);
+            KUAISHOUNUMBERMAP.put("493.0#722.0", 5);
+            KUAISHOUNUMBERMAP.put("491.0#737.0", 6);
+            KUAISHOUNUMBERMAP.put("498.0#704.0", 7);
+            KUAISHOUNUMBERMAP.put("492.0#738.0", 8);
+            KUAISHOUNUMBERMAP.put("484.0#737.0", 9);
+        }
+        return KUAISHOUNUMBERMAP.get(key);
+    }
+
+
+    public static String mapParamsSortToStringBySeperator(TreeMap<String, Object> treeMap, String seperator) {
+        String result = "";
+        if (null != treeMap && !treeMap.isEmpty()) {
+            for (Map.Entry<String, Object> entry : treeMap.entrySet()) {
+                String key = entry.getKey();
+                String value = entry.getValue().toString();
+                result += (key + "=" + value + seperator);
+            }
+            result = result.substring(0, result.length() - seperator.length());
+        }
+        return result;
+    }
+
+    public static String httpGetRequest(String url, Map<String, String> headers, TreeMap<String, Object> params) {
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        try {
+            String uri = url + "?" + mapParamsSortToStringBySeperator(params, "&");
+            HttpGet httpGet = new HttpGet(uri);
+            if (headers != null) {
+                Iterator<String> keyIter = headers.keySet().iterator();
+                while (keyIter.hasNext()) {
+                    String curKey = keyIter.next();
+                    if (curKey != null && headers.get(curKey) != null) {
+                        httpGet.addHeader(curKey, headers.get(curKey));
+                    }
+                }
+            }
+            HttpEntity respentity;
+            HttpResponse response = httpClient.execute(httpGet);
+            respentity = response.getEntity();
+            strReturn = EntityUtils.toString(respentity);
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+
+    public static String httpGetRequest(String url, Map<String, String> headers, JSONObject params) {
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        try {
+            HttpGetWithBodyEntity httpGet = new HttpGetWithBodyEntity(url);
+            if (headers != null) {
+                Iterator<String> keyIter = headers.keySet().iterator();
+                while (keyIter.hasNext()) {
+                    String curKey = keyIter.next();
+                    if (curKey != null && headers.get(curKey) != null) {
+                        httpGet.addHeader(curKey, headers.get(curKey));
+                    }
+                }
+            }
+            httpGet.setEntity(new StringEntity(params.toJSONString(), Charset.forName("UTF-8")));
+            HttpEntity respentity;
+            HttpResponse response = httpClient.execute(httpGet);
+            respentity = response.getEntity();
+            strReturn = EntityUtils.toString(respentity);
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+
+
+    public static String httpGet(String url, Map<String, Object> paramsMap, Map<String, String> headers) {
+        String result = null;
+        try {
+            //创建参数列表
+            HttpClient httpclient = getHttpclient();
+            StringBuilder postBody = null;
+            if (!Check.isNull(paramsMap)) {
+                postBody = new StringBuilder();
+                for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
+                    if (entry.getValue() == null) {
+                        continue;
+                    }
+                    postBody.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue().toString(),
+                            "utf-8")).append("&");
+                }
+                if (!paramsMap.isEmpty()) {
+                    postBody.deleteCharAt(postBody.length() - 1);
+                }
+            }
+            String urlStr;
+            if (!Check.isNull(postBody)) {
+                urlStr = url + "?" + postBody;
+            } else {
+                urlStr = url;
+            }
+            HttpGet httpget = new HttpGet(urlStr);
+//            httpget.setHeader("User-Agent", USER_AGENT);
+            if (!Check.isNullMap(headers)) {
+                for (String key : headers.keySet()) {
+                    httpget.setHeader(key, headers.get(key));
+                }
+            }
+            HttpEntity respEntity;
+            HttpResponse response = httpclient.execute(httpget);
+            respEntity = response.getEntity();
+            Header[] responseHeaders = response.getHeaders("Set-Cookie");
+            if (responseHeaders != null) {
+
+                for (Header header : responseHeaders) {
+                    String[] ckArray = header.getValue().split(";");
+                    BasicClientCookie ck = new BasicClientCookie(ckArray[0].split("=")[0], ckArray[0].split("=")[1]);
+                    ck.setPath(ckArray[1].split("=")[1]);
+                    ck.setDomain(ckArray[2].split("=")[1]);
+                    HttpUtil.COOKIESTORE.addCookie(ck);
+                }
+            }
+            result = EntityUtils.toString(respEntity);
+        } catch (Exception e) {
+            log.error("http get请求异常");
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+
+    public static JSONObject kuaiShouHttpGetRequest(String accessToken, String url, JSONObject params) {
+        // 构造请求
+        HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
+            @Override
+            public String getMethod() {
+                return "GET";
+            }
+        };
+        httpEntity.setHeader("Access-Token", accessToken);
+        CloseableHttpResponse response = null;
+        CloseableHttpClient client = null;
+        try {
+            client = HttpClientBuilder.create().build();
+            httpEntity.setURI(URI.create(url));
+            httpEntity.setEntity(new StringEntity(params.toJSONString(), ContentType.APPLICATION_JSON));
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(12000).setConnectTimeout(12000).build();
+            httpEntity.setConfig(requestConfig);
+            response = client.execute(httpEntity);
+            if (response != null && response.getStatusLine().getStatusCode() == 200) {
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                StringBuilder result = new StringBuilder();
+                String line = "";
+                while ((line = bufferedReader.readLine()) != null) {
+                    result.append(line);
+                }
+                bufferedReader.close();
+                return JSONObject.parseObject(result.toString());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                if (client != null) {
+                    client.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+
+
+    public static String KuaiShouttpGetRequest(String url, Map<String, Object> params, Map<String, String> headers) throws Exception {
+        HttpClient httpclient = getHttpclient();
+        String strReturn = "";
+        try {
+
+
+            StringBuilder postBody = new StringBuilder();
+            for (Map.Entry<String, Object> entry : params.entrySet()) {
+                if (entry.getValue() == null) {
+                    continue;
+                }
+                postBody.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue().toString(),
+                        "utf-8")).append("&");
+            }
+            if (!params.isEmpty()) {
+                postBody.deleteCharAt(postBody.length() - 1);
+            }
+
+            HttpGet httpget = new HttpGet(url + "?" + postBody);
+            if (headers != null) {
+                Iterator<String> keyIter = headers.keySet().iterator();
+                while (keyIter.hasNext()) {
+                    String curKey = keyIter.next();
+                    if (curKey != null && headers.get(curKey) != null) {
+                        httpget.addHeader(curKey, headers.get(curKey));
+                    }
+                }
+            }
+            HttpEntity respentity;
+            HttpResponse response = httpclient.execute(httpget);
+            respentity = response.getEntity();
+            strReturn = EntityUtils.toString(respentity);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return strReturn;
+    }
+
+    public static JSONObject feishuGetRequest(String url, JSONObject params) {
+        return feishuGetRequest(null, url, params);
+    }
+
+    public static JSONObject feishuPostRequest(String url, JSONObject params) {
+        return feishuPostRequest(null, url, params);
+    }
+
+    public static String feishuGetRequestString(String url) {
+        // 构造请求
+        HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
+            @Override
+            public String getMethod() {
+                return "GET";
+            }
+        };
+        CloseableHttpResponse response = null;
+        CloseableHttpClient client = null;
+        try {
+            client = HttpClientBuilder.create().build();
+            httpEntity.setURI(URI.create(url));
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(12000).setConnectTimeout(12000).build();
+            httpEntity.setConfig(requestConfig);
+            response = client.execute(httpEntity);
+            if (response != null && response.getStatusLine().getStatusCode() == 200) {
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                StringBuilder result = new StringBuilder();
+                String line = "";
+                while ((line = bufferedReader.readLine()) != null) {
+                    result.append(line);
+                }
+                bufferedReader.close();
+                return result.toString();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                if (client != null) {
+                    client.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+
+    public static JSONObject feishuGetRequest(String accessToken, String url, JSONObject params) {
+        // 构造请求
+        HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
+            @Override
+            public String getMethod() {
+                return "GET";
+            }
+        };
+        if (accessToken != null) {
+            httpEntity.setHeader("Authorization", accessToken);
+        }
+        CloseableHttpResponse response = null;
+        CloseableHttpClient client = null;
+        try {
+            client = HttpClientBuilder.create().build();
+            httpEntity.setURI(URI.create(url));
+            if (params != null) {
+                httpEntity.setEntity(new StringEntity(params.toJSONString(), ContentType.APPLICATION_JSON));
+            }
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(12000).setConnectTimeout(12000).build();
+            httpEntity.setConfig(requestConfig);
+            response = client.execute(httpEntity);
+            if (response != null && response.getStatusLine().getStatusCode() == 200) {
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                StringBuilder result = new StringBuilder();
+                String line = "";
+                while ((line = bufferedReader.readLine()) != null) {
+                    result.append(line);
+                }
+                bufferedReader.close();
+                return JSONObject.parseObject(result.toString());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                if (client != null) {
+                    client.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+
+
+    public static JSONObject feishuPostRequest(String accessToken, String url, JSONObject params) {
+        // 构造请求
+        HttpPost httpEntity = new HttpPost(url);
+        if (accessToken != null) {
+            httpEntity.setHeader("Authorization", accessToken);
+        }
+        CloseableHttpResponse response = null;
+        CloseableHttpClient client = null;
+        try {
+            client = HttpClientBuilder.create().build();
+            httpEntity.setEntity(new StringEntity(params.toJSONString(), ContentType.APPLICATION_JSON));
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(12000).setConnectTimeout(12000).build();
+            httpEntity.setConfig(requestConfig);
+            response = client.execute(httpEntity);
+            if (response != null && response.getStatusLine().getStatusCode() == 200) {
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                StringBuilder result = new StringBuilder();
+                String line = "";
+                while ((line = bufferedReader.readLine()) != null) {
+                    result.append(line);
+                }
+                bufferedReader.close();
+                return JSONObject.parseObject(result.toString());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                if (client != null) {
+                    client.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+}

+ 3 - 1
job-live/src/main/resources/application.yml

@@ -120,5 +120,7 @@ api:
   kuaishou:
     postUrl: https://ad.e.kuaishou.com
 
-
+report:
+  #启动宇鹏整理数据的服务IP
+  start_ip_path: http://192.168.0.203:3456/