Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
a06f5077
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看板
提交
a06f5077
编写于
10月 24, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:点赞接口完成
上级
4408b001
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
189 addition
and
26 deletion
+189
-26
src/main/java/com/kwan/springbootkwan/controller/CsdnController.java
...va/com/kwan/springbootkwan/controller/CsdnController.java
+9
-0
src/main/java/com/kwan/springbootkwan/entity/resp/BusinessInfo.java
...ava/com/kwan/springbootkwan/entity/resp/BusinessInfo.java
+1
-1
src/main/java/com/kwan/springbootkwan/entity/resp/CollectData.java
...java/com/kwan/springbootkwan/entity/resp/CollectData.java
+11
-0
src/main/java/com/kwan/springbootkwan/entity/resp/CollectInfo.java
...java/com/kwan/springbootkwan/entity/resp/CollectInfo.java
+18
-0
src/main/java/com/kwan/springbootkwan/entity/resp/LikeData.java
...in/java/com/kwan/springbootkwan/entity/resp/LikeData.java
+9
-1
src/main/java/com/kwan/springbootkwan/service/CsdnLikeService.java
...java/com/kwan/springbootkwan/service/CsdnLikeService.java
+18
-0
src/main/java/com/kwan/springbootkwan/service/impl/CsdnLikeServiceImpl.java
...kwan/springbootkwan/service/impl/CsdnLikeServiceImpl.java
+62
-0
src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
...com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
+61
-24
未找到文件。
src/main/java/com/kwan/springbootkwan/controller/CsdnController.java
浏览文件 @
a06f5077
package
com.kwan.springbootkwan.controller
;
package
com.kwan.springbootkwan.controller
;
import
com.kwan.springbootkwan.entity.Result
;
import
com.kwan.springbootkwan.entity.Result
;
import
com.kwan.springbootkwan.service.CsdnLikeService
;
import
com.kwan.springbootkwan.service.CsdnService
;
import
com.kwan.springbootkwan.service.CsdnService
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -17,6 +18,14 @@ public class CsdnController {
...
@@ -17,6 +18,14 @@ public class CsdnController {
@Autowired
@Autowired
private
CsdnService
csdnService
;
private
CsdnService
csdnService
;
@Autowired
private
CsdnLikeService
csdnLikeService
;
@ApiOperation
(
value
=
"单人点赞"
,
notes
=
"单人点赞"
)
@GetMapping
(
"/singleLike"
)
public
Result
singleLike
(
@Param
(
"articleId"
)
String
articleId
)
{
return
Result
.
ok
(
csdnLikeService
.
like
(
articleId
));
}
@ApiOperation
(
value
=
"单人三连"
,
notes
=
"单人三连"
)
@ApiOperation
(
value
=
"单人三连"
,
notes
=
"单人三连"
)
@GetMapping
(
"/singleTriplet"
)
@GetMapping
(
"/singleTriplet"
)
...
...
src/main/java/com/kwan/springbootkwan/entity/resp/BusinessInfo.java
浏览文件 @
a06f5077
...
@@ -23,7 +23,7 @@ public class BusinessInfo {
...
@@ -23,7 +23,7 @@ public class BusinessInfo {
public
static
class
Article
{
public
static
class
Article
{
public
String
formatTime
;
public
String
formatTime
;
public
Integer
collectCount
;
public
Integer
collectCount
;
public
Integer
source
;
public
String
source
;
public
String
description
;
public
String
description
;
public
Integer
diggCount
;
public
Integer
diggCount
;
public
String
type
;
public
String
type
;
...
...
src/main/java/com/kwan/springbootkwan/entity/resp/CollectData.java
0 → 100644
浏览文件 @
a06f5077
package
com.kwan.springbootkwan.entity.resp
;
import
lombok.Data
;
@Data
public
class
CollectData
{
public
Long
code
;
public
String
msg
;
public
String
total
;
public
Object
data
;
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/entity/resp/CollectInfo.java
0 → 100644
浏览文件 @
a06f5077
package
com.kwan.springbootkwan.entity.resp
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
CollectInfo
{
private
Integer
sourceId
;
private
String
fromType
;
private
String
author
;
private
String
description
;
private
String
source
;
private
List
<
Integer
>
folderIdList
;
private
String
title
;
private
String
url
;
private
String
username
;
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/entity/resp/LikeData.java
浏览文件 @
a06f5077
package
com.kwan.springbootkwan.entity.resp
;
package
com.kwan.springbootkwan.entity.resp
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
lombok.Data
;
@Data
@Data
...
@@ -7,5 +8,12 @@ public class LikeData {
...
@@ -7,5 +8,12 @@ public class LikeData {
public
int
code
;
public
int
code
;
public
String
message
;
public
String
message
;
public
String
traceId
;
public
String
traceId
;
public
Object
data
;
public
LikeDataDetail
data
;
@Data
public
static
class
LikeDataDetail
{
@JsonProperty
(
"like_num"
)
public
int
likeNum
;
public
boolean
status
;
}
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/service/CsdnLikeService.java
0 → 100644
浏览文件 @
a06f5077
package
com.kwan.springbootkwan.service
;
/**
* 点赞
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/10/24 00:19
*/
public
interface
CsdnLikeService
{
/**
* 是否点过赞,true,点过,false,没有点过
*
* @return
*/
Boolean
like
(
String
articleId
);
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/service/impl/CsdnLikeServiceImpl.java
0 → 100644
浏览文件 @
a06f5077
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.kwan.springbootkwan.entity.resp.LikeData
;
import
com.kwan.springbootkwan.service.CsdnLikeService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
@Slf4j
@Service
public
class
CsdnLikeServiceImpl
implements
CsdnLikeService
{
/**
* 构建header参数
*/
private
static
final
String
CUSTOM_HEADER_NAME
=
"Cookie"
;
/**
* 点赞满了
*/
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
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
)
.
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
();
if
(
code
==
200
)
{
final
boolean
status
=
data
.
status
;
if
(
status
)
{
log
.
info
(
"点赞成功"
);
}
else
{
log
.
info
(
"点赞取消"
);
}
return
status
;
}
else
if
(
code
==
400
)
{
LIKE_IS_FULL
=
true
;
log
.
info
(
"今日点赞次数已达上限!"
);
}
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
}
return
true
;
}
}
src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
浏览文件 @
a06f5077
...
@@ -5,11 +5,13 @@ import cn.hutool.http.HttpResponse;
...
@@ -5,11 +5,13 @@ 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.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.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.CommentData
;
import
com.kwan.springbootkwan.entity.resp.LikeData
;
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
;
...
@@ -31,6 +33,10 @@ public class CsdnServiceImpl implements CsdnService {
...
@@ -31,6 +33,10 @@ public class CsdnServiceImpl implements CsdnService {
* 点赞满了
* 点赞满了
*/
*/
private
static
boolean
LIKE_IS_FULL
=
false
;
private
static
boolean
LIKE_IS_FULL
=
false
;
/**
* 收藏满了
*/
private
static
boolean
COLLECT_IS_FULL
=
false
;
/**
/**
* 参数值
* 参数值
*/
*/
...
@@ -83,6 +89,9 @@ public class CsdnServiceImpl implements CsdnService {
...
@@ -83,6 +89,9 @@ public class CsdnServiceImpl implements CsdnService {
// 打印响应结果
// 打印响应结果
if
(
comment
==
200
)
{
if
(
comment
==
200
)
{
successNum
++;
successNum
++;
if
(!
COLLECT_IS_FULL
)
{
this
.
collect
(
username
,
article
,
articleId
);
}
if
(!
LIKE_IS_FULL
)
{
if
(!
LIKE_IS_FULL
)
{
this
.
like
(
articleId
);
this
.
like
(
articleId
);
}
}
...
@@ -99,12 +108,61 @@ public class CsdnServiceImpl implements CsdnService {
...
@@ -99,12 +108,61 @@ public class CsdnServiceImpl implements CsdnService {
return
new
CsdnStatusResp
(
200
,
"三连完成"
);
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
@Override
public
Boolean
getArticleInfo
(
String
articleId
)
{
public
Boolean
getArticleInfo
(
String
articleId
)
{
String
url
=
"https://blog.csdn.net/phoenix/web/v1/comment/list/"
+
articleId
;
String
url
=
"https://blog.csdn.net/phoenix/web/v1/comment/list/"
+
articleId
;
// 使用Hutool发送GET请求
// 使用Hutool发送GET请求
HttpResponse
response
=
HttpUtil
.
createPost
(
url
)
HttpResponse
response
=
HttpUtil
.
createPost
(
url
)
.
header
(
CUSTOM_HEADER_NAME
,
CUSTOM_HEADER_VALUE
)
// 添加自定义header参数
.
header
(
CUSTOM_HEADER_NAME
,
CUSTOM_HEADER_VALUE
)
.
form
(
"page"
,
1
)
.
form
(
"page"
,
1
)
.
form
(
"size"
,
100
)
.
form
(
"size"
,
100
)
.
form
(
"fold"
,
"unfold"
)
.
form
(
"fold"
,
"unfold"
)
...
@@ -135,28 +193,7 @@ public class CsdnServiceImpl implements CsdnService {
...
@@ -135,28 +193,7 @@ public class CsdnServiceImpl implements CsdnService {
@Override
@Override
public
void
like
(
String
articleId
)
{
public
void
like
(
String
articleId
)
{
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参数
.
form
(
"articleId"
,
articleId
)
.
execute
();
// 打印响应结果
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
@Override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录