Browse Source

提交评论管理接口

xuzuoyun 5 năm trước cách đây
mục cha
commit
318a95ea55

+ 6 - 3
module-common/src/main/java/cn/com/ctop/common/module/utils/HttpClientUtils.java

@@ -83,7 +83,7 @@ public class HttpClientUtils {
                 }
                 result = builder.toString();
             }
-
+            log.info(httpClientEntity.getResult());
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -92,6 +92,7 @@ public class HttpClientUtils {
     }
 
     public HttpClientEntity httpPostParamRequest(HttpClientEntity httpClientEntity) {
+        String result = "";
         try {
             CookieStore cs = httpClientEntity.getCookieStore();
             if (cs != null) {
@@ -118,17 +119,18 @@ public class HttpClientUtils {
             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) {
-                String result = EntityUtils.toString(response.getEntity());
+                result = EntityUtils.toString(response.getEntity());
                 log.info(result);
-                httpClientEntity.setResult(result);
                 httpClientEntity.setCloseableHttpClient(httpClient);
             }
         } catch (Exception e) {
             e.printStackTrace();
             log.error(e.getMessage());
         }
+        httpClientEntity.setResult(result);
         System.out.println(new Gson().toJson(cookieStore.getCookies()));
         httpClientEntity.setCookieStore(cookieStore);
         return httpClientEntity;
@@ -161,6 +163,7 @@ public class HttpClientUtils {
                 builder.append(line);
             }
             httpClientEntity.setResult(builder.toString());
+            log.info(httpClientEntity.getResult());
         } catch (Exception e) {
             e.printStackTrace();
         }

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

@@ -116,6 +116,20 @@ public class KuaishouWebController {
         return result;
     }
 
+    @PostMapping(value = "/comment/add")
+    public Result<Map<String, Object>> commentAdd(String ksid, String photoId, String principalId, String content, Long replyToCommentId, Long repltTo) {
+        Result<Map<String, Object>> result = new Result<Map<String, Object>>();
+        try {
+            Map<String, Object> statusMap = kuaishouWebInterfaceService.commentAdd(ksid, photoId, principalId, content, replyToCommentId, repltTo);
+            result.setSuccess(true);
+            result.setResult(statusMap);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+        }
+        return result;
+    }
+
     @PostMapping(value = "/subcomment/list")
     public Result<Map<String, Object>> subCommentList(String ksid, String photoId, Long rootCommentId, String pcursor) {
         Result<Map<String, Object>> result = new Result<Map<String, Object>>();

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

@@ -28,5 +28,7 @@ public interface IKuaishouWebInterfaceService {
 
     public Map<String, Object> commentList(String ksid, String photoId, String pcursor);
 
+    public Map<String, Object> commentAdd(String ksid, String photoId, String principalId, String content, Long replyToCommentId, Long replyTo);
+
     public Map<String, Object> subCommentList(String ksid, String photoId, Long rootCommentId, String pcursor);
 }

+ 61 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/impl/KuaishouWebInterfaceServiceImpl.java

@@ -316,13 +316,71 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
             params.put("photoId", photoId);
             params.put("commentId", commentId);
             System.out.println(new Gson().toJson(params));
+            Map<String, String> headers = getHeaders();
+            headers.put("Content-Type", "application/x-www-form-urlencoded");
+            headers.put("kpn", "GAME_ZONE");
+            headers.put("kpf", "PC_WEB");
             HttpClientEntity httpClientEntity = new HttpClientEntity();
             HttpClientUtils httpClientUtils = new HttpClientUtils();
             httpClientEntity.setCloseableHttpClient(httpClientUtils.createSSLClientDefault());
-            httpClientEntity.setUrl("https://id.kuaishou.com/pass/kuaishou/login/qr/callback");
+            httpClientEntity.setUrl("https://live.kuaishou.com/rest/wd/comment/delete");
             httpClientEntity.setResult("");
             httpClientEntity.setCookieStore(cookieTransfer(kuaishouUserCookie.getCookie()));
-            httpClientEntity.setHeaders(getHeaders());
+            List<Cookie> list = httpClientEntity.getCookieStore().getCookies();
+            String did = "";
+            for (Cookie ck : list) {
+                if (ck.getName().equals("did")) {
+                    did = ck.getValue();
+                }
+            }
+            headers.put("Referer", "https://live.kuaishou.com/u/" + kuaishouUserCookie.getEid() + "/" + photoId + "?did=" + did);
+            httpClientEntity.setHeaders(headers);
+            httpClientEntity.setParams(params);
+            httpClientEntity = httpClientUtils.httpPostParamRequest(httpClientEntity);
+            try {
+                ObjectMapper mapper = new ObjectMapper();
+                resultMap = mapper.readValue(httpClientEntity.getResult(), new TypeReference<Map<String, Object>>() {
+                });
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return resultMap;
+    }
+
+    public Map<String, Object> commentAdd(String ksid, String photoId, String principalId, String content, Long replyToCommentId, Long replyTo) {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        QueryWrapper<KuaishouUserCookie> queryWrapper = new QueryWrapper<KuaishouUserCookie>();
+        Map<String, Object> resultMap = new HashMap<>();
+        queryWrapper.eq("user_id", user.getId());
+        queryWrapper.eq("ksid", ksid);
+        KuaishouUserCookie kuaishouUserCookie = kuaishouUserCookieService.getOne(queryWrapper);
+        if (kuaishouUserCookie != null) {
+            Map<String, Object> params = new HashMap<String, Object>();
+            params.put("photoId", photoId);
+            params.put("principalId", principalId);
+            params.put("content", content);
+            params.put("replyToCommentId", replyToCommentId);
+            params.put("replyTo", replyTo);
+            Map<String, String> headers = getHeaders();
+            headers.put("Content-Type", "application/x-www-form-urlencoded");
+            headers.put("kpn", "GAME_ZONE");
+            headers.put("kpf", "PC_WEB");
+            System.out.println(new Gson().toJson(params));
+            HttpClientEntity httpClientEntity = new HttpClientEntity();
+            HttpClientUtils httpClientUtils = new HttpClientUtils();
+            httpClientEntity.setCloseableHttpClient(httpClientUtils.createSSLClientDefault());
+            httpClientEntity.setUrl("https://live.kuaishou.com/rest/wd/photo/comment/add");
+            httpClientEntity.setResult("");
+            List<Cookie> list = httpClientEntity.getCookieStore().getCookies();
+            String did = "";
+            for (Cookie ck : list) {
+                if (ck.getName().equals("did")) {
+                    did = ck.getValue();
+                }
+            }
+            headers.put("Referer", "https://live.kuaishou.com/u/" + kuaishouUserCookie.getEid() + "/" + photoId + "?did=" + did);
+            httpClientEntity.setHeaders(headers);
             httpClientEntity.setParams(params);
             httpClientEntity = httpClientUtils.httpPostParamRequest(httpClientEntity);
             try {
@@ -341,7 +399,7 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
         try {
             ObjectMapper mapper = new ObjectMapper();
             JsonNode jsonNode = mapper.readTree(json);
-            SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy H:m:s aaa");
+            SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy h:m:s aa", Locale.ENGLISH);
             if (jsonNode != null) {
                 JsonNode cookiesNode = jsonNode.get("cookies");
                 if (cookiesNode != null && cookiesNode.isArray()) {

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

@@ -2,10 +2,25 @@ package cn.com.ctop.kuaishou.modules.graphql.vo;
 
 import lombok.Data;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
 @Data
 public class KuaishouAcceptVO {
     private Integer result;
     private String qrToken;
     private String callback;
     private String sid;
+
+    public static void main(String[] args) {
+        SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy h:m:s aa", Locale.ENGLISH);
+        try {
+            Date d = sdf.parse("Oct 10, 2019 7:49:30 PM");
+            System.out.println(d.toLocaleString());
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+    }
 }