From 31bbdfebea9047d61f2947f7879eccd467f93c14 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:07:15 +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=9F=A5=E8=AF=86=E6=98=9F=E7=90=83API=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/bugstack/chatbot/api/test/ApiTest.java | 60 +++++++++++++++++++ ...23\345\272\223\344\275\277\347\224\250.md" | 7 +++ ...45\345\217\243\344\277\241\346\201\257.md" | 5 ++ 3 files changed, 72 insertions(+) create mode 100644 "docs/md/\347\254\2541\350\212\202\357\274\232\345\267\245\347\250\213\345\210\233\345\273\272\345\222\214\344\273\223\345\272\223\344\275\277\347\224\250.md" create mode 100644 "docs/md/\347\254\2542\350\212\202\357\274\232\345\210\233\345\273\272\347\237\245\350\257\206\346\230\237\347\220\203\357\274\214\347\210\254\345\217\226\346\216\245\345\217\243\344\277\241\346\201\257.md" diff --git a/chatbot-api-interfaces/src/test/java/cn/bugstack/chatbot/api/test/ApiTest.java b/chatbot-api-interfaces/src/test/java/cn/bugstack/chatbot/api/test/ApiTest.java index ee29d5e..6defd31 100644 --- a/chatbot-api-interfaces/src/test/java/cn/bugstack/chatbot/api/test/ApiTest.java +++ b/chatbot-api-interfaces/src/test/java/cn/bugstack/chatbot/api/test/ApiTest.java @@ -1,5 +1,18 @@ package cn.bugstack.chatbot.api.test; +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.junit.Test; + +import java.io.IOException; + /** * @author 小傅哥,微信:fustack * @description 单元测试 @@ -7,4 +20,51 @@ package cn.bugstack.chatbot.api.test; * @Copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! */ public class ApiTest { + + @Test + public void query_unanswered_questions() throws IOException { + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + + HttpGet get = new HttpGet("https://api.zsxq.com/v2/groups/28885518425541/topics?scope=unanswered_questions&count=20"); + + get.addHeader("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"); + get.addHeader("Content-Type", "application/json;charset=utf8"); + + CloseableHttpResponse response = httpClient.execute(get); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + String res = EntityUtils.toString(response.getEntity()); + System.out.println(res); + } else { + System.out.println(response.getStatusLine().getStatusCode()); + } + } + + @Test + public void answer() throws IOException { + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + + HttpPost post = new HttpPost("https://api.zsxq.com/v2/topics/412884248251548/answer"); + post.addHeader("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"); + post.addHeader("Content-Type", "application/json;charset=utf8"); + + String paramJson = "{\n" + + " \"req_data\": {\n" + + " \"text\": \"自己去百度!\\n\",\n" + + " \"image_ids\": [],\n" + + " \"silenced\": false\n" + + " }\n" + + "}"; + + 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 res = EntityUtils.toString(response.getEntity()); + System.out.println(res); + } else { + System.out.println(response.getStatusLine().getStatusCode()); + } + } + } diff --git "a/docs/md/\347\254\2541\350\212\202\357\274\232\345\267\245\347\250\213\345\210\233\345\273\272\345\222\214\344\273\223\345\272\223\344\275\277\347\224\250.md" "b/docs/md/\347\254\2541\350\212\202\357\274\232\345\267\245\347\250\213\345\210\233\345\273\272\345\222\214\344\273\223\345\272\223\344\275\277\347\224\250.md" new file mode 100644 index 0000000..607720f --- /dev/null +++ "b/docs/md/\347\254\2541\350\212\202\357\274\232\345\267\245\347\250\213\345\210\233\345\273\272\345\222\214\344\273\223\345\272\223\344\275\277\347\224\250.md" @@ -0,0 +1,7 @@ +# 第1节:工程创建和仓库使用 + +## 资料 + +1. 仓库(GitHub):https://github.com/fuzhengwei/chatbot-api +2. 仓库(GitCode):https://gitcode.net/fuzhengwei/chatbot-api +3. DDD 博客:https://bugstack.cn/md/develop/framework/ddd/2019-10-15-DDD%E4%B8%93%E9%A2%98%E6%A1%88%E4%BE%8B%E4%B8%80%E3%80%8A%E5%88%9D%E8%AF%86%E9%A2%86%E5%9F%9F%E9%A9%B1%E5%8A%A8%E8%AE%BE%E8%AE%A1DDD%E8%90%BD%E5%9C%B0%E3%80%8B.html \ No newline at end of file diff --git "a/docs/md/\347\254\2542\350\212\202\357\274\232\345\210\233\345\273\272\347\237\245\350\257\206\346\230\237\347\220\203\357\274\214\347\210\254\345\217\226\346\216\245\345\217\243\344\277\241\346\201\257.md" "b/docs/md/\347\254\2542\350\212\202\357\274\232\345\210\233\345\273\272\347\237\245\350\257\206\346\230\237\347\220\203\357\274\214\347\210\254\345\217\226\346\216\245\345\217\243\344\277\241\346\201\257.md" new file mode 100644 index 0000000..033d4bc --- /dev/null +++ "b/docs/md/\347\254\2542\350\212\202\357\274\232\345\210\233\345\273\272\347\237\245\350\257\206\346\230\237\347\220\203\357\274\214\347\210\254\345\217\226\346\216\245\345\217\243\344\277\241\346\201\257.md" @@ -0,0 +1,5 @@ +# 第2节:创建知识星球,爬取接口信息 + +## 资料 + +1. json2entity:https://www.sojson.com/json2entity.html -- GitLab