Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
b0934336
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看板
提交
b0934336
编写于
10月 24, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:优化
上级
a06f5077
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
406 addition
and
243 deletion
+406
-243
src/main/java/com/kwan/springbootkwan/controller/CsdnController.java
...va/com/kwan/springbootkwan/controller/CsdnController.java
+2
-1
src/main/java/com/kwan/springbootkwan/entity/CsdnStatusResp.java
...n/java/com/kwan/springbootkwan/entity/CsdnStatusResp.java
+0
-15
src/main/java/com/kwan/springbootkwan/entity/resp/BusinessInfoResponse.java
...kwan/springbootkwan/entity/resp/BusinessInfoResponse.java
+7
-7
src/main/java/com/kwan/springbootkwan/entity/resp/CollectInfoQuery.java
...com/kwan/springbootkwan/entity/resp/CollectInfoQuery.java
+1
-1
src/main/java/com/kwan/springbootkwan/entity/resp/CollectResponse.java
.../com/kwan/springbootkwan/entity/resp/CollectResponse.java
+1
-1
src/main/java/com/kwan/springbootkwan/entity/resp/CommentListResponse.java
.../kwan/springbootkwan/entity/resp/CommentListResponse.java
+1
-1
src/main/java/com/kwan/springbootkwan/entity/resp/CommentResponse.java
.../com/kwan/springbootkwan/entity/resp/CommentResponse.java
+11
-0
src/main/java/com/kwan/springbootkwan/entity/resp/IsCollectResponse.java
...om/kwan/springbootkwan/entity/resp/IsCollectResponse.java
+17
-0
src/main/java/com/kwan/springbootkwan/entity/resp/LikeResponse.java
...ava/com/kwan/springbootkwan/entity/resp/LikeResponse.java
+1
-1
src/main/java/com/kwan/springbootkwan/service/CsdnCollectService.java
...a/com/kwan/springbootkwan/service/CsdnCollectService.java
+28
-0
src/main/java/com/kwan/springbootkwan/service/CsdnCommentService.java
...a/com/kwan/springbootkwan/service/CsdnCommentService.java
+27
-0
src/main/java/com/kwan/springbootkwan/service/CsdnLikeService.java
...java/com/kwan/springbootkwan/service/CsdnLikeService.java
+10
-1
src/main/java/com/kwan/springbootkwan/service/CsdnService.java
...ain/java/com/kwan/springbootkwan/service/CsdnService.java
+3
-26
src/main/java/com/kwan/springbootkwan/service/impl/CsdnCollectServiceImpl.java
...n/springbootkwan/service/impl/CsdnCollectServiceImpl.java
+107
-0
src/main/java/com/kwan/springbootkwan/service/impl/CsdnCommentServiceImpl.java
...n/springbootkwan/service/impl/CsdnCommentServiceImpl.java
+117
-0
src/main/java/com/kwan/springbootkwan/service/impl/CsdnLikeServiceImpl.java
...kwan/springbootkwan/service/impl/CsdnLikeServiceImpl.java
+14
-14
src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
...com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
+42
-174
src/main/resources/application-local.yml
src/main/resources/application-local.yml
+17
-1
未找到文件。
src/main/java/com/kwan/springbootkwan/controller/CsdnController.java
浏览文件 @
b0934336
...
@@ -30,7 +30,8 @@ public class CsdnController {
...
@@ -30,7 +30,8 @@ public class CsdnController {
@ApiOperation
(
value
=
"单人三连"
,
notes
=
"单人三连"
)
@ApiOperation
(
value
=
"单人三连"
,
notes
=
"单人三连"
)
@GetMapping
(
"/singleTriplet"
)
@GetMapping
(
"/singleTriplet"
)
public
Result
singleTriplet
(
@Param
(
"username"
)
String
username
)
{
public
Result
singleTriplet
(
@Param
(
"username"
)
String
username
)
{
return
Result
.
ok
(
csdnService
.
singleArticle
(
username
));
csdnService
.
singleArticle
(
username
);
return
Result
.
ok
(
"三连完成"
);
}
}
@ApiOperation
(
value
=
"多人三连"
,
notes
=
"多人三连"
)
@ApiOperation
(
value
=
"多人三连"
,
notes
=
"多人三连"
)
...
...
src/main/java/com/kwan/springbootkwan/entity/CsdnStatusResp.java
已删除
100644 → 0
浏览文件 @
a06f5077
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
→
src/main/java/com/kwan/springbootkwan/entity/resp/BusinessInfo
Response
.java
浏览文件 @
b0934336
...
@@ -7,7 +7,7 @@ import lombok.Data;
...
@@ -7,7 +7,7 @@ import lombok.Data;
import
java.util.List
;
import
java.util.List
;
@Data
@Data
public
class
BusinessInfo
{
public
class
BusinessInfo
Response
{
private
String
traceId
;
private
String
traceId
;
private
Integer
code
;
private
Integer
code
;
...
@@ -48,16 +48,16 @@ public class BusinessInfo {
...
@@ -48,16 +48,16 @@ public class BusinessInfo {
public
static
void
main
(
String
[]
args
)
{
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}}"
;
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
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
BusinessInfo
businessInfo
=
null
;
BusinessInfo
Response
businessInfoResponse
=
null
;
try
{
try
{
businessInfo
=
objectMapper
.
readValue
(
body
,
BusinessInfo
.
class
);
businessInfo
Response
=
objectMapper
.
readValue
(
body
,
BusinessInfoResponse
.
class
);
System
.
out
.
println
(
businessInfo
);
System
.
out
.
println
(
businessInfo
Response
);
}
catch
(
JsonProcessingException
e
)
{
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
final
BusinessInfo
.
ArticleData
data
=
businessInfo
.
getData
();
final
BusinessInfo
Response
.
ArticleData
data
=
businessInfoResponse
.
getData
();
final
List
<
BusinessInfo
.
ArticleData
.
Article
>
list
=
data
.
getList
();
final
List
<
BusinessInfo
Response
.
ArticleData
.
Article
>
list
=
data
.
getList
();
final
BusinessInfo
.
ArticleData
.
Article
article
=
list
.
get
(
0
);
final
BusinessInfo
Response
.
ArticleData
.
Article
article
=
list
.
get
(
0
);
final
String
type
=
article
.
getType
();
final
String
type
=
article
.
getType
();
final
String
urlInfo
=
article
.
getUrl
();
final
String
urlInfo
=
article
.
getUrl
();
System
.
out
.
println
(
type
);
System
.
out
.
println
(
type
);
...
...
src/main/java/com/kwan/springbootkwan/entity/resp/CollectInfo.java
→
src/main/java/com/kwan/springbootkwan/entity/resp/CollectInfo
Query
.java
浏览文件 @
b0934336
...
@@ -5,7 +5,7 @@ import lombok.Data;
...
@@ -5,7 +5,7 @@ import lombok.Data;
import
java.util.List
;
import
java.util.List
;
@Data
@Data
public
class
CollectInfo
{
public
class
CollectInfo
Query
{
private
Integer
sourceId
;
private
Integer
sourceId
;
private
String
fromType
;
private
String
fromType
;
private
String
author
;
private
String
author
;
...
...
src/main/java/com/kwan/springbootkwan/entity/resp/Collect
Data
.java
→
src/main/java/com/kwan/springbootkwan/entity/resp/Collect
Response
.java
浏览文件 @
b0934336
...
@@ -3,7 +3,7 @@ package com.kwan.springbootkwan.entity.resp;
...
@@ -3,7 +3,7 @@ package com.kwan.springbootkwan.entity.resp;
import
lombok.Data
;
import
lombok.Data
;
@Data
@Data
public
class
Collect
Data
{
public
class
Collect
Response
{
public
Long
code
;
public
Long
code
;
public
String
msg
;
public
String
msg
;
public
String
total
;
public
String
total
;
...
...
src/main/java/com/kwan/springbootkwan/entity/resp/Comment
Data
.java
→
src/main/java/com/kwan/springbootkwan/entity/resp/Comment
ListResponse
.java
浏览文件 @
b0934336
...
@@ -5,7 +5,7 @@ import lombok.Data;
...
@@ -5,7 +5,7 @@ import lombok.Data;
import
java.util.List
;
import
java.util.List
;
@Data
@Data
public
class
Comment
Data
{
public
class
Comment
ListResponse
{
public
int
code
;
public
int
code
;
public
String
message
;
public
String
message
;
public
String
traceId
;
public
String
traceId
;
...
...
src/main/java/com/kwan/springbootkwan/entity/resp/CommentResponse.java
0 → 100644
浏览文件 @
b0934336
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
src/main/java/com/kwan/springbootkwan/entity/resp/IsCollectResponse.java
0 → 100644
浏览文件 @
b0934336
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
src/main/java/com/kwan/springbootkwan/entity/resp/Like
Data
.java
→
src/main/java/com/kwan/springbootkwan/entity/resp/Like
Response
.java
浏览文件 @
b0934336
...
@@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
...
@@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import
lombok.Data
;
import
lombok.Data
;
@Data
@Data
public
class
Like
Data
{
public
class
Like
Response
{
public
int
code
;
public
int
code
;
public
String
message
;
public
String
message
;
public
String
traceId
;
public
String
traceId
;
...
...
src/main/java/com/kwan/springbootkwan/service/CsdnCollectService.java
0 → 100644
浏览文件 @
b0934336
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
src/main/java/com/kwan/springbootkwan/service/CsdnCommentService.java
0 → 100644
浏览文件 @
b0934336
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
src/main/java/com/kwan/springbootkwan/service/CsdnLikeService.java
浏览文件 @
b0934336
...
@@ -9,8 +9,17 @@ package com.kwan.springbootkwan.service;
...
@@ -9,8 +9,17 @@ package com.kwan.springbootkwan.service;
* @date : 2023/10/24 00:19
* @date : 2023/10/24 00:19
*/
*/
public
interface
CsdnLikeService
{
public
interface
CsdnLikeService
{
/**
* 查询是否点过赞
* todo:还未找到接口,搁浅
*
* @return
*/
Boolean
islike
(
String
articleId
);
/**
/**
*
是否点过赞
,true,点过,false,没有点过
*
点赞和取消点赞接口
,true,点过,false,没有点过
*
*
* @return
* @return
*/
*/
...
...
src/main/java/com/kwan/springbootkwan/service/CsdnService.java
浏览文件 @
b0934336
package
com.kwan.springbootkwan.service
;
package
com.kwan.springbootkwan.service
;
import
com.kwan.springbootkwan.entity.CsdnStatusResp
;
/**
/**
* csdn博客自动化
* csdn博客自动化
*
*
...
@@ -10,37 +8,16 @@ import com.kwan.springbootkwan.entity.CsdnStatusResp;
...
@@ -10,37 +8,16 @@ import com.kwan.springbootkwan.entity.CsdnStatusResp;
* @date : 2023/10/23 14:59
* @date : 2023/10/23 14:59
*/
*/
public
interface
CsdnService
{
public
interface
CsdnService
{
/**
* 单人三连
*
* @return
*/
CsdnStatusResp
singleArticle
(
String
username
);
/**
/**
*
查询是否评论过
*
单人三连
*
*
* @param articleId
* @return
* @return
*/
*/
Boolean
getArticleInfo
(
String
articleId
);
void
singleArticle
(
String
username
);
/**
* 点赞
*
* @param articleId
*/
void
like
(
String
articleId
);
/**
* 评论
*
* @param articleId
*/
int
comment
(
String
articleId
);
/**
/**
* 三连
*
多人
三连
*/
*/
void
multiTriplet
();
void
multiTriplet
();
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/service/impl/CsdnCollectServiceImpl.java
0 → 100644
浏览文件 @
b0934336
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
src/main/java/com/kwan/springbootkwan/service/impl/CsdnCommentServiceImpl.java
0 → 100644
浏览文件 @
b0934336
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
src/main/java/com/kwan/springbootkwan/service/impl/CsdnLikeServiceImpl.java
浏览文件 @
b0934336
...
@@ -4,44 +4,44 @@ import cn.hutool.http.HttpResponse;
...
@@ -4,44 +4,44 @@ import cn.hutool.http.HttpResponse;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.http.HttpUtil
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.kwan.springbootkwan.entity.resp.Like
Data
;
import
com.kwan.springbootkwan.entity.resp.Like
Response
;
import
com.kwan.springbootkwan.service.CsdnLikeService
;
import
com.kwan.springbootkwan.service.CsdnLikeService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
@Slf4j
@Slf4j
@Service
@Service
public
class
CsdnLikeServiceImpl
implements
CsdnLikeService
{
public
class
CsdnLikeServiceImpl
implements
CsdnLikeService
{
/**
@Value
(
"${csdn.cookie}"
)
* 构建header参数
private
String
csdnCookie
;
*/
@Value
(
"${csdn.url.like_url}"
)
private
static
final
String
CUSTOM_HEADER_NAME
=
"Cookie"
;
private
String
url
;
/**
/**
* 点赞满了
* 点赞满了
*/
*/
private
static
boolean
LIKE_IS_FULL
=
false
;
private
static
boolean
LIKE_IS_FULL
=
false
;
/**
* 参数值
@Override
*/
public
Boolean
islike
(
String
articleId
)
{
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"
;
return
true
;
}
@Override
@Override
public
Boolean
like
(
String
articleId
)
{
public
Boolean
like
(
String
articleId
)
{
if
(
LIKE_IS_FULL
)
{
if
(
LIKE_IS_FULL
)
{
return
true
;
return
true
;
}
}
String
url
=
"https://blog.csdn.net//phoenix/web/v1/article/like"
;
// 使用Hutool发送GET请求
HttpResponse
response
=
HttpUtil
.
createPost
(
url
)
HttpResponse
response
=
HttpUtil
.
createPost
(
url
)
.
header
(
CUSTOM_HEADER_NAME
,
CUSTOM_HEADER_VALUE
)
.
header
(
"Cookie"
,
csdnCookie
)
.
form
(
"articleId"
,
articleId
)
.
form
(
"articleId"
,
articleId
)
.
execute
();
.
execute
();
final
String
body
=
response
.
body
();
final
String
body
=
response
.
body
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
try
{
try
{
final
int
code
=
objectMapper
.
readValue
(
body
,
Like
Data
.
class
).
code
;
final
int
code
=
objectMapper
.
readValue
(
body
,
Like
Response
.
class
).
code
;
final
Like
Data
.
LikeDataDetail
data
=
objectMapper
.
readValue
(
body
,
LikeData
.
class
).
getData
();
final
Like
Response
.
LikeDataDetail
data
=
objectMapper
.
readValue
(
body
,
LikeResponse
.
class
).
getData
();
if
(
code
==
200
)
{
if
(
code
==
200
)
{
final
boolean
status
=
data
.
status
;
final
boolean
status
=
data
.
status
;
if
(
status
)
{
if
(
status
)
{
...
...
src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
浏览文件 @
b0934336
...
@@ -5,18 +5,16 @@ import cn.hutool.http.HttpResponse;
...
@@ -5,18 +5,16 @@ import cn.hutool.http.HttpResponse;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.http.HttpUtil
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
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.CsdnUserInfo
;
import
com.kwan.springbootkwan.entity.resp.BusinessInfo
;
import
com.kwan.springbootkwan.entity.resp.BusinessInfoResponse
;
import
com.kwan.springbootkwan.entity.resp.CollectData
;
import
com.kwan.springbootkwan.service.CsdnCollectService
;
import
com.kwan.springbootkwan.entity.resp.CollectInfo
;
import
com.kwan.springbootkwan.service.CsdnCommentService
;
import
com.kwan.springbootkwan.entity.resp.CommentData
;
import
com.kwan.springbootkwan.service.CsdnService
;
import
com.kwan.springbootkwan.service.CsdnService
;
import
com.kwan.springbootkwan.service.CsdnUserInfoService
;
import
com.kwan.springbootkwan.service.CsdnUserInfoService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.List
;
...
@@ -25,187 +23,66 @@ import java.util.List;
...
@@ -25,187 +23,66 @@ import java.util.List;
@Slf4j
@Slf4j
@Service
@Service
public
class
CsdnServiceImpl
implements
CsdnService
{
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
@Autowired
private
CsdnUserInfoService
csdnUserInfoService
;
private
CsdnUserInfoService
csdnUserInfoService
;
@Autowired
private
CsdnCollectService
csdnCollectService
;
@Autowired
private
CsdnCommentService
csdnCommentService
;
@Override
@Override
public
CsdnStatusResp
singleArticle
(
String
username
)
{
public
void
singleArticle
(
String
username
)
{
String
url
=
"https://blog.csdn.net/community/home-api/v1/get-business-list"
;
// 使用Hutool发送GET请求
HttpResponse
response
=
HttpUtil
.
createGet
(
url
)
HttpResponse
response
=
HttpUtil
.
createGet
(
url
)
.
header
(
CUSTOM_HEADER_NAME
,
CUSTOM_HEADER_VALUE
)
.
header
(
"Cookie"
,
csdnCookie
)
.
form
(
"page"
,
1
)
.
form
(
"page"
,
1
)
.
form
(
"size"
,
5
)
.
form
(
"size"
,
5
)
.
form
(
"businessType"
,
"lately"
)
.
form
(
"businessType"
,
"lately"
)
.
form
(
"noMore"
,
false
)
.
form
(
"noMore"
,
false
)
.
form
(
"username"
,
username
)
.
form
(
"username"
,
username
)
.
execute
();
.
execute
();
// 打印响应结果
final
String
body
=
response
.
body
();
final
String
body
=
response
.
body
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
BusinessInfo
businessInfo
=
null
;
BusinessInfo
Response
businessInfoResponse
;
try
{
try
{
businessInfo
=
objectMapper
.
readValue
(
body
,
BusinessInfo
.
class
);
businessInfoResponse
=
objectMapper
.
readValue
(
body
,
BusinessInfoResponse
.
class
);
}
catch
(
JsonProcessingException
e
)
{
final
BusinessInfoResponse
.
ArticleData
data
=
businessInfoResponse
.
getData
();
e
.
printStackTrace
();
final
List
<
BusinessInfoResponse
.
ArticleData
.
Article
>
list
=
data
.
getList
();
}
if
(
CollectionUtil
.
isNotEmpty
(
list
))
{
final
BusinessInfo
.
ArticleData
data
=
businessInfo
.
getData
();
final
int
size
=
list
.
size
();
final
List
<
BusinessInfo
.
ArticleData
.
Article
>
list
=
data
.
getList
();
if
(
size
<
numOfArticlesPerPerson
)
{
//处理评论过
numOfArticlesPerPerson
=
size
;
int
commentNum
=
0
;
}
int
successNum
=
0
;
for
(
int
i
=
0
;
i
<
numOfArticlesPerPerson
;
i
++)
{
int
notBlogNum
=
0
;
final
BusinessInfoResponse
.
ArticleData
.
Article
article
=
list
.
get
(
i
);
int
count
=
3
;
//评论3篇
final
String
type
=
article
.
getType
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
if
(!
StringUtils
.
equals
(
"blog"
,
type
))
{
final
BusinessInfo
.
ArticleData
.
Article
article
=
list
.
get
(
i
);
continue
;
final
String
type
=
article
.
getType
();
}
if
(!
StringUtils
.
equals
(
"blog"
,
type
))
{
final
String
urlInfo
=
article
.
getUrl
();
notBlogNum
++;
String
articleId
=
urlInfo
.
substring
(
urlInfo
.
lastIndexOf
(
"/"
)
+
1
);
continue
;
//评论
}
final
Boolean
comment
=
csdnCommentService
.
isComment
(
article
);
final
String
urlInfo
=
article
.
getUrl
();
if
(!
comment
)
{
String
articleId
=
urlInfo
.
substring
(
urlInfo
.
lastIndexOf
(
"/"
)
+
1
);
csdnCommentService
.
comment
(
articleId
);
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
);
}
}
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
)
{
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
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
@Override
...
@@ -213,16 +90,7 @@ public class CsdnServiceImpl implements CsdnService {
...
@@ -213,16 +90,7 @@ public class CsdnServiceImpl implements CsdnService {
final
List
<
CsdnUserInfo
>
list
=
csdnUserInfoService
.
list
();
final
List
<
CsdnUserInfo
>
list
=
csdnUserInfoService
.
list
();
if
(
CollectionUtil
.
isNotEmpty
(
list
))
{
if
(
CollectionUtil
.
isNotEmpty
(
list
))
{
for
(
CsdnUserInfo
csdnUserInfo
:
list
)
{
for
(
CsdnUserInfo
csdnUserInfo
:
list
)
{
// 构建参数
singleArticle
(
csdnUserInfo
.
getUserName
());
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
);
}
}
}
}
}
}
...
...
src/main/resources/application-local.yml
浏览文件 @
b0934336
...
@@ -45,4 +45,20 @@ spring:
...
@@ -45,4 +45,20 @@ spring:
# jasypt加密的密匙
# jasypt加密的密匙
jasypt
:
jasypt
:
encryptor
:
encryptor
:
password
:
Y6M9fAJQdU7jNp5MW
password
:
Y6M9fAJQdU7jNp5MW
\ No newline at end of file
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录