fix:优化

上级 a06f5077
......@@ -30,7 +30,8 @@ public class CsdnController {
@ApiOperation(value = "单人三连", notes = "单人三连")
@GetMapping("/singleTriplet")
public Result singleTriplet(@Param("username") String username) {
return Result.ok(csdnService.singleArticle(username));
csdnService.singleArticle(username);
return Result.ok("三连完成");
}
@ApiOperation(value = "多人三连", notes = "多人三连")
......
package com.kwan.springbootkwan.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CsdnStatusResp {
public Integer code;
public String value;
}
......@@ -7,7 +7,7 @@ import lombok.Data;
import java.util.List;
@Data
public class BusinessInfo {
public class BusinessInfoResponse {
private String traceId;
private Integer code;
......@@ -48,16 +48,16 @@ public class BusinessInfo {
public static void main(String[] args) {
String body = " {\"code\":200,\"message\":\"success\",\"traceId\":\"56e59727-b0e5-4017-b613-3bfb9dbee864\",\"data\":{\"list\":[{\"type\":\"blog\",\"formatTime\":\"12 分钟前\",\"title\":\"【实战项目】从0到1实现高并发内存池(上)\",\"description\":\"\u200B本篇文章是实现一个高并发的内存池,他的原型是google的一个开源项目tcmalloc(tcmalloc源码),tcmalloc全称Thread-Caching Malloc,即线程缓存的malloc,是一种用于内存分配和管理的内存分配器(内存池)。这个项目旨在提高多线程应用程序的性能,实现了高效的多线程内存管理。\",\"hasOriginal\":true,\"diggCount\":4,\"commentCount\":3,\"postTime\":1698045098000,\"createTime\":1697553615000,\"url\":\"https://blog.csdn.net/weixin_67596609/article/details/133895730\",\"articleType\":1,\"viewCount\":36,\"picList\":[\"https://img-blog.csdnimg.cn/b7634b29af834f9d88cad6ba1de0258a.png\"],\"editUrl\":\"https://mp.csdn.net/console/editor/html/133895730\",\"collectCount\":3,\"rtype\":\"article\"},{\"type\":\"blink\",\"formatTime\":\"昨天 10:40\",\"title\":\"前几天由于一些原因,没有更新文章。最近要开始持续更新啦!\\nps:想多了全是问题,做多了全是答案!加油!\\n\",\"picList\":[{\"thumbnail\":\"https://userblink.csdnimg.cn/6748783d6e974f5da67346c6b0e9b2f0.png?x-oss-process=image/interlace,1/format,jpg/resize,w_375\",\"url\":\"https://userblink.csdnimg.cn/6748783d6e974f5da67346c6b0e9b2f0.png\"}],\"createTime\":1697942415000,\"url\":\"https://blink.csdn.net/details/1591445\",\"source\":1,\"expandTitle\":null,\"cover\":null,\"rtype\":\"picture\"}],\"total\":null}}";
ObjectMapper objectMapper = new ObjectMapper();
BusinessInfo businessInfo = null;
BusinessInfoResponse businessInfoResponse = null;
try {
businessInfo = objectMapper.readValue(body, BusinessInfo.class);
System.out.println(businessInfo);
businessInfoResponse = objectMapper.readValue(body, BusinessInfoResponse.class);
System.out.println(businessInfoResponse);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
final BusinessInfo.ArticleData data = businessInfo.getData();
final List<BusinessInfo.ArticleData.Article> list = data.getList();
final BusinessInfo.ArticleData.Article article = list.get(0);
final BusinessInfoResponse.ArticleData data = businessInfoResponse.getData();
final List<BusinessInfoResponse.ArticleData.Article> list = data.getList();
final BusinessInfoResponse.ArticleData.Article article = list.get(0);
final String type = article.getType();
final String urlInfo = article.getUrl();
System.out.println(type);
......
......@@ -5,7 +5,7 @@ import lombok.Data;
import java.util.List;
@Data
public class CollectInfo {
public class CollectInfoQuery {
private Integer sourceId;
private String fromType;
private String author;
......
......@@ -3,7 +3,7 @@ package com.kwan.springbootkwan.entity.resp;
import lombok.Data;
@Data
public class CollectData {
public class CollectResponse {
public Long code;
public String msg;
public String total;
......
......@@ -5,7 +5,7 @@ import lombok.Data;
import java.util.List;
@Data
public class CommentData {
public class CommentListResponse {
public int code;
public String message;
public String traceId;
......
package com.kwan.springbootkwan.entity.resp;
import lombok.Data;
@Data
public class CommentResponse {
public int code;
public String message;
public String traceId;
public int data;
}
\ No newline at end of file
package com.kwan.springbootkwan.entity.resp;
import lombok.Data;
@Data
public class IsCollectResponse {
public int code;
public String message;
public String traceId;
public CollectDataDetail data;
@Data
public static class CollectDataDetail {
public String tips;
public boolean status;
}
}
\ No newline at end of file
......@@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class LikeData {
public class LikeResponse {
public int code;
public String message;
public String traceId;
......
package com.kwan.springbootkwan.service;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
/**
* 收藏
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/10/24 01:00
*/
public interface CsdnCollectService {
/**
* 查询是否收藏过
*
* @return
*/
Boolean isCollect(String articleId);
/**
* 点赞和取消点赞接口,true,点过,false,没有点过
*
* @return
*/
Boolean collect(BusinessInfoResponse.ArticleData.Article article, String username);
}
\ No newline at end of file
package com.kwan.springbootkwan.service;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
/**
* 评论
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/10/24 01:25
*/
public interface CsdnCommentService {
/**
* 查询是否评论过
*
* @return
*/
Boolean isComment(BusinessInfoResponse.ArticleData.Article article);
/**
* 点赞和取消点赞接口,true,点过,false,没有点过
*
* @return
*/
Boolean comment(String articleId);
}
\ No newline at end of file
......@@ -9,8 +9,17 @@ package com.kwan.springbootkwan.service;
* @date : 2023/10/24 00:19
*/
public interface CsdnLikeService {
/**
* 查询是否点过赞
* todo:还未找到接口,搁浅
*
* @return
*/
Boolean islike(String articleId);
/**
* 是否点过赞,true,点过,false,没有点过
* 点赞和取消点赞接口,true,点过,false,没有点过
*
* @return
*/
......
package com.kwan.springbootkwan.service;
import com.kwan.springbootkwan.entity.CsdnStatusResp;
/**
* csdn博客自动化
*
......@@ -10,37 +8,16 @@ import com.kwan.springbootkwan.entity.CsdnStatusResp;
* @date : 2023/10/23 14:59
*/
public interface CsdnService {
/**
* 单人三连
*
* @return
*/
CsdnStatusResp singleArticle(String username);
/**
* 查询是否评论过
* 单人三连
*
* @param articleId
* @return
*/
Boolean getArticleInfo(String articleId);
/**
* 点赞
*
* @param articleId
*/
void like(String articleId);
/**
* 评论
*
* @param articleId
*/
int comment(String articleId);
void singleArticle(String username);
/**
* 三连
* 多人三连
*/
void multiTriplet();
}
\ No newline at end of file
package com.kwan.springbootkwan.service.impl;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
import com.kwan.springbootkwan.entity.resp.CollectInfoQuery;
import com.kwan.springbootkwan.entity.resp.CollectResponse;
import com.kwan.springbootkwan.entity.resp.IsCollectResponse;
import com.kwan.springbootkwan.service.CsdnCollectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class CsdnCollectServiceImpl implements CsdnCollectService {
@Value("${csdn.cookie}")
private String csdnCookie;
@Value("${csdn.self_user_name}")
private String selfUserName;
@Value("${csdn.url.is_collect_url}")
private String isCollectUrl;
@Value("${csdn.url.add_collect_url}")
private String addCollectUrl;
/**
* 收藏满了
*/
private static boolean COLLECT_IS_FULL = false;
@Override
public Boolean isCollect(String articleId) {
if (COLLECT_IS_FULL) {
return true;
}
HttpResponse response = HttpUtil.createGet(isCollectUrl)
.header("Cookie", csdnCookie)
.form("articleId", articleId)
.execute();
final String body = response.body();
ObjectMapper objectMapper = new ObjectMapper();
try {
final int code = objectMapper.readValue(body, IsCollectResponse.class).code;
final IsCollectResponse.CollectDataDetail data = objectMapper.readValue(body, IsCollectResponse.class).getData();
if (code == 200) {
final boolean status = data.status;
if (status) {
log.info("已收藏");
} else {
log.info("未收藏");
}
return status;
}
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return true;
}
@Override
public Boolean collect(BusinessInfoResponse.ArticleData.Article article, String username) {
if (COLLECT_IS_FULL) {
return true;
}
final String urlInfo = article.getUrl();
String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1);
CollectResponse collectResponse = null;
try {
CollectInfoQuery collectInfoQuery = new CollectInfoQuery();
collectInfoQuery.setSourceId(Integer.valueOf(articleId));
collectInfoQuery.setFromType("PC");
collectInfoQuery.setAuthor(username);
collectInfoQuery.setDescription(article.getDescription());
collectInfoQuery.setSource("blog");
collectInfoQuery.setFolderIdList(Lists.newArrayList(7589042));
collectInfoQuery.setTitle(article.getTitle());
collectInfoQuery.setUrl(article.getUrl());
collectInfoQuery.setUsername(selfUserName);
ObjectMapper objectMapper = new ObjectMapper();
String jsonCollectInfo = objectMapper.writeValueAsString(collectInfoQuery);
HttpResponse response = HttpUtil.createPost(addCollectUrl)
.header("Cookie", csdnCookie)
.header("Content-Type", "application/json")
.body(jsonCollectInfo)
.execute();
final String body = response.body();
collectResponse = objectMapper.readValue(body, CollectResponse.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
final Long code = collectResponse.code;
if (code.equals(200)) {
log.info("收藏成功");
} else if (code.equals(400000101)) {
log.info("参数缺失");
} else if (code.equals(400)) {
COLLECT_IS_FULL = true;
log.info("今日收藏次数已达上限!");
}
return true;
}
}
\ No newline at end of file
package com.kwan.springbootkwan.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
import com.kwan.springbootkwan.entity.resp.CommentListResponse;
import com.kwan.springbootkwan.entity.resp.CommentResponse;
import com.kwan.springbootkwan.service.CsdnCommentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service
public class CsdnCommentServiceImpl implements CsdnCommentService {
@Value("${csdn.cookie}")
private String csdnCookie;
@Value("${csdn.self_user_name}")
private String selfUserName;
@Value("${csdn.url.is_comment_list_url}")
private String commentListUrl;
@Value("${csdn.url.comment_url}")
private String commentUrl;
/**
* 收藏满了
*/
private static boolean COMMENT_IS_FULL = false;
@Override
public Boolean isComment(BusinessInfoResponse.ArticleData.Article article) {
if (COMMENT_IS_FULL) {
return true;
}
final String urlInfo = article.getUrl();
String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1);
String url = commentListUrl + articleId;
// 使用Hutool发送GET请求
HttpResponse response = HttpUtil.createPost(url)
.header("Cookie", csdnCookie)
.form("page", 1)
.form("size", 50)
.form("fold", "unfold")
.execute();
// 打印响应结果
final String body = response.body();
ObjectMapper objectMapper = new ObjectMapper();
CommentListResponse articleInfo;
try {
articleInfo = objectMapper.readValue(body, CommentListResponse.class);
final CommentListResponse.DataInfo data = articleInfo.getData();
final List<CommentListResponse.Comment> list = data.getList();
if (CollectionUtil.isNotEmpty(list)) {
for (CommentListResponse.Comment comment : list) {
final CommentListResponse.Info info = comment.getInfo();
final String userName = info.getUserName();
if (StringUtils.equals(userName, selfUserName)) {
//评论过
return true;
}
}
}
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return false;
}
@Override
public Boolean comment(String articleId) {
if (COMMENT_IS_FULL) {
return true;
}
//评论
CommentResponse comment = this.dealComment(articleId);
final int code = comment.code;
final String message = comment.getMessage();
if (code == 200) {
log.info("评论成功");
} else if (code == 400 && StringUtils.equals(message, "您已达到当日发送上限,请明天尝试!")) {
log.info(message);
COMMENT_IS_FULL = true;
} else {
log.info("您评论太快了,请休息一下!");
}
return true;
}
/**
* 评论文章
*
* @param articleId
* @return
*/
private CommentResponse dealComment(String articleId) {
HttpResponse response = HttpUtil.createPost(commentUrl)
.header("Cookie", csdnCookie)
.form("articleId", articleId)
.form("content", "支持博主优质文章,讲解得非常详细,干货满满,通俗易懂,期待博主下次更新")
.execute();
final String body = response.body();
ObjectMapper objectMapper = new ObjectMapper();
CommentResponse commentResponse = null;
try {
commentResponse = objectMapper.readValue(body, CommentResponse.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return commentResponse;
}
}
\ No newline at end of file
......@@ -4,44 +4,44 @@ import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kwan.springbootkwan.entity.resp.LikeData;
import com.kwan.springbootkwan.entity.resp.LikeResponse;
import com.kwan.springbootkwan.service.CsdnLikeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class CsdnLikeServiceImpl implements CsdnLikeService {
/**
* 构建header参数
*/
private static final String CUSTOM_HEADER_NAME = "Cookie";
@Value("${csdn.cookie}")
private String csdnCookie;
@Value("${csdn.url.like_url}")
private String url;
/**
* 点赞满了
*/
private static boolean LIKE_IS_FULL = false;
/**
* 参数值
*/
private static final String CUSTOM_HEADER_VALUE = "uuid_tt_dd=10_20285116700-1697522872601-604163; c_adb=1; loginbox_strategy=%7B%22taskId%22%3A308%2C%22abCheckTime%22%3A1697522874474%2C%22version%22%3A%22control%22%7D; UserName=qyj19920704; UserInfo=a7d3b88c53a841ebb5792202cb43c84f; UserToken=a7d3b88c53a841ebb5792202cb43c84f; UserNick=%E6%AA%80%E8%B6%8A%E5%89%91%E6%8C%87%E5%A4%A7%E5%8E%82; AU=769; UN=qyj19920704; BT=1697522886100; p_uid=U010000; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22qyj19920704%22%2C%22scope%22%3A1%7D%7D; management_ques=1697592152734; blog_details_recommend_nps=1697616147423; c_segment=3; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1697522874,1697551027,1697636661,1697683407; csrfToken=jTRD3_1IBVA703lu2FkVkazx; dc_sid=9f7a02ed8375e91d86271ddaf1cf2ce4; c_first_ref=default; c_first_page=https%3A//liucy.blog.csdn.net/article/details/133852303%3Fspm%3D1001.2014.3001.5502; c_segment=3; Hm_lvt_e5ef47b9f471504959267fd614d579cd=1697764951; Hm_lpvt_e5ef47b9f471504959267fd614d579cd=1697764951; 404_page_nps=1697764955523; ssxmod_itna=YqUxBD97kOGHD8D2BmYite44zxcYo1=WOiox0vmvqGzDAxn40iDtgeqODDwu0/DNMQiDpiDuWOntaV73S5fd3iPeaN3D84i7DKqibDCqD1D3qDktzDYA8Dt4DTD34DYDiO=DBRsUQDFATN/3wUjmGtDG4DgDB=DxBEl3djBAq4DCr4DbxPy7mrDtLNSeLLdXT0/nn5Yf445SOG5lipwm0GdG7vwBA4PlDxNt8v1wADoGGGQYf+IE75ep753zpDxD; ssxmod_itna2=YqUxBD97kOGHD8D2BmYite44zxcYo1=WOYxn9EenDDsYebDLGQCoqQuGvHdDQRKYubdD6QqomsRD3xyRI/W9Q5nhe8oeYUvimaWYrNsqwcDgL6mDjYUhZK09LYcY/t5hSuP2va/kclf6hRkNh+LPyDwic73=9i4d94Lvw/R=oQ7E+jT4jjjA2Y+=QplLm8nbePRb+7=Re1CpjmZ4wIrnNPSKofWnIj=WOtkFtphylt+GhUxr0KkGtTzDXKDEEkbn3qhIn3Sj/ezt1u2MO3M9h7zEL6RunrXaKE+YdkRnIKiTG93cqpGFq8Fwr7ehksk1ZSWhoN2hQydddqQ1bTOSW8ddX+7g24v4TZ0+52=Y8PsOwfhavW4ECY8+GZOK=ro97bK0=Yi3YD5ZGsq25FhPodIRGCD2O8xidfo8+NR88v+rq4+b=fUOEK2frPEPdLFuYkao9uCfM1+cFZQ7q6HEMfRLjf6bhof0=1YhEYO1U=NZCPvDDw2Psluciq4De13mDNBODwqLwwg44qwOiDf=j1fKK5q+8gd7DDjKDeMv/04YDmLGvrwqOz4cov79500D4D==; c_first_ref=default; c_first_page=https%3A//mp.csdn.net/; creative_btn_mp=3; c_hasSub=true; write_guide_show=3; log_Id_click=177; dc_session_id=11_1698022100317.787671; c_dsid=11_1698022100317.794351; log_Id_pv=149; log_Id_view=1105; c_pref=https%3A//i.csdn.net/; c_ref=https%3A//blog.csdn.net/imwucx; c_page_id=default; dc_session_id=11_1698022100317.787671; c_dsid=11_1698022100317.794351; log_Id_view=1106; dc_tos=s2yi9b; log_Id_click=178; c_pref=https%3A//blog.csdn.net/imwucx; log_Id_pv=150; creativeSetApiNew=%7B%22toolbarImg%22%3Anull%2C%22publishSuccessImg%22%3Anull%2C%22articleNum%22%3A895%2C%22type%22%3A0%2C%22oldUser%22%3Afalse%2C%22useSeven%22%3Afalse%2C%22userName%22%3A%22qyj19920704%22%7D; c_ref=https%3A//cxian.blog.csdn.net/article/details/131299195; c_page_id=default; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1698022433; dc_tos=s2yinc";
@Override
public Boolean islike(String articleId) {
return true;
}
@Override
public Boolean like(String articleId) {
if (LIKE_IS_FULL) {
return true;
}
String url = "https://blog.csdn.net//phoenix/web/v1/article/like";
// 使用Hutool发送GET请求
HttpResponse response = HttpUtil.createPost(url)
.header(CUSTOM_HEADER_NAME, CUSTOM_HEADER_VALUE)
.header("Cookie", csdnCookie)
.form("articleId", articleId)
.execute();
final String body = response.body();
ObjectMapper objectMapper = new ObjectMapper();
try {
final int code = objectMapper.readValue(body, LikeData.class).code;
final LikeData.LikeDataDetail data = objectMapper.readValue(body, LikeData.class).getData();
final int code = objectMapper.readValue(body, LikeResponse.class).code;
final LikeResponse.LikeDataDetail data = objectMapper.readValue(body, LikeResponse.class).getData();
if (code == 200) {
final boolean status = data.status;
if (status) {
......
......@@ -5,18 +5,16 @@ import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.kwan.springbootkwan.entity.CsdnStatusResp;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.entity.resp.BusinessInfo;
import com.kwan.springbootkwan.entity.resp.CollectData;
import com.kwan.springbootkwan.entity.resp.CollectInfo;
import com.kwan.springbootkwan.entity.resp.CommentData;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
import com.kwan.springbootkwan.service.CsdnCollectService;
import com.kwan.springbootkwan.service.CsdnCommentService;
import com.kwan.springbootkwan.service.CsdnService;
import com.kwan.springbootkwan.service.CsdnUserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
......@@ -25,187 +23,66 @@ import java.util.List;
@Slf4j
@Service
public class CsdnServiceImpl implements CsdnService {
/**
* 构建header参数
*/
private static final String CUSTOM_HEADER_NAME = "Cookie";
/**
* 点赞满了
*/
private static boolean LIKE_IS_FULL = false;
/**
* 收藏满了
*/
private static boolean COLLECT_IS_FULL = false;
/**
* 参数值
*/
private static final String CUSTOM_HEADER_VALUE = "uuid_tt_dd=10_20285116700-1697522872601-604163; c_adb=1; loginbox_strategy=%7B%22taskId%22%3A308%2C%22abCheckTime%22%3A1697522874474%2C%22version%22%3A%22control%22%7D; UserName=qyj19920704; UserInfo=a7d3b88c53a841ebb5792202cb43c84f; UserToken=a7d3b88c53a841ebb5792202cb43c84f; UserNick=%E6%AA%80%E8%B6%8A%E5%89%91%E6%8C%87%E5%A4%A7%E5%8E%82; AU=769; UN=qyj19920704; BT=1697522886100; p_uid=U010000; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22qyj19920704%22%2C%22scope%22%3A1%7D%7D; management_ques=1697592152734; blog_details_recommend_nps=1697616147423; c_segment=3; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1697522874,1697551027,1697636661,1697683407; csrfToken=jTRD3_1IBVA703lu2FkVkazx; dc_sid=9f7a02ed8375e91d86271ddaf1cf2ce4; c_first_ref=default; c_first_page=https%3A//liucy.blog.csdn.net/article/details/133852303%3Fspm%3D1001.2014.3001.5502; c_segment=3; Hm_lvt_e5ef47b9f471504959267fd614d579cd=1697764951; Hm_lpvt_e5ef47b9f471504959267fd614d579cd=1697764951; 404_page_nps=1697764955523; ssxmod_itna=YqUxBD97kOGHD8D2BmYite44zxcYo1=WOiox0vmvqGzDAxn40iDtgeqODDwu0/DNMQiDpiDuWOntaV73S5fd3iPeaN3D84i7DKqibDCqD1D3qDktzDYA8Dt4DTD34DYDiO=DBRsUQDFATN/3wUjmGtDG4DgDB=DxBEl3djBAq4DCr4DbxPy7mrDtLNSeLLdXT0/nn5Yf445SOG5lipwm0GdG7vwBA4PlDxNt8v1wADoGGGQYf+IE75ep753zpDxD; ssxmod_itna2=YqUxBD97kOGHD8D2BmYite44zxcYo1=WOYxn9EenDDsYebDLGQCoqQuGvHdDQRKYubdD6QqomsRD3xyRI/W9Q5nhe8oeYUvimaWYrNsqwcDgL6mDjYUhZK09LYcY/t5hSuP2va/kclf6hRkNh+LPyDwic73=9i4d94Lvw/R=oQ7E+jT4jjjA2Y+=QplLm8nbePRb+7=Re1CpjmZ4wIrnNPSKofWnIj=WOtkFtphylt+GhUxr0KkGtTzDXKDEEkbn3qhIn3Sj/ezt1u2MO3M9h7zEL6RunrXaKE+YdkRnIKiTG93cqpGFq8Fwr7ehksk1ZSWhoN2hQydddqQ1bTOSW8ddX+7g24v4TZ0+52=Y8PsOwfhavW4ECY8+GZOK=ro97bK0=Yi3YD5ZGsq25FhPodIRGCD2O8xidfo8+NR88v+rq4+b=fUOEK2frPEPdLFuYkao9uCfM1+cFZQ7q6HEMfRLjf6bhof0=1YhEYO1U=NZCPvDDw2Psluciq4De13mDNBODwqLwwg44qwOiDf=j1fKK5q+8gd7DDjKDeMv/04YDmLGvrwqOz4cov79500D4D==; c_first_ref=default; c_first_page=https%3A//mp.csdn.net/; creative_btn_mp=3; c_hasSub=true; write_guide_show=3; log_Id_click=177; dc_session_id=11_1698022100317.787671; c_dsid=11_1698022100317.794351; log_Id_pv=149; log_Id_view=1105; c_pref=https%3A//i.csdn.net/; c_ref=https%3A//blog.csdn.net/imwucx; c_page_id=default; dc_session_id=11_1698022100317.787671; c_dsid=11_1698022100317.794351; log_Id_view=1106; dc_tos=s2yi9b; log_Id_click=178; c_pref=https%3A//blog.csdn.net/imwucx; log_Id_pv=150; creativeSetApiNew=%7B%22toolbarImg%22%3Anull%2C%22publishSuccessImg%22%3Anull%2C%22articleNum%22%3A895%2C%22type%22%3A0%2C%22oldUser%22%3Afalse%2C%22useSeven%22%3Afalse%2C%22userName%22%3A%22qyj19920704%22%7D; c_ref=https%3A//cxian.blog.csdn.net/article/details/131299195; c_page_id=default; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1698022433; dc_tos=s2yinc";
@Value("${csdn.cookie}")
private String csdnCookie;
@Value("${csdn.num_of_articles_per_person}")
private Integer numOfArticlesPerPerson;
@Value("${csdn.url.user_article_url}")
private String url;
@Autowired
private CsdnUserInfoService csdnUserInfoService;
@Autowired
private CsdnCollectService csdnCollectService;
@Autowired
private CsdnCommentService csdnCommentService;
@Override
public CsdnStatusResp singleArticle(String username) {
String url = "https://blog.csdn.net/community/home-api/v1/get-business-list";
// 使用Hutool发送GET请求
public void singleArticle(String username) {
HttpResponse response = HttpUtil.createGet(url)
.header(CUSTOM_HEADER_NAME, CUSTOM_HEADER_VALUE)
.header("Cookie", csdnCookie)
.form("page", 1)
.form("size", 5)
.form("businessType", "lately")
.form("noMore", false)
.form("username", username)
.execute();
// 打印响应结果
final String body = response.body();
ObjectMapper objectMapper = new ObjectMapper();
BusinessInfo businessInfo = null;
BusinessInfoResponse businessInfoResponse;
try {
businessInfo = objectMapper.readValue(body, BusinessInfo.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
final BusinessInfo.ArticleData data = businessInfo.getData();
final List<BusinessInfo.ArticleData.Article> list = data.getList();
//处理评论过
int commentNum = 0;
int successNum = 0;
int notBlogNum = 0;
int count = 3;//评论3篇
for (int i = 0; i < count; i++) {
final BusinessInfo.ArticleData.Article article = list.get(i);
final String type = article.getType();
if (!StringUtils.equals("blog", type)) {
notBlogNum++;
continue;
}
final String urlInfo = article.getUrl();
String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1);
final Boolean articleInfo = this.getArticleInfo(articleId);
if (!articleInfo) {
//进行点赞和评论
final int comment = this.comment(articleId);
// 打印响应结果
if (comment == 200) {
successNum++;
if (!COLLECT_IS_FULL) {
this.collect(username, article, articleId);
businessInfoResponse = objectMapper.readValue(body, BusinessInfoResponse.class);
final BusinessInfoResponse.ArticleData data = businessInfoResponse.getData();
final List<BusinessInfoResponse.ArticleData.Article> list = data.getList();
if (CollectionUtil.isNotEmpty(list)) {
final int size = list.size();
if (size < numOfArticlesPerPerson) {
numOfArticlesPerPerson = size;
}
for (int i = 0; i < numOfArticlesPerPerson; i++) {
final BusinessInfoResponse.ArticleData.Article article = list.get(i);
final String type = article.getType();
if (!StringUtils.equals("blog", type)) {
continue;
}
final String urlInfo = article.getUrl();
String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1);
//评论
final Boolean comment = csdnCommentService.isComment(article);
if (!comment) {
csdnCommentService.comment(articleId);
}
if (!LIKE_IS_FULL) {
this.like(articleId);
//收藏
final Boolean collect = csdnCollectService.isCollect(articleId);
if (!collect) {
csdnCollectService.collect(article, username);
}
} else if (comment == 400) {
return new CsdnStatusResp(400, "您评论太快了,请休息一下!");
}
} else {
commentNum++;
}
}
if (count != successNum) {
return new CsdnStatusResp(300, "评论过的数量=" + commentNum + "非博客的数量:" + notBlogNum);
}
return new CsdnStatusResp(200, "三连完成");
}
/**
* 收藏
*
* @param username
* @param article
* @param articleId
*/
private void collect(String username, BusinessInfo.ArticleData.Article article, String articleId) {
CollectData collectData = null;
try {
CollectInfo collectInfo = new CollectInfo();
collectInfo.setSourceId(Integer.valueOf(articleId));
collectInfo.setFromType("PC");
collectInfo.setAuthor(username);
collectInfo.setDescription(article.getDescription());
collectInfo.setSource("blog");
collectInfo.setFolderIdList(Lists.newArrayList(7589042));
collectInfo.setTitle(article.getTitle());
collectInfo.setUrl(article.getUrl());
collectInfo.setUsername("qyj19920704");
ObjectMapper objectMapper = new ObjectMapper();
String jsonCollectInfo = objectMapper.writeValueAsString(collectInfo);
System.out.println("jsonCollectInfo=" + jsonCollectInfo);
String collectUrl = "https://mp-action.csdn.net/interact/wrapper/pc/favorite/v1/api/addFavoriteInFolds";
// 使用Hutool发送GET请求
HttpResponse response = HttpUtil.createPost(collectUrl)
.header(CUSTOM_HEADER_NAME, CUSTOM_HEADER_VALUE)
.header("Content-Type", "application/json")
.body(jsonCollectInfo)
.execute();
// 打印响应结果
final String body = response.body();
log.info(body);
collectData = objectMapper.readValue(body, CollectData.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
final Long code = collectData.code;
if (code.equals(200)) {
log.info("收藏成功");
} else if (code.equals(400000101)) {
log.info("参数缺失");
} else if (code.equals(400)) {
COLLECT_IS_FULL = true;
log.info("今日收藏次数已达上限!");
}
}
@Override
public Boolean getArticleInfo(String articleId) {
String url = "https://blog.csdn.net/phoenix/web/v1/comment/list/" + articleId;
// 使用Hutool发送GET请求
HttpResponse response = HttpUtil.createPost(url)
.header(CUSTOM_HEADER_NAME, CUSTOM_HEADER_VALUE)
.form("page", 1)
.form("size", 100)
.form("fold", "unfold")
.execute();
// 打印响应结果
final String body = response.body();
ObjectMapper objectMapper = new ObjectMapper();
CommentData articleInfo = null;
try {
articleInfo = objectMapper.readValue(body, CommentData.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
final CommentData.DataInfo data = articleInfo.getData();
final List<CommentData.Comment> list = data.getList();
if (CollectionUtil.isNotEmpty(list)) {
for (CommentData.Comment comment : list) {
final CommentData.Info info = comment.getInfo();
final String userName = info.getUserName();
if (StringUtils.equals(userName, "qyj19920704")) {
//评论过
return true;
}
}
}
return false;
}
@Override
public void like(String articleId) {
}
@Override
public int comment(String articleId) {
String url = "https://blog.csdn.net/phoenix/web/v1/comment/submit";
// 使用Hutool发送GET请求
HttpResponse response = HttpUtil.createPost(url)
.header(CUSTOM_HEADER_NAME, CUSTOM_HEADER_VALUE) // 添加自定义header参数
.form("articleId", articleId)
.form("content", "支持博主优质文章,讲解得非常详细,干货满满,通俗易懂,期待博主下次更新")
.execute();
return response.getStatus();
}
@Override
......@@ -213,16 +90,7 @@ public class CsdnServiceImpl implements CsdnService {
final List<CsdnUserInfo> list = csdnUserInfoService.list();
if (CollectionUtil.isNotEmpty(list)) {
for (CsdnUserInfo csdnUserInfo : list) {
// 构建参数
String username = csdnUserInfo.getUserName();
final CsdnStatusResp csdnStatusResp = singleArticle(username);
final Integer code = csdnStatusResp.getCode();
final String value = csdnStatusResp.getValue();
if (code.equals(400)) {
log.info("用户{}:code={},{}", username, code, value);
break;
}
log.info("用户{}:{}", username, value);
singleArticle(csdnUserInfo.getUserName());
}
}
}
......
......@@ -45,4 +45,20 @@ spring:
# jasypt加密的密匙
jasypt:
encryptor:
password: Y6M9fAJQdU7jNp5MW
\ No newline at end of file
password: Y6M9fAJQdU7jNp5MW
csdn:
num_of_articles_per_person: 1 #每人文章个数
self_user_name: "qyj19920704" #自己的用户id
#cookie,身份验证
cookie: "uuid_tt_dd=10_20285116700-1697522872601-604163; c_adb=1; loginbox_strategy=%7B%22taskId%22%3A308%2C%22abCheckTime%22%3A1697522874474%2C%22version%22%3A%22control%22%7D; UserName=qyj19920704; UserInfo=a7d3b88c53a841ebb5792202cb43c84f; UserToken=a7d3b88c53a841ebb5792202cb43c84f; UserNick=%E6%AA%80%E8%B6%8A%E5%89%91%E6%8C%87%E5%A4%A7%E5%8E%82; AU=769; UN=qyj19920704; BT=1697522886100; p_uid=U010000; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22qyj19920704%22%2C%22scope%22%3A1%7D%7D; management_ques=1697592152734; blog_details_recommend_nps=1697616147423; c_segment=3; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1697522874,1697551027,1697636661,1697683407; csrfToken=jTRD3_1IBVA703lu2FkVkazx; dc_sid=9f7a02ed8375e91d86271ddaf1cf2ce4; c_first_ref=default; c_first_page=https%3A//liucy.blog.csdn.net/article/details/133852303%3Fspm%3D1001.2014.3001.5502; c_segment=3; Hm_lvt_e5ef47b9f471504959267fd614d579cd=1697764951; Hm_lpvt_e5ef47b9f471504959267fd614d579cd=1697764951; 404_page_nps=1697764955523; ssxmod_itna=YqUxBD97kOGHD8D2BmYite44zxcYo1=WOiox0vmvqGzDAxn40iDtgeqODDwu0/DNMQiDpiDuWOntaV73S5fd3iPeaN3D84i7DKqibDCqD1D3qDktzDYA8Dt4DTD34DYDiO=DBRsUQDFATN/3wUjmGtDG4DgDB=DxBEl3djBAq4DCr4DbxPy7mrDtLNSeLLdXT0/nn5Yf445SOG5lipwm0GdG7vwBA4PlDxNt8v1wADoGGGQYf+IE75ep753zpDxD; ssxmod_itna2=YqUxBD97kOGHD8D2BmYite44zxcYo1=WOYxn9EenDDsYebDLGQCoqQuGvHdDQRKYubdD6QqomsRD3xyRI/W9Q5nhe8oeYUvimaWYrNsqwcDgL6mDjYUhZK09LYcY/t5hSuP2va/kclf6hRkNh+LPyDwic73=9i4d94Lvw/R=oQ7E+jT4jjjA2Y+=QplLm8nbePRb+7=Re1CpjmZ4wIrnNPSKofWnIj=WOtkFtphylt+GhUxr0KkGtTzDXKDEEkbn3qhIn3Sj/ezt1u2MO3M9h7zEL6RunrXaKE+YdkRnIKiTG93cqpGFq8Fwr7ehksk1ZSWhoN2hQydddqQ1bTOSW8ddX+7g24v4TZ0+52=Y8PsOwfhavW4ECY8+GZOK=ro97bK0=Yi3YD5ZGsq25FhPodIRGCD2O8xidfo8+NR88v+rq4+b=fUOEK2frPEPdLFuYkao9uCfM1+cFZQ7q6HEMfRLjf6bhof0=1YhEYO1U=NZCPvDDw2Psluciq4De13mDNBODwqLwwg44qwOiDf=j1fKK5q+8gd7DDjKDeMv/04YDmLGvrwqOz4cov79500D4D==; c_first_ref=default; c_first_page=https%3A//mp.csdn.net/; creative_btn_mp=3; c_hasSub=true; write_guide_show=3; log_Id_click=177; dc_session_id=11_1698022100317.787671; c_dsid=11_1698022100317.794351; log_Id_pv=149; log_Id_view=1105; c_pref=https%3A//i.csdn.net/; c_ref=https%3A//blog.csdn.net/imwucx; c_page_id=default; dc_session_id=11_1698022100317.787671; c_dsid=11_1698022100317.794351; log_Id_view=1106; dc_tos=s2yi9b; log_Id_click=178; c_pref=https%3A//blog.csdn.net/imwucx; log_Id_pv=150; creativeSetApiNew=%7B%22toolbarImg%22%3Anull%2C%22publishSuccessImg%22%3Anull%2C%22articleNum%22%3A895%2C%22type%22%3A0%2C%22oldUser%22%3Afalse%2C%22useSeven%22%3Afalse%2C%22userName%22%3A%22qyj19920704%22%7D; c_ref=https%3A//cxian.blog.csdn.net/article/details/131299195; c_page_id=default; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1698022433; dc_tos=s2yinc"
url:
user_article_url: "https://blog.csdn.net/community/home-api/v1/get-business-list" #获取用户文章接口
is_collect_url: "https://blog.csdn.net/phoenix/web/v1/isCollect" #是否收藏接口
add_collect_url: "https://mp-action.csdn.net/interact/wrapper/pc/favorite/v1/api/addFavoriteInFolds" #添加收藏接口
is_comment_list_url: "https://blog.csdn.net/phoenix/web/v1/comment/list/" #查询评论接口
comment_url: "https://blog.csdn.net/phoenix/web/v1/comment/submit" #评论接口
like_url: "https://blog.csdn.net//phoenix/web/v1/article/like" #点赞接口
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册