From 8035e308befe08a370811fb02fed3b6ce5a2f4fc Mon Sep 17 00:00:00 2001 From: wujingtao Date: Mon, 29 Aug 2022 18:39:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/constant/TiktokRequestConstants.java | 14 +-- .../java/com/baiye/requert/RequestTiktok.java | 107 ++++++++++++++++++ 2 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 cdp-tools/cdp-tool-dy/dy-tool-member/dy-tool-member-service/src/main/java/com/baiye/requert/RequestTiktok.java diff --git a/cdp-common/cdp-common-core/src/main/java/com/baiye/core/constant/TiktokRequestConstants.java b/cdp-common/cdp-common-core/src/main/java/com/baiye/core/constant/TiktokRequestConstants.java index d4f2fbc..b5d45ee 100644 --- a/cdp-common/cdp-common-core/src/main/java/com/baiye/core/constant/TiktokRequestConstants.java +++ b/cdp-common/cdp-common-core/src/main/java/com/baiye/core/constant/TiktokRequestConstants.java @@ -43,31 +43,27 @@ public interface TiktokRequestConstants { /** - * 评论列表 + * 评论视频中的评论 */ String TIK_TOK_OPT_COMMENT_VIDEO_LIST = "/api/video/optCommentVideoComment"; /** - * 评论列表 + * 删除评论 */ String TIK_TOK_DELETE_COMMENT = "/api/video/delComment"; - - - - - /** * 搜索视频 */ - String SEARCH_VIDEO = "/api/search/searchVideo"; + String TIK_TOK_SEARCH_VIDEO = "/api/search/searchVideo"; /** * 视频详情 */ - String AWEME_DETAIL = "/api/video/awemeDetail"; + String TIK_TOK_AWEME_DETAIL = "/api/video/awemeDetail"; + } diff --git a/cdp-tools/cdp-tool-dy/dy-tool-member/dy-tool-member-service/src/main/java/com/baiye/requert/RequestTiktok.java b/cdp-tools/cdp-tool-dy/dy-tool-member/dy-tool-member-service/src/main/java/com/baiye/requert/RequestTiktok.java new file mode 100644 index 0000000..bf60844 --- /dev/null +++ b/cdp-tools/cdp-tool-dy/dy-tool-member/dy-tool-member-service/src/main/java/com/baiye/requert/RequestTiktok.java @@ -0,0 +1,107 @@ +package com.baiye.requert; + +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.baiye.core.constant.TiktokRequestConstants; +import com.baiye.core.util.StringUtils; +import com.baiye.properties.TiktokProperties; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @author jt + */ +@Component +@Slf4j +@RequiredArgsConstructor +public class RequestTiktok { + private final TiktokProperties tiktokProperties; + + /** + * 搜索视频 + */ + public JSONObject searchVideo(String vendorId, String keyWord) { + JSONObject jsonObject = twoJson(); + jsonObject.putOpt("vendorId", vendorId); + jsonObject.putOpt("keyWord", keyWord); + String s = firstJson(jsonObject); + String post = HttpUtil.post(tiktokProperties.getGatewayHost().concat(TiktokRequestConstants.TIK_TOK_SEARCH_VIDEO), s); + if (StringUtils.isNotBlank(post)) { + JSONObject json = JSONUtil.parseObj(post); + if (json.getInt("status_code") == 0) { + return JSONUtil.parseObj(post); + } + } + return null; + } + + /** + * 获取视频的评论 + * + * @param vendorId + * @param awemeId + * @return + */ + public JSONObject getVideoCommentList(String vendorId, String awemeId) { + JSONObject jsonObject = twoJson(); + jsonObject.putOpt("vendorId", vendorId); + jsonObject.putOpt("awemeId", awemeId); + String s = firstJson(jsonObject); + String post = HttpUtil.post(tiktokProperties.getGatewayHost().concat(TiktokRequestConstants.TIK_TOK_COMMENT_VIDEO_LIST), s); + if (StringUtils.isNotBlank(post)) { + JSONObject json = JSONUtil.parseObj(post); + if (json.getInt("status_code") == 0) { + return JSONUtil.parseObj(post); + } + } + return null; + } + + /** + * 评论视频的评论 + * + * @param vendorId + * @param awemeId + * @return + */ + public JSONObject optCommentVideoComment(String vendorId, String awemeId, String commentId, String content) { + JSONObject jsonObject = twoJson(); + jsonObject.putOpt("vendorId", vendorId); + jsonObject.putOpt("awemeId", awemeId); + jsonObject.putOpt("commentId", commentId); + jsonObject.putOpt("content", content); + String s = firstJson(jsonObject); + String post = HttpUtil.post(tiktokProperties.getGatewayHost().concat(TiktokRequestConstants.TIK_TOK_OPT_COMMENT_VIDEO_LIST), s); + if (StringUtils.isNotBlank(post)) { + JSONObject json = JSONUtil.parseObj(post); + if (json.getInt("status_code") == 0) { + return JSONUtil.parseObj(post); + } + } + return null; + } + + + /** + * @param jsonObject + * @return + */ + + private String firstJson(JSONObject jsonObject) { + JSONObject json = new JSONObject(); + json.putOpt("sessionKey", tiktokProperties.getSessionKey()); + json.putOpt("data", jsonObject); + return JSONUtil.toJsonStr(json); + } + + private JSONObject twoJson() { + JSONObject childrenJson = new JSONObject(); + + childrenJson.putOpt("offset", 0); + childrenJson.putOpt("checkLogin", false); + childrenJson.putOpt("checkProxyInfo", false); + return childrenJson; + } +}