Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
a83817bf
S
SpringBoot-kwan
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringBoot-kwan
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBoot-kwan
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
a83817bf
编写于
10月 23, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:点赞评论
上级
2fc342ca
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
101 addition
and
32 deletion
+101
-32
src/main/java/com/kwan/springbootkwan/entity/CsdnStatusResp.java
...n/java/com/kwan/springbootkwan/entity/CsdnStatusResp.java
+15
-0
src/main/java/com/kwan/springbootkwan/entity/resp/BusinessInfo.java
...ava/com/kwan/springbootkwan/entity/resp/BusinessInfo.java
+2
-0
src/main/java/com/kwan/springbootkwan/entity/resp/LikeData.java
...in/java/com/kwan/springbootkwan/entity/resp/LikeData.java
+11
-0
src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java
...n/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java
+2
-2
src/main/java/com/kwan/springbootkwan/service/CsdnService.java
...ain/java/com/kwan/springbootkwan/service/CsdnService.java
+5
-3
src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
...com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
+66
-27
未找到文件。
src/main/java/com/kwan/springbootkwan/entity/CsdnStatusResp.java
0 → 100644
浏览文件 @
a83817bf
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
;
}
src/main/java/com/kwan/springbootkwan/entity/resp/BusinessInfo.java
浏览文件 @
a83817bf
...
...
@@ -40,6 +40,8 @@ public class BusinessInfo {
public
Integer
viewCount
;
public
Object
expandTitle
;
public
Object
cover
;
public
Object
fileType
;
public
Object
content
;
}
}
...
...
src/main/java/com/kwan/springbootkwan/entity/resp/LikeData.java
0 → 100644
浏览文件 @
a83817bf
package
com.kwan.springbootkwan.entity.resp
;
import
lombok.Data
;
@Data
public
class
LikeData
{
public
int
code
;
public
String
message
;
public
String
traceId
;
public
Object
data
;
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java
浏览文件 @
a83817bf
...
...
@@ -8,14 +8,14 @@ import org.springframework.scheduling.annotation.Scheduled;
import
org.springframework.stereotype.Component
;
@Component
@Slf4j
@Component
public
class
CsdnSchedule
{
@Autowired
private
CsdnService
csdnService
;
@Scheduled
(
cron
=
"0 0
10,15,21
* * ?"
)
@Scheduled
(
cron
=
"0 0
6,8,10,12,14,16,18,20,22
* * ?"
)
public
void
execute
()
{
log
.
info
(
"Scheduled task is running ... ..."
);
csdnService
.
multiTriplet
();
...
...
src/main/java/com/kwan/springbootkwan/service/CsdnService.java
浏览文件 @
a83817bf
package
com.kwan.springbootkwan.service
;
import
com.kwan.springbootkwan.entity.CsdnStatusResp
;
/**
* csdn博客自动化
*
...
...
@@ -9,11 +11,11 @@ package com.kwan.springbootkwan.service;
*/
public
interface
CsdnService
{
/**
*
查询单篇文章信息
*
单人三连
*
* @return
*/
String
singleArticle
(
String
username
);
CsdnStatusResp
singleArticle
(
String
username
);
/**
* 查询是否评论过
...
...
@@ -35,7 +37,7 @@ public interface CsdnService {
*
* @param articleId
*/
void
comment
(
String
articleId
);
int
comment
(
String
articleId
);
/**
* 三连
...
...
src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
浏览文件 @
a83817bf
...
...
@@ -5,9 +5,11 @@ 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.CsdnStatusResp
;
import
com.kwan.springbootkwan.entity.CsdnUserInfo
;
import
com.kwan.springbootkwan.entity.resp.BusinessInfo
;
import
com.kwan.springbootkwan.entity.resp.CommentData
;
import
com.kwan.springbootkwan.entity.resp.LikeData
;
import
com.kwan.springbootkwan.service.CsdnService
;
import
com.kwan.springbootkwan.service.CsdnUserInfoService
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -25,6 +27,10 @@ public class CsdnServiceImpl implements CsdnService {
* 构建header参数
*/
private
static
final
String
CUSTOM_HEADER_NAME
=
"Cookie"
;
/**
* 点赞满了
*/
private
static
boolean
LIKE_IS_FULL
=
false
;
/**
* 参数值
*/
...
...
@@ -34,13 +40,13 @@ public class CsdnServiceImpl implements CsdnService {
private
CsdnUserInfoService
csdnUserInfoService
;
@Override
public
String
singleArticle
(
String
username
)
{
public
CsdnStatusResp
singleArticle
(
String
username
)
{
String
url
=
"https://blog.csdn.net/community/home-api/v1/get-business-list"
;
// 使用Hutool发送GET请求
HttpResponse
response
=
HttpUtil
.
createGet
(
url
)
.
header
(
CUSTOM_HEADER_NAME
,
CUSTOM_HEADER_VALUE
)
.
form
(
"page"
,
1
)
.
form
(
"size"
,
2
)
.
form
(
"size"
,
5
)
.
form
(
"businessType"
,
"lately"
)
.
form
(
"noMore"
,
false
)
.
form
(
"username"
,
username
)
...
...
@@ -56,23 +62,41 @@ public class CsdnServiceImpl implements CsdnService {
}
final
BusinessInfo
.
ArticleData
data
=
businessInfo
.
getData
();
final
List
<
BusinessInfo
.
ArticleData
.
Article
>
list
=
data
.
getList
();
final
BusinessInfo
.
ArticleData
.
Article
article
=
list
.
get
(
0
);
//处理评论过
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
))
{
return
"非博客不能评论"
;
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
(!
LIKE_IS_FULL
)
{
this
.
like
(
articleId
);
this
.
comment
(
articleId
);
return
"三连完成"
;
}
}
else
if
(
comment
==
400
)
{
return
new
CsdnStatusResp
(
400
,
"您评论太快了,请休息一下!"
);
}
}
else
{
return
"文章已经评论过,不能再次评论"
;
commentNum
++;
}
}
if
(
count
!=
successNum
)
{
return
new
CsdnStatusResp
(
300
,
"评论过的数量="
+
commentNum
+
"非博客的数量:"
+
notBlogNum
);
}
return
new
CsdnStatusResp
(
200
,
"三连完成"
);
}
@Override
...
...
@@ -118,13 +142,25 @@ public class CsdnServiceImpl implements CsdnService {
.
form
(
"articleId"
,
articleId
)
.
execute
();
// 打印响应结果
if
(
response
.
getStatus
()
==
200
)
{
final
String
body
=
response
.
body
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
LikeData
likeData
=
null
;
try
{
likeData
=
objectMapper
.
readValue
(
body
,
LikeData
.
class
);
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
}
final
int
code
=
likeData
.
code
;
if
(
code
==
200
)
{
log
.
info
(
"点赞成功"
);
}
else
if
(
code
==
400
)
{
LIKE_IS_FULL
=
true
;
log
.
info
(
"今日点赞次数已达上限!"
);
}
}
@Override
public
void
comment
(
String
articleId
)
{
public
int
comment
(
String
articleId
)
{
String
url
=
"https://blog.csdn.net/phoenix/web/v1/comment/submit"
;
// 使用Hutool发送GET请求
HttpResponse
response
=
HttpUtil
.
createPost
(
url
)
...
...
@@ -132,22 +168,25 @@ public class CsdnServiceImpl implements CsdnService {
.
form
(
"articleId"
,
articleId
)
.
form
(
"content"
,
"支持博主优质文章,讲解得非常详细,干货满满,通俗易懂,期待博主下次更新"
)
.
execute
();
// 打印响应结果
if
(
response
.
getStatus
()
==
200
)
{
log
.
info
(
"评论成功"
);
}
return
response
.
getStatus
();
}
@Override
public
void
multiTriplet
()
{
final
List
<
CsdnUserInfo
>
list
=
csdnUserInfoService
.
list
();
if
(
CollectionUtil
.
isNotEmpty
(
list
))
{
list
.
forEach
(
csdnUserInfo
->
{
for
(
CsdnUserInfo
csdnUserInfo
:
list
)
{
// 构建参数
String
username
=
csdnUserInfo
.
getUserName
();
final
String
res
=
singleArticle
(
username
);
log
.
info
(
"用户{}:{}"
,
username
,
res
);
});
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
);
}
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录