Browse Source

完善代理池错误处理

xuzuoyun 5 years ago
parent
commit
3954af5620
17 changed files with 398 additions and 215 deletions
  1. 4 2
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/IpPoolServiceImpl.java
  2. 125 149
      module-common/src/main/java/cn/com/ctop/common/module/utils/HttpClientUtils.java
  3. 25 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/controller/KuaishouWebController.java
  4. 16 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/entity/KuaishouCommentConfig.java
  5. 18 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/entity/KuaishouCommentKeyword.java
  6. 15 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/entity/KuaishouCommentStat.java
  7. 84 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/job/KuaishouCommentDayJob.java
  8. 7 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/mapper/KuaishouCommentConfigMapper.java
  9. 7 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/mapper/KuaishouCommentKeywordMapper.java
  10. 7 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/mapper/KuaishouCommentStatMapper.java
  11. 7 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/IKuaishouCommentConfigService.java
  12. 7 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/IKuaishouCommentKeywordService.java
  13. 7 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/IKuaishouCommentStatService.java
  14. 11 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/impl/KuaishouCommentConfigServiceImpl.java
  15. 11 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/impl/KuaishouCommentKeywordServiceImpl.java
  16. 11 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/impl/KuaishouCommentStatServiceImpl.java
  17. 36 62
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/impl/KuaishouWebInterfaceServiceImpl.java

+ 4 - 2
module-common/src/main/java/cn/com/ctop/common/module/service/impl/IpPoolServiceImpl.java

@@ -38,10 +38,12 @@ public class IpPoolServiceImpl extends ServiceImpl<IpPoolMapper, IpPool> impleme
     private void syncIpPool() {
         HttpClientUtils httpClientUtils = new HttpClientUtils();
         try {
-            String result = httpClientUtils.get("http://d.jghttp.golangapi.com/getip?num=10&type=2&pro=&city=0&yys=0&port=11&pack=14503&ts=1&ys=1&cs=1&lb=1&sb=0&pb=45&mr=2&regions=");
+//            String result = httpClientUtils.get("http://d.jghttp.golangapi.com/getip?num=10&type=2&pro=&city=0&yys=0&port=11&pack=14503&ts=1&ys=1&cs=1&lb=1&sb=0&pb=45&mr=2&regions=");
+//            String result = httpClientUtils.get("http://webapi.http.zhimacangku.com/getip?num=10&type=2&pro=&city=0&yys=0&port=11&time=1&ts=1&ys=1&cs=1&lb=1&sb=0&pb=45&mr=2&regions=");
+            String result = httpClientUtils.get("http://api.qingtingip.com/ip?app_key=31f9e03d6c362cb926d6c5d911e01387&num=10&ptc=http&fmt=json&lb=\\r\\n&port=0&mr=2&");
             ObjectMapper mapper = new ObjectMapper();
             JsonNode jsonNode = mapper.readTree(result);
-            if (jsonNode.get("code").asInt() == 0) {
+            if (jsonNode.get("code").asInt() == 200) {
                 List<IpPool> ipList = JSON.parseObject(jsonNode.get("data").toString(), new TypeReference<List<IpPool>>() {
                 });
                 if (ipList != null && ipList.size() > 0) {

+ 125 - 149
module-common/src/main/java/cn/com/ctop/common/module/utils/HttpClientUtils.java

@@ -27,6 +27,7 @@ import org.apache.http.message.BasicNameValuePair;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.ssl.SSLContextBuilder;
 import org.apache.http.util.EntityUtils;
+import org.springframework.stereotype.Component;
 
 import javax.net.ssl.SSLContext;
 import java.io.BufferedReader;
@@ -113,142 +114,131 @@ public class HttpClientUtils {
         return sb.toString();
     }
 
-    public HttpClientEntity httpGetRequest(HttpClientEntity httpClientEntity) {
+    public HttpClientEntity httpGetRequest(HttpClientEntity httpClientEntity) throws Exception {
         String result = null;
-        try {
-            CookieStore cs = httpClientEntity.getCookieStore();
-            if (cs != null) {
-                for (Cookie ck : cs.getCookies()) {
-                    cookieStore.addCookie(ck);
-                }
+        CookieStore cs = httpClientEntity.getCookieStore();
+        if (cs != null) {
+            for (Cookie ck : cs.getCookies()) {
+                cookieStore.addCookie(ck);
             }
-            HttpResponse response = null;
-            HttpGet httpGet = new HttpGet(httpClientEntity.getUrl());
+        }
+        HttpResponse response = null;
+        HttpGet httpGet = new HttpGet(httpClientEntity.getUrl());
 
-            CloseableHttpClient httpClient = httpClientEntity.getCloseableHttpClient();
-            response = httpClient.execute(httpGet);
-            Header[] headers = response.getHeaders("Set-Cookie");
-            if (headers != null && headers.length > 0) {
-                for (Header header : headers) {
-                    String[] cookieArr = header.getValue().split(";");
-                    String[] ck = cookieArr[0].split("=");
-                    BasicClientCookie basicClientCookie = new BasicClientCookie(ck[0], ck[1]);
-                    Map<String, String> cookieMap = new HashMap<>();
-                    if (cookieArr.length > 1) {
-                        for (int i = 1; i < cookieArr.length; i++) {
-                            String[] ckParam = cookieArr[i].split("=");
-                            if (ckParam.length > 1) {
-                                cookieMap.put(ckParam[0].trim(), ckParam[1]);
-                            }
+        CloseableHttpClient httpClient = httpClientEntity.getCloseableHttpClient();
+        response = httpClient.execute(httpGet);
+        Header[] headers = response.getHeaders("Set-Cookie");
+        if (headers != null && headers.length > 0) {
+            for (Header header : headers) {
+                String[] cookieArr = header.getValue().split(";");
+                String[] ck = cookieArr[0].split("=");
+                BasicClientCookie basicClientCookie = new BasicClientCookie(ck[0], ck[1]);
+                Map<String, String> cookieMap = new HashMap<>();
+                if (cookieArr.length > 1) {
+                    for (int i = 1; i < cookieArr.length; i++) {
+                        String[] ckParam = cookieArr[i].split("=");
+                        if (ckParam.length > 1) {
+                            cookieMap.put(ckParam[0].trim(), ckParam[1]);
                         }
                     }
+                }
 
-                    basicClientCookie.setPath(cookieMap.get("Path"));
-                    if (cookieMap.get("Domain") == null || cookieMap.get("Domain").equals("")) {
-                        if (httpClientEntity.getHeaders() != null && httpClientEntity.getHeaders().get("Origin") != null) {
-                            basicClientCookie.setDomain(httpClientEntity.getHeaders().get("Origin").split("//")[1]);
-                        }
-                    } else {
-                        basicClientCookie.setDomain(cookieMap.get("Domain"));
+                basicClientCookie.setPath(cookieMap.get("Path"));
+                if (cookieMap.get("Domain") == null || cookieMap.get("Domain").equals("")) {
+                    if (httpClientEntity.getHeaders() != null && httpClientEntity.getHeaders().get("Origin") != null) {
+                        basicClientCookie.setDomain(httpClientEntity.getHeaders().get("Origin").split("//")[1]);
                     }
-                    basicClientCookie.setExpiryDate(new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 365));
-                    cookieStore.addCookie(basicClientCookie);
+                } else {
+                    basicClientCookie.setDomain(cookieMap.get("Domain"));
                 }
+                basicClientCookie.setExpiryDate(new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 365));
+                cookieStore.addCookie(basicClientCookie);
             }
-            int statusCode = response.getStatusLine().getStatusCode();
-            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
-                String newUrl = response.getFirstHeader("Location").getValue();
-                httpClientEntity.setUrl(newUrl);
-                return httpGetRequest(httpClientEntity);
-            } 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();
-            }
-            log.info(httpClientEntity.getResult());
-        } catch (Exception e) {
-            e.printStackTrace();
+        }
+        int statusCode = response.getStatusLine().getStatusCode();
+        if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
+            String newUrl = response.getFirstHeader("Location").getValue();
+            httpClientEntity.setUrl(newUrl);
             return httpGetRequest(httpClientEntity);
+        } 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();
         }
+        log.info(httpClientEntity.getResult());
         httpClientEntity.setResult(result);
         httpClientEntity.setCookieStore(cookieStore);
         return httpClientEntity;
     }
 
-    public HttpClientEntity httpPostParamRequest(HttpClientEntity httpClientEntity) {
+    public HttpClientEntity httpPostParamRequest(HttpClientEntity httpClientEntity) throws Exception {
         String result = "";
-        try {
-            CookieStore cs = httpClientEntity.getCookieStore();
-            if (cs != null) {
-                for (Cookie ck : cs.getCookies()) {
-                    cookieStore.addCookie(ck);
-                }
+        CookieStore cs = httpClientEntity.getCookieStore();
+        if (cs != null) {
+            for (Cookie ck : cs.getCookies()) {
+                cookieStore.addCookie(ck);
             }
+        }
 
-            HttpPost httppost = new HttpPost(httpClientEntity.getUrl());
-            for (String key : httpClientEntity.getHeaders().keySet()) {
-                httppost.setHeader(key, httpClientEntity.getHeaders().get(key));
-            }
-            List<NameValuePair> paramList = new ArrayList<NameValuePair>();
-            for (String key : httpClientEntity.getParams().keySet()) {
-                BasicNameValuePair basicNameValuePair = new BasicNameValuePair(key, String.valueOf(httpClientEntity.getParams().get(key)));
-                paramList.add(basicNameValuePair);
-            }
-            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramList, "UTF-8");
-            httppost.setEntity(formEntity);
-            CloseableHttpClient httpClient = httpClientEntity.getCloseableHttpClient();
-            HttpResponse response = httpClient.execute(httppost);
-            Header[] headers = response.getHeaders("Set-Cookie");
-            if (headers != null && headers.length > 0) {
-                for (Header header : headers) {
-                    String[] cookieArr = header.getValue().split(";");
-                    String[] ck = cookieArr[0].split("=");
-                    BasicClientCookie basicClientCookie = new BasicClientCookie(ck[0], ck[1]);
-                    Map<String, String> cookieMap = new HashMap<>();
-                    if (cookieArr.length > 1) {
-                        for (int i = 1; i < cookieArr.length; i++) {
-                            String[] ckParam = cookieArr[i].split("=");
-                            if (ckParam.length > 1) {
-                                cookieMap.put(ckParam[0].trim(), ckParam[1]);
-                            }
+        HttpPost httppost = new HttpPost(httpClientEntity.getUrl());
+        for (String key : httpClientEntity.getHeaders().keySet()) {
+            httppost.setHeader(key, httpClientEntity.getHeaders().get(key));
+        }
+        List<NameValuePair> paramList = new ArrayList<NameValuePair>();
+        for (String key : httpClientEntity.getParams().keySet()) {
+            BasicNameValuePair basicNameValuePair = new BasicNameValuePair(key, String.valueOf(httpClientEntity.getParams().get(key)));
+            paramList.add(basicNameValuePair);
+        }
+        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramList, "UTF-8");
+        httppost.setEntity(formEntity);
+        CloseableHttpClient httpClient = httpClientEntity.getCloseableHttpClient();
+        HttpResponse response = httpClient.execute(httppost);
+        Header[] headers = response.getHeaders("Set-Cookie");
+        if (headers != null && headers.length > 0) {
+            for (Header header : headers) {
+                String[] cookieArr = header.getValue().split(";");
+                String[] ck = cookieArr[0].split("=");
+                BasicClientCookie basicClientCookie = new BasicClientCookie(ck[0], ck[1]);
+                Map<String, String> cookieMap = new HashMap<>();
+                if (cookieArr.length > 1) {
+                    for (int i = 1; i < cookieArr.length; i++) {
+                        String[] ckParam = cookieArr[i].split("=");
+                        if (ckParam.length > 1) {
+                            cookieMap.put(ckParam[0].trim(), ckParam[1]);
                         }
                     }
-                    basicClientCookie.setPath(cookieMap.get("Path"));
-                    if (cookieMap.get("Domain") == null || cookieMap.get("Domain").equals("")) {
-                        basicClientCookie.setDomain(httpClientEntity.getHeaders().get("Origin").split("//")[1]);
-                    } else {
-                        basicClientCookie.setDomain(cookieMap.get("Domain"));
-                    }
-                    basicClientCookie.setExpiryDate(new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 365));
-                    cookieStore.addCookie(basicClientCookie);
                 }
+                basicClientCookie.setPath(cookieMap.get("Path"));
+                if (cookieMap.get("Domain") == null || cookieMap.get("Domain").equals("")) {
+                    basicClientCookie.setDomain(httpClientEntity.getHeaders().get("Origin").split("//")[1]);
+                } else {
+                    basicClientCookie.setDomain(cookieMap.get("Domain"));
+                }
+                basicClientCookie.setExpiryDate(new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 365));
+                cookieStore.addCookie(basicClientCookie);
             }
-            int statusCode = response.getStatusLine().getStatusCode();
-            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
-                String newUrl = response.getFirstHeader("Location").getValue();
-                httpClientEntity.setUrl(newUrl);
-                result = EntityUtils.toString(response.getEntity());
-                return httpPostParamRequest(httpClientEntity);
-            } else if (statusCode == HttpStatus.SC_OK) {
-                result = EntityUtils.toString(response.getEntity());
-                log.info(result);
-                httpClientEntity.setCloseableHttpClient(httpClient);
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-            log.error(e.getMessage());
-            return httpGetRequest(httpClientEntity);
+        }
+        int statusCode = response.getStatusLine().getStatusCode();
+        if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
+            String newUrl = response.getFirstHeader("Location").getValue();
+            httpClientEntity.setUrl(newUrl);
+            result = EntityUtils.toString(response.getEntity());
+            return httpPostParamRequest(httpClientEntity);
+        } else if (statusCode == HttpStatus.SC_OK) {
+            result = EntityUtils.toString(response.getEntity());
+            log.info(result);
+            httpClientEntity.setCloseableHttpClient(httpClient);
         }
         httpClientEntity.setResult(result);
         httpClientEntity.setCookieStore(cookieStore);
         return httpClientEntity;
     }
 
-    public HttpClientEntity callingGraph(HttpClientEntity httpClientEntity, String json) {
+    public HttpClientEntity callingGraph(HttpClientEntity httpClientEntity, String json) throws Exception {
         CookieStore cs = httpClientEntity.getCookieStore();
         if (cs != null) {
             for (Cookie ck : cs.getCookies()) {
@@ -262,53 +252,39 @@ public class HttpClientUtils {
             httpPost.setHeader(key, httpClientEntity.getHeaders().get(key));
         }
         httpPost.setHeader("Content-Type", "application/json");
-
-        try {
-            StringEntity entity = new StringEntity(json, "utf-8");
-            httpPost.setEntity(entity);
-            httpPost.setProtocolVersion(HttpVersion.HTTP_1_0);
-            httpPost.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
-            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);
-//            }
-            String result = EntityUtils.toString(response.getEntity(), "utf-8");
-            Header[] headers = response.getHeaders("Set-Cookie");
-            if (headers != null && headers.length > 0) {
-                for (Header header : headers) {
-                    String[] cookieArr = header.getValue().split(";");
-                    String[] ck = cookieArr[0].split("=");
-                    BasicClientCookie basicClientCookie = new BasicClientCookie(ck[0], ck[1]);
-                    Map<String, String> cookieMap = new HashMap<>();
-                    if (cookieArr.length > 1) {
-                        for (int i = 1; i < cookieArr.length; i++) {
-                            String[] ckParam = cookieArr[i].split("=");
-                            if (ckParam.length > 1) {
-                                cookieMap.put(ckParam[0].trim(), ckParam[1]);
-                            }
+        StringEntity entity = new StringEntity(json, "utf-8");
+        httpPost.setEntity(entity);
+        httpPost.setProtocolVersion(HttpVersion.HTTP_1_0);
+        httpPost.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
+        response = httpClient.execute(httpPost);
+        String result = EntityUtils.toString(response.getEntity(), "utf-8");
+        Header[] headers = response.getHeaders("Set-Cookie");
+        if (headers != null && headers.length > 0) {
+            for (Header header : headers) {
+                String[] cookieArr = header.getValue().split(";");
+                String[] ck = cookieArr[0].split("=");
+                BasicClientCookie basicClientCookie = new BasicClientCookie(ck[0], ck[1]);
+                Map<String, String> cookieMap = new HashMap<>();
+                if (cookieArr.length > 1) {
+                    for (int i = 1; i < cookieArr.length; i++) {
+                        String[] ckParam = cookieArr[i].split("=");
+                        if (ckParam.length > 1) {
+                            cookieMap.put(ckParam[0].trim(), ckParam[1]);
                         }
                     }
-                    basicClientCookie.setPath(cookieMap.get("Path"));
-                    if (cookieMap.get("Domain") == null || cookieMap.get("Domain").equals("")) {
-                        basicClientCookie.setDomain(httpClientEntity.getHeaders().get("Origin").split("//")[1]);
-                    } else {
-                        basicClientCookie.setDomain(cookieMap.get("Domain"));
-                    }
-                    basicClientCookie.setExpiryDate(new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 365));
-                    cookieStore.addCookie(basicClientCookie);
                 }
+                basicClientCookie.setPath(cookieMap.get("Path"));
+                if (cookieMap.get("Domain") == null || cookieMap.get("Domain").equals("")) {
+                    basicClientCookie.setDomain(httpClientEntity.getHeaders().get("Origin").split("//")[1]);
+                } else {
+                    basicClientCookie.setDomain(cookieMap.get("Domain"));
+                }
+                basicClientCookie.setExpiryDate(new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 365));
+                cookieStore.addCookie(basicClientCookie);
             }
-
-//            httpClientEntity.setResult(builder.toString());
-            httpClientEntity.setResult(result);
-            log.info(httpClientEntity.getResult());
-        } catch (Exception e) {
-            e.printStackTrace();
-            return httpGetRequest(httpClientEntity);
         }
+        httpClientEntity.setResult(result);
+        log.info(httpClientEntity.getResult());
         httpClientEntity.setCookieStore(cookieStore);
         return httpClientEntity;
     }

+ 25 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/controller/KuaishouWebController.java

@@ -1,8 +1,8 @@
 package cn.com.ctop.kuaishou.modules.graphql.controller;
 
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentConfig;
 import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouUserCookie;
-import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouUserCookieService;
-import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
+import cn.com.ctop.kuaishou.modules.graphql.service.*;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
@@ -24,6 +24,12 @@ public class KuaishouWebController {
     private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
     @Autowired
     private IKuaishouUserCookieService kuaishouUserCookieService;
+    @Autowired
+    private IKuaishouCommentStatService kuaishouCommentStatService;
+    @Autowired
+    private IKuaishouCommentKeywordService kuaishouCommentKeywordService;
+    @Autowired
+    private IKuaishouCommentConfigService kuaishouCommentConfigService;
 
     @PostMapping(value = "/login/qr")
     public Result<Map<String, Object>> getQrCode() {
@@ -60,6 +66,23 @@ public class KuaishouWebController {
         return result;
     }
 
+    @PostMapping(value = "/comment/config/detail")
+    public Result<KuaishouCommentConfig> getCommentConfig(String ksid) {
+        Result<KuaishouCommentConfig> result = new Result<>();
+        KuaishouCommentConfig kuaishouCommentConfig = kuaishouCommentConfigService.getById(ksid);
+        result.setSuccess(true);
+        result.setResult(kuaishouCommentConfig);
+        return result;
+    }
+
+    @PostMapping(value = "/comment/config/save")
+    public Result<Object> saveCommentConfig(KuaishouCommentConfig kuaishouCommentConfig) {
+        Result<Object> result = new Result<>();
+        kuaishouCommentConfigService.saveOrUpdate(kuaishouCommentConfig);
+        result.setSuccess(true);
+        return result;
+    }
+
     @PostMapping(value = "/login/status")
     public Result<Map<String, Object>> getStatus(String requestId) {
         Result<Map<String, Object>> result = new Result<Map<String, Object>>();

+ 16 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/entity/KuaishouCommentConfig.java

@@ -0,0 +1,16 @@
+package cn.com.ctop.kuaishou.modules.graphql.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+@Data
+@TableName("ctop_kuaishou_comment_config")
+public class KuaishouCommentConfig {
+    @TableId(value = "ksid", type = IdType.INPUT)
+    private String ksid;
+    private Boolean autoDelete;
+    private String strategy;
+    private String cycle;
+}

+ 18 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/entity/KuaishouCommentKeyword.java

@@ -0,0 +1,18 @@
+package cn.com.ctop.kuaishou.modules.graphql.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+@Data
+@TableName("ctop_kuaishou_comment_keyword")
+public class KuaishouCommentKeyword {
+    @TableId(value = "id", type = IdType.INPUT)
+    private Long id;
+    private String ksid;
+    private String keyword;
+    private Integer deleteCount;
+    private Integer status;
+
+}

+ 15 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/entity/KuaishouCommentStat.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.kuaishou.modules.graphql.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+@Data
+@TableName("ctop_kuaishou_comment_stat")
+public class KuaishouCommentStat {
+    @TableId(value = "comment_id", type = IdType.INPUT)
+    private Long commentId;
+    private String ksid;
+    private Integer deleteCount;
+}

+ 84 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/job/KuaishouCommentDayJob.java

@@ -0,0 +1,84 @@
+package cn.com.ctop.kuaishou.modules.graphql.job;
+
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentConfig;
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouUserCookie;
+import cn.com.ctop.kuaishou.modules.graphql.service.*;
+import com.alibaba.fastjson.JSONArray;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public class KuaishouCommentDayJob implements Job {
+    @Autowired
+    private IKuaishouCommentConfigService kuaishouCommentConfigService;
+    @Autowired
+    private IKuaishouCommentKeywordService kuaishouCommentKeywordService;
+    @Autowired
+    private IKuaishouCommentStatService kuaishouCommentStatService;
+    @Autowired
+    private IKuaishouUserCookieService kuaishouUserCookieService;
+    @Autowired
+    private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        QueryWrapper<KuaishouCommentConfig> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("auto_delete", true);
+        queryWrapper.eq("cycle", "DAY");
+        List<KuaishouCommentConfig> kuaishouCommentConfigList = kuaishouCommentConfigService.list(queryWrapper);
+        if (kuaishouCommentConfigList != null && kuaishouCommentConfigList.size() > 0) {
+            for (KuaishouCommentConfig config : kuaishouCommentConfigList) {
+                QueryWrapper<KuaishouUserCookie> queryWrapper1 = new QueryWrapper<>();
+                queryWrapper1.eq("ksid", config.getKsid());
+                KuaishouUserCookie kuaishouUserCookie = kuaishouUserCookieService.getOne(queryWrapper1);
+
+                try {
+                    String pcursor = "";
+                    do {
+                        Map<String, Object> videoMap = kuaishouWebInterfaceService.videoList(config.getKsid(), pcursor);
+                        JsonNode videoNode = mapToJson(videoMap);
+                        pcursor = videoNode.get("data").get("publicFeeds").get("pcursor").asText();
+                        Iterator<JsonNode> list = videoNode.get("data").get("publicFeeds").get("list").iterator();
+                        while (list.hasNext()) {
+                            JsonNode node = list.next();
+                            Integer commentCount = node.get("commentCount").asInt();
+                            if (commentCount > 0) {
+                                String photoId = node.get("photoId").asText();
+                                String commentPcursor = "";
+                                do {
+                                    Map<String, Object> commentMap = kuaishouWebInterfaceService.commentList(config.getKsid(), photoId, commentPcursor);
+                                    JsonNode commentNode = mapToJson(commentMap);
+                                    commentPcursor = commentNode.get("data").get("shortVideoCommentList").get("pcursor").asText();
+                                    Iterator<JsonNode> commentList = commentNode.get("data").get("shortVideoCommentList").get("commentList").iterator();
+                                    while (commentList.hasNext()) {
+                                        JsonNode commentListNode = commentList.next();
+                                        Long commentId = commentListNode.get("commentId").asLong();
+                                        Map<String, Object> deleteMap = kuaishouWebInterfaceService.commentDelete(config.getKsid(), photoId, commentId);
+
+                                    }
+                                } while (!commentPcursor.equals("no_more"));
+                            }
+                        }
+                    } while (!pcursor.equals("no_more"));
+
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    public JsonNode mapToJson(Map<String, Object> map) throws Exception {
+        ObjectMapper mapper = new ObjectMapper();
+        String json = mapper.writeValueAsString(map);
+        return mapper.readTree(json);
+    }
+}

+ 7 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/mapper/KuaishouCommentConfigMapper.java

@@ -0,0 +1,7 @@
+package cn.com.ctop.kuaishou.modules.graphql.mapper;
+
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentConfig;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+public interface KuaishouCommentConfigMapper extends BaseMapper<KuaishouCommentConfig> {
+}

+ 7 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/mapper/KuaishouCommentKeywordMapper.java

@@ -0,0 +1,7 @@
+package cn.com.ctop.kuaishou.modules.graphql.mapper;
+
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentKeyword;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+public interface KuaishouCommentKeywordMapper extends BaseMapper<KuaishouCommentKeyword> {
+}

+ 7 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/mapper/KuaishouCommentStatMapper.java

@@ -0,0 +1,7 @@
+package cn.com.ctop.kuaishou.modules.graphql.mapper;
+
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentStat;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+public interface KuaishouCommentStatMapper extends BaseMapper<KuaishouCommentStat> {
+}

+ 7 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/IKuaishouCommentConfigService.java

@@ -0,0 +1,7 @@
+package cn.com.ctop.kuaishou.modules.graphql.service;
+
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentConfig;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+public interface IKuaishouCommentConfigService extends IService<KuaishouCommentConfig> {
+}

+ 7 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/IKuaishouCommentKeywordService.java

@@ -0,0 +1,7 @@
+package cn.com.ctop.kuaishou.modules.graphql.service;
+
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentKeyword;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+public interface IKuaishouCommentKeywordService extends IService<KuaishouCommentKeyword> {
+}

+ 7 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/IKuaishouCommentStatService.java

@@ -0,0 +1,7 @@
+package cn.com.ctop.kuaishou.modules.graphql.service;
+
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentStat;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+public interface IKuaishouCommentStatService extends IService<KuaishouCommentStat> {
+}

+ 11 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/impl/KuaishouCommentConfigServiceImpl.java

@@ -0,0 +1,11 @@
+package cn.com.ctop.kuaishou.modules.graphql.service.impl;
+
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentConfig;
+import cn.com.ctop.kuaishou.modules.graphql.mapper.KuaishouCommentConfigMapper;
+import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouCommentConfigService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+@Service
+public class KuaishouCommentConfigServiceImpl extends ServiceImpl<KuaishouCommentConfigMapper, KuaishouCommentConfig> implements IKuaishouCommentConfigService {
+}

+ 11 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/impl/KuaishouCommentKeywordServiceImpl.java

@@ -0,0 +1,11 @@
+package cn.com.ctop.kuaishou.modules.graphql.service.impl;
+
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentKeyword;
+import cn.com.ctop.kuaishou.modules.graphql.mapper.KuaishouCommentKeywordMapper;
+import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouCommentKeywordService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+@Service
+public class KuaishouCommentKeywordServiceImpl extends ServiceImpl<KuaishouCommentKeywordMapper, KuaishouCommentKeyword> implements IKuaishouCommentKeywordService {
+}

+ 11 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/impl/KuaishouCommentStatServiceImpl.java

@@ -0,0 +1,11 @@
+package cn.com.ctop.kuaishou.modules.graphql.service.impl;
+
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentStat;
+import cn.com.ctop.kuaishou.modules.graphql.mapper.KuaishouCommentStatMapper;
+import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouCommentStatService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+@Service
+public class KuaishouCommentStatServiceImpl extends ServiceImpl<KuaishouCommentStatMapper, KuaishouCommentStat> implements IKuaishouCommentStatService {
+}

File diff suppressed because it is too large
+ 36 - 62
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/impl/KuaishouWebInterfaceServiceImpl.java