fix:评论限制规避

上级 f7f69bac
......@@ -26,6 +26,14 @@ public enum CommentStatus {
* 评论太快
*/
COMMENT_TOO_FAST(4, "评论太快"),
/**
* 评论已经到了49条
*/
COMMENT_NUM_49(5, "评论已经到了49条"),
/**
* 其他错误
*/
OTHER_ERRORS(8, "其他错误"),
/**
* 评论成功
*/
......
......@@ -95,9 +95,17 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
} else if (code == 400 && message.contains("因存在恶意评论嫌疑,您的账号已被禁言")) {
log.info("因存在恶意评论嫌疑,您的账号已被禁言");
csdnUserInfo.setCommentStatus(CommentStatus.RESTRICTED_COMMENTS.getCode());
} else {
} else if (code == 400 && StringUtils.equals(message, "您评论太快了,请休息一下!")) {
log.info("您评论太快了,请休息一下!");
csdnUserInfo.setCommentStatus(CommentStatus.COMMENT_TOO_FAST.getCode());
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
log.info("其他错误");
csdnUserInfo.setCommentStatus(CommentStatus.OTHER_ERRORS.getCode());
}
return true;
}
......
......@@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
import com.kwan.springbootkwan.enums.CommentStatus;
import com.kwan.springbootkwan.service.CsdnCollectService;
import com.kwan.springbootkwan.service.CsdnCommentService;
import com.kwan.springbootkwan.service.CsdnLikeService;
......@@ -62,11 +63,22 @@ public class CsdnServiceImpl implements CsdnService {
if (!isLike) {
csdnLikeService.like(articleId, csdnUserInfo);
}
//查看已经评论总数量
QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
wrapper.eq("is_delete", 0);
wrapper.eq("comment_status", 9);
final List<CsdnUserInfo> comments = csdnUserInfoService.list(wrapper);
if (CollectionUtil.isNotEmpty(comments)) {
if (comments.size() >= 49) {
csdnUserInfo.setCommentStatus(CommentStatus.COMMENT_NUM_49.getCode());
} else {
//评论
final Boolean comment = csdnCommentService.isComment(article, csdnUserInfo);
if (!comment) {
csdnCommentService.comment(articleId, csdnUserInfo);
}
}
}
//收藏
final Boolean collect = csdnCollectService.isCollect(articleId, csdnUserInfo);
if (!collect) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册