From c04c3d8549c72e75c2f21ee54ab12c339ffea9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=82=85=E5=93=A5?= <184172133@qq.com> Date: Thu, 19 Jan 2023 12:54:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E5=82=85=E5=93=A5=EF=BC=8Cfeat?= =?UTF-8?q?=EF=BC=9A=E7=AC=AC3=E8=8A=82=EF=BC=9A=E7=9F=A5=E8=AF=86?= =?UTF-8?q?=E6=98=9F=E7=90=83API=E8=B0=83=E7=94=A8=EF=BC=8C=E9=A2=86?= =?UTF-8?q?=E5=9F=9F=E6=9C=8D=E5=8A=A1=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chatbot-api-domain/pom.xml | 38 ++++++ .../chatbot/api/domain/zsxq/IZsxqApi.java | 22 ++++ .../UnAnsweredQuestionsAggregates.java | 32 +++++ .../api/domain/zsxq/model/req/AnswerReq.java | 25 ++++ .../api/domain/zsxq/model/req/ReqData.java | 43 ++++++ .../api/domain/zsxq/model/res/AnswerRes.java | 21 +++ .../api/domain/zsxq/model/res/RespData.java | 25 ++++ .../api/domain/zsxq/model/vo/Group.java | 36 +++++ .../api/domain/zsxq/model/vo/Owner.java | 44 +++++++ .../api/domain/zsxq/model/vo/OwnerDetail.java | 28 ++++ .../api/domain/zsxq/model/vo/Question.java | 68 ++++++++++ .../api/domain/zsxq/model/vo/Questionee.java | 52 ++++++++ .../api/domain/zsxq/model/vo/Topics.java | 124 ++++++++++++++++++ .../domain/zsxq/model/vo/UserSpecific.java | 28 ++++ .../api/domain/zsxq/service/ZsxqApi.java | 92 +++++++++++++ chatbot-api-interfaces/pom.xml | 6 + .../src/main/resources/application.yml | 6 +- .../chatbot/api/test/SpringBootRunTest.java | 55 ++++++++ 18 files changed, 744 insertions(+), 1 deletion(-) create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/IZsxqApi.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/aggregates/UnAnsweredQuestionsAggregates.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/req/AnswerReq.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/req/ReqData.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/res/AnswerRes.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/res/RespData.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Group.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Owner.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/OwnerDetail.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Question.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Questionee.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Topics.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/UserSpecific.java create mode 100644 chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/service/ZsxqApi.java create mode 100644 chatbot-api-interfaces/src/test/java/cn/bugstack/chatbot/api/test/SpringBootRunTest.java diff --git a/chatbot-api-domain/pom.xml b/chatbot-api-domain/pom.xml index 14c44bb..c47ed4f 100644 --- a/chatbot-api-domain/pom.xml +++ b/chatbot-api-domain/pom.xml @@ -11,5 +11,43 @@ chatbot-api-domain + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + com.alibaba + fastjson + + + org.apache.commons + commons-lang3 + + + org.seleniumhq.selenium + selenium-api + + + + org.apache.httpcomponents + httpclient + + + org.apache.httpcomponents + httpmime + + + + net.sf.json-lib + json-lib + jdk15 + + \ No newline at end of file diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/IZsxqApi.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/IZsxqApi.java new file mode 100644 index 0000000..ba418e7 --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/IZsxqApi.java @@ -0,0 +1,22 @@ +package cn.bugstack.chatbot.api.domain.zsxq; + +import cn.bugstack.chatbot.api.domain.zsxq.model.aggregates.UnAnsweredQuestionsAggregates; +import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * @author 小傅哥,微信:fustack + * @description 知识星球 API 接口 + * @github https://github.com/fuzhengwei + * @Copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public interface IZsxqApi { + + UnAnsweredQuestionsAggregates queryUnAnsweredQuestionsTopicId(String groupId, String cookie) throws IOException; + + boolean answer(String groupId, String cookie, String topicId, String text, boolean silenced) throws IOException; + +} \ No newline at end of file diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/aggregates/UnAnsweredQuestionsAggregates.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/aggregates/UnAnsweredQuestionsAggregates.java new file mode 100644 index 0000000..0f26505 --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/aggregates/UnAnsweredQuestionsAggregates.java @@ -0,0 +1,32 @@ +package cn.bugstack.chatbot.api.domain.zsxq.model.aggregates; + +import cn.bugstack.chatbot.api.domain.zsxq.model.res.RespData; + +/** + * @author 小傅哥,微信:fustack + * @description 未回答问题的聚合信息 + * @github https://github.com/fuzhengwei + * @Copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public class UnAnsweredQuestionsAggregates { + + private boolean succeeded; + private RespData resp_data; + + public boolean isSucceeded() { + return succeeded; + } + + public void setSucceeded(boolean succeeded) { + this.succeeded = succeeded; + } + + public RespData getResp_data() { + return resp_data; + } + + public void setResp_data(RespData resp_data) { + this.resp_data = resp_data; + } + +} diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/req/AnswerReq.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/req/AnswerReq.java new file mode 100644 index 0000000..e558ba5 --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/req/AnswerReq.java @@ -0,0 +1,25 @@ +package cn.bugstack.chatbot.api.domain.zsxq.model.req; + +/** + * @author 小傅哥,微信:fustack + * @description 请求问答接口信息 + * @github https://github.com/fuzhengwei + * @Copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public class AnswerReq { + + private ReqData req_data; + + public AnswerReq(ReqData req_data) { + this.req_data = req_data; + } + + public ReqData getReq_data() { + return req_data; + } + + public void setReq_data(ReqData req_data) { + this.req_data = req_data; + } + +} diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/req/ReqData.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/req/ReqData.java new file mode 100644 index 0000000..689366e --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/req/ReqData.java @@ -0,0 +1,43 @@ +package cn.bugstack.chatbot.api.domain.zsxq.model.req; + +/** + * @author 小傅哥,微信:fustack + * @description 请求对象 + * @github https://github.com/fuzhengwei + * @copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public class ReqData { + + private String text; + private String[] image_ids = new String[]{}; + private boolean silenced; + + public ReqData(String text, boolean silenced) { + this.text = text; + this.silenced = silenced; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String[] getImage_ids() { + return image_ids; + } + + public void setImage_ids(String[] image_ids) { + this.image_ids = image_ids; + } + + public boolean isSilenced() { + return silenced; + } + + public void setSilenced(boolean silenced) { + this.silenced = silenced; + } +} diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/res/AnswerRes.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/res/AnswerRes.java new file mode 100644 index 0000000..0a845ce --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/res/AnswerRes.java @@ -0,0 +1,21 @@ +package cn.bugstack.chatbot.api.domain.zsxq.model.res; + +/** + * @author 小傅哥,微信:fustack + * @description 请求问答接口结果 + * @github https://github.com/fuzhengwei + * @Copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public class AnswerRes { + + private boolean succeeded; + + public boolean isSucceeded() { + return succeeded; + } + + public void setSucceeded(boolean succeeded) { + this.succeeded = succeeded; + } + +} diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/res/RespData.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/res/RespData.java new file mode 100644 index 0000000..ef6ae02 --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/res/RespData.java @@ -0,0 +1,25 @@ +package cn.bugstack.chatbot.api.domain.zsxq.model.res; + +import cn.bugstack.chatbot.api.domain.zsxq.model.vo.Topics; + +import java.util.List; + +/** + * @author 小傅哥,微信:fustack + * @description 结果数据 + * @github https://github.com/fuzhengwei + * @Copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public class RespData { + + private List topics; + + public List getTopics() { + return topics; + } + + public void setTopics(List topics) { + this.topics = topics; + } + +} diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Group.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Group.java new file mode 100644 index 0000000..d0f283f --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Group.java @@ -0,0 +1,36 @@ +package cn.bugstack.chatbot.api.domain.zsxq.model.vo; + +/** + * @author 小傅哥,微信:fustack + * @description + * @github https://github.com/fuzhengwei + * @copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public class Group { + + private String group_id; + + private String name; + + private String type; + + public void setGroup_id(String group_id){ + this.group_id = group_id; + } + public String getGroup_id(){ + return this.group_id; + } + public void setName(String name){ + this.name = name; + } + public String getName(){ + return this.name; + } + public void setType(String type){ + this.type = type; + } + public String getType(){ + return this.type; + } + +} diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Owner.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Owner.java new file mode 100644 index 0000000..4d1e894 --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Owner.java @@ -0,0 +1,44 @@ +package cn.bugstack.chatbot.api.domain.zsxq.model.vo; + +/** + * @author 小傅哥,微信:fustack + * @description + * @github https://github.com/fuzhengwei + * @Copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public class Owner { + + private String user_id; + + private String name; + + private String avatar_url; + + private String location; + + public void setUser_id(String user_id){ + this.user_id = user_id; + } + public String getUser_id(){ + return this.user_id; + } + public void setName(String name){ + this.name = name; + } + public String getName(){ + return this.name; + } + public void setAvatar_url(String avatar_url){ + this.avatar_url = avatar_url; + } + public String getAvatar_url(){ + return this.avatar_url; + } + public void setLocation(String location){ + this.location = location; + } + public String getLocation(){ + return this.location; + } + +} diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/OwnerDetail.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/OwnerDetail.java new file mode 100644 index 0000000..69eac88 --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/OwnerDetail.java @@ -0,0 +1,28 @@ +package cn.bugstack.chatbot.api.domain.zsxq.model.vo; + +/** + * @author 小傅哥,微信:fustack + * @description + * @github https://github.com/fuzhengwei + * @copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public class OwnerDetail { + + private int questions_count; + + private String join_time; + + public void setQuestions_count(int questions_count){ + this.questions_count = questions_count; + } + public int getQuestions_count(){ + return this.questions_count; + } + public void setJoin_time(String join_time){ + this.join_time = join_time; + } + public String getJoin_time(){ + return this.join_time; + } + +} diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Question.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Question.java new file mode 100644 index 0000000..a467cca --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Question.java @@ -0,0 +1,68 @@ +package cn.bugstack.chatbot.api.domain.zsxq.model.vo; + +/** + * @author 小傅哥,微信:fustack + * @description + * @github https://github.com/fuzhengwei + * @copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public class Question { + + private Owner owner; + + private Questionee questionee; + + private String text; + + private boolean expired; + + private boolean anonymous; + + private OwnerDetail owner_detail; + + private String owner_location; + + public void setOwner(Owner owner){ + this.owner = owner; + } + public Owner getOwner(){ + return this.owner; + } + public void setQuestionee(Questionee questionee){ + this.questionee = questionee; + } + public Questionee getQuestionee(){ + return this.questionee; + } + public void setText(String text){ + this.text = text; + } + public String getText(){ + return this.text; + } + public void setExpired(boolean expired){ + this.expired = expired; + } + public boolean getExpired(){ + return this.expired; + } + public void setAnonymous(boolean anonymous){ + this.anonymous = anonymous; + } + public boolean getAnonymous(){ + return this.anonymous; + } + public void setOwner_detail(OwnerDetail owner_detail){ + this.owner_detail = owner_detail; + } + public OwnerDetail getOwner_detail(){ + return this.owner_detail; + } + public void setOwner_location(String owner_location){ + this.owner_location = owner_location; + } + public String getOwner_location(){ + return this.owner_location; + } + +} diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Questionee.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Questionee.java new file mode 100644 index 0000000..f8fa288 --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Questionee.java @@ -0,0 +1,52 @@ +package cn.bugstack.chatbot.api.domain.zsxq.model.vo; + +/** + * @author 小傅哥,微信:fustack + * @description + * @github https://github.com/fuzhengwei + * @copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public class Questionee { + + private String user_id; + + private String name; + + private String avatar_url; + + private String description; + + private String location; + + public void setUser_id(String user_id){ + this.user_id = user_id; + } + public String getUser_id(){ + return this.user_id; + } + public void setName(String name){ + this.name = name; + } + public String getName(){ + return this.name; + } + public void setAvatar_url(String avatar_url){ + this.avatar_url = avatar_url; + } + public String getAvatar_url(){ + return this.avatar_url; + } + public void setDescription(String description){ + this.description = description; + } + public String getDescription(){ + return this.description; + } + public void setLocation(String location){ + this.location = location; + } + public String getLocation(){ + return this.location; + } + +} diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Topics.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Topics.java new file mode 100644 index 0000000..cbabf78 --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/Topics.java @@ -0,0 +1,124 @@ +package cn.bugstack.chatbot.api.domain.zsxq.model.vo; + +/** + * @author 小傅哥,微信:fustack + * @description + * @github https://github.com/fuzhengwei + * @copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public class Topics { + + private String topic_id; + + private Group group; + + private String type; + + private Question question; + + private boolean answered; + + private int likes_count; + + private int rewards_count; + + private int comments_count; + + private int reading_count; + + private int readers_count; + + private boolean digested; + + private boolean sticky; + + private String create_time; + + private UserSpecific user_specific; + + public void setTopic_id(String topic_id){ + this.topic_id = topic_id; + } + public String getTopic_id(){ + return this.topic_id; + } + public void setGroup(Group group){ + this.group = group; + } + public Group getGroup(){ + return this.group; + } + public void setType(String type){ + this.type = type; + } + public String getType(){ + return this.type; + } + public void setQuestion(Question question){ + this.question = question; + } + public Question getQuestion(){ + return this.question; + } + public void setAnswered(boolean answered){ + this.answered = answered; + } + public boolean getAnswered(){ + return this.answered; + } + public void setLikes_count(int likes_count){ + this.likes_count = likes_count; + } + public int getLikes_count(){ + return this.likes_count; + } + public void setRewards_count(int rewards_count){ + this.rewards_count = rewards_count; + } + public int getRewards_count(){ + return this.rewards_count; + } + public void setComments_count(int comments_count){ + this.comments_count = comments_count; + } + public int getComments_count(){ + return this.comments_count; + } + public void setReading_count(int reading_count){ + this.reading_count = reading_count; + } + public int getReading_count(){ + return this.reading_count; + } + public void setReaders_count(int readers_count){ + this.readers_count = readers_count; + } + public int getReaders_count(){ + return this.readers_count; + } + public void setDigested(boolean digested){ + this.digested = digested; + } + public boolean getDigested(){ + return this.digested; + } + public void setSticky(boolean sticky){ + this.sticky = sticky; + } + public boolean getSticky(){ + return this.sticky; + } + public void setCreate_time(String create_time){ + this.create_time = create_time; + } + public String getCreate_time(){ + return this.create_time; + } + public void setUser_specific(UserSpecific user_specific){ + this.user_specific = user_specific; + } + public UserSpecific getUser_specific(){ + return this.user_specific; + } + +} diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/UserSpecific.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/UserSpecific.java new file mode 100644 index 0000000..e68c2e8 --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/model/vo/UserSpecific.java @@ -0,0 +1,28 @@ +package cn.bugstack.chatbot.api.domain.zsxq.model.vo; + +/** + * @author 小傅哥,微信:fustack + * @description + * @github https://github.com/fuzhengwei + * @copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +public class UserSpecific { + + private boolean liked; + + private boolean subscribed; + + public void setLiked(boolean liked){ + this.liked = liked; + } + public boolean getLiked(){ + return this.liked; + } + public void setSubscribed(boolean subscribed){ + this.subscribed = subscribed; + } + public boolean getSubscribed(){ + return this.subscribed; + } + +} diff --git a/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/service/ZsxqApi.java b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/service/ZsxqApi.java new file mode 100644 index 0000000..99532d5 --- /dev/null +++ b/chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/service/ZsxqApi.java @@ -0,0 +1,92 @@ +package cn.bugstack.chatbot.api.domain.zsxq.service; + +import cn.bugstack.chatbot.api.domain.zsxq.IZsxqApi; +import cn.bugstack.chatbot.api.domain.zsxq.model.aggregates.UnAnsweredQuestionsAggregates; +import cn.bugstack.chatbot.api.domain.zsxq.model.req.AnswerReq; +import cn.bugstack.chatbot.api.domain.zsxq.model.req.ReqData; +import cn.bugstack.chatbot.api.domain.zsxq.model.res.AnswerRes; +import com.alibaba.fastjson.JSON; +import net.sf.json.JSONObject; +import org.apache.http.HttpStatus; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import java.io.IOException; + +/** + * @author 小傅哥,微信:fustack + * @description + * @github https://github.com/fuzhengwei + * @Copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +@Service +public class ZsxqApi implements IZsxqApi { + + private Logger logger = LoggerFactory.getLogger(ZsxqApi.class); + + @Override + public UnAnsweredQuestionsAggregates queryUnAnsweredQuestionsTopicId(String groupId, String cookie) throws IOException { + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + + HttpGet get = new HttpGet("https://api.zsxq.com/v2/groups/" + groupId + "/topics?scope=unanswered_questions&count=20"); + + get.addHeader("cookie", cookie); + get.addHeader("Content-Type", "application/json;charset=utf8"); + + CloseableHttpResponse response = httpClient.execute(get); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + String jsonStr = EntityUtils.toString(response.getEntity()); + logger.info("拉取提问数据。groupId:{} jsonStr:{}", groupId, jsonStr); + return JSON.parseObject(jsonStr, UnAnsweredQuestionsAggregates.class); + } else { + throw new RuntimeException("queryUnAnsweredQuestionsTopicId Err Code is " + response.getStatusLine().getStatusCode()); + } + } + + @Override + public boolean answer(String groupId, String cookie, String topicId, String text, boolean silenced) throws IOException { + + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + + HttpPost post = new HttpPost("https://api.zsxq.com/v2/topics/" + topicId + "/answer"); + post.addHeader("cookie", cookie); + post.addHeader("Content-Type", "application/json;charset=utf8"); + post.addHeader("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"); + + /* 测试数据 + String paramJson = "{\n" + + " \"req_data\": {\n" + + " \"text\": \"自己去百度!\\n\",\n" + + " \"image_ids\": [],\n" + + " \"silenced\": false\n" + + " }\n" + + "}"; + */ + + AnswerReq answerReq = new AnswerReq(new ReqData(text, silenced)); + String paramJson = JSONObject.fromObject(answerReq).toString(); + + StringEntity stringEntity = new StringEntity(paramJson, ContentType.create("text/json", "UTF-8")); + post.setEntity(stringEntity); + + CloseableHttpResponse response = httpClient.execute(post); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + String jsonStr = EntityUtils.toString(response.getEntity()); + logger.info("回答问题结果。groupId:{} topicId:{} jsonStr:{}", groupId, topicId, jsonStr); + AnswerRes answerRes = JSON.parseObject(jsonStr, AnswerRes.class); + return answerRes.isSucceeded(); + } else { + throw new RuntimeException("answer Err Code is " + response.getStatusLine().getStatusCode()); + } + } + +} diff --git a/chatbot-api-interfaces/pom.xml b/chatbot-api-interfaces/pom.xml index 92dfba4..bd79ac0 100644 --- a/chatbot-api-interfaces/pom.xml +++ b/chatbot-api-interfaces/pom.xml @@ -72,6 +72,12 @@ cn.hutool hutool-all + + + cn.bugstack.ai + chatbot-api-domain + 1.0-SNAPSHOT + \ No newline at end of file diff --git a/chatbot-api-interfaces/src/main/resources/application.yml b/chatbot-api-interfaces/src/main/resources/application.yml index 58de10c..afd84ad 100644 --- a/chatbot-api-interfaces/src/main/resources/application.yml +++ b/chatbot-api-interfaces/src/main/resources/application.yml @@ -1,2 +1,6 @@ server: - port: 8090 \ No newline at end of file + port: 8090 + +chatbot-api: + groupId: 28885518425541 + cookie: __cuid=5330a556392a4c5b8084b4cbc165e0f3; amp_fef1e8=930aec23-e22e-4f11-8864-0389bd5095d1R...1g55hl79m.1g55hl79t.1.1.2; UM_distinctid=183e61195d535b-0bddac94679c75-19525635-1aeaa0-183e61195d7c52; sensorsdata2015jssdkcross={"distinct_id":"241858242255511","first_id":"17ebd0b4317ecb-0b27f672c2d3af-133a6253-1296000-17ebd0b4318ba7","props":{"$latest_traffic_source_type":"直接流量","$latest_search_keyword":"未取到值_直接打开","$latest_referrer":""},"$device_id":"17ebd0b4317ecb-0b27f672c2d3af-133a6253-1296000-17ebd0b4318ba7","identities":"eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMTgwMmQ2YjZiOWIxZjMtMGQ4YzMzZjhmYTA3YmEtMzU3MzZhMDMtMTI5NjAwMC0xODAyZDZiNmI5YzEwODYiLCIkaWRlbnRpdHlfbG9naW5faWQiOiIyNDE4NTgyNDIyNTU1MTEifQ==","history_login_id":{"name":"$identity_login_id","value":"241858242255511"}}; abtest_env=product; zsxqsessionid=8fae9a083a4874ab833c2158a44deb82; zsxq_access_token=5D862869-1229-A9B6-1BC1-C662EC4B16DD_D625BA7FD9CBBDFA \ No newline at end of file diff --git a/chatbot-api-interfaces/src/test/java/cn/bugstack/chatbot/api/test/SpringBootRunTest.java b/chatbot-api-interfaces/src/test/java/cn/bugstack/chatbot/api/test/SpringBootRunTest.java new file mode 100644 index 0000000..32c8ce1 --- /dev/null +++ b/chatbot-api-interfaces/src/test/java/cn/bugstack/chatbot/api/test/SpringBootRunTest.java @@ -0,0 +1,55 @@ +package cn.bugstack.chatbot.api.test; + +import cn.bugstack.chatbot.api.domain.zsxq.IZsxqApi; +import cn.bugstack.chatbot.api.domain.zsxq.model.aggregates.UnAnsweredQuestionsAggregates; +import cn.bugstack.chatbot.api.domain.zsxq.model.vo.Topics; +import com.alibaba.fastjson.JSON; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.io.IOException; +import java.util.List; + +/** + * @author 小傅哥,微信:fustack + * @description + * @github https://github.com/fuzhengwei + * @Copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +@RunWith(SpringRunner.class) +@SpringBootTest +public class SpringBootRunTest { + + private Logger logger = LoggerFactory.getLogger(SpringBootRunTest.class); + + @Value("${chatbot-api.groupId}") + private String groupId; + @Value("${chatbot-api.cookie}") + private String cookie; + + @Resource + private IZsxqApi zsxqApi; + + @Test + public void test_zsxqApi() throws IOException { + UnAnsweredQuestionsAggregates unAnsweredQuestionsAggregates = zsxqApi.queryUnAnsweredQuestionsTopicId(groupId, cookie); + logger.info("测试结果:{}", JSON.toJSONString(unAnsweredQuestionsAggregates)); + + List topics = unAnsweredQuestionsAggregates.getResp_data().getTopics(); + for (Topics topic : topics) { + String topicId = topic.getTopic_id(); + String text = topic.getQuestion().getText(); + logger.info("topicId:{} text:{}", topicId, text); + + // 回答问题 + zsxqApi.answer(groupId, cookie, topicId, text, false); + } + } + +} -- GitLab