|
@@ -83,17 +83,20 @@ func parseWeiboStats(jsonData []byte) (likes, comments, reposts, reads string, e
|
|
|
}
|
|
|
|
|
|
// GetRedBookLinkDetail 获取小红书链接数据详情
|
|
|
-func GetRedBookLinkDetail(ctx context.Context, shareText string) (int, int, int, int, error) {
|
|
|
+func GetRedBookLinkDetail(ctx context.Context, noteId string, xSecToken string) (int, int, int, int, error) {
|
|
|
|
|
|
url := "http://120.46.92.62:6888/api/xhs/note_detail"
|
|
|
method := "POST"
|
|
|
|
|
|
// 构造请求体结构
|
|
|
requestBody := struct {
|
|
|
+ NoteId string `json:"note_id"`
|
|
|
+ XSecToken string `json:"xsec_token"`
|
|
|
ShareText string `json:"share_text"`
|
|
|
Proxy string `json:"proxy"`
|
|
|
}{
|
|
|
- ShareText: shareText,
|
|
|
+ NoteId: noteId,
|
|
|
+ XSecToken: xSecToken,
|
|
|
Proxy: "",
|
|
|
}
|
|
|
|
|
@@ -156,8 +159,6 @@ func GetWeiBoLinkDetail(ctx context.Context, shareText string) (int, int, int, i
|
|
|
url := "http://120.46.92.62:6888/api/weibo/post_detail"
|
|
|
method := "POST"
|
|
|
|
|
|
- fmt.Println(shareText)
|
|
|
-
|
|
|
requestBody := struct {
|
|
|
Id string `json:"id"`
|
|
|
ShareText string `json:"share_text"`
|
|
@@ -262,7 +263,6 @@ type WeiboPostStats struct {
|
|
|
Likes int `json:"likes"` // 点赞数
|
|
|
Comments int `json:"comments"` // 评论数
|
|
|
Reposts int `json:"reposts"` // 转发数
|
|
|
- Pending int `json:"pending"` // 待审数
|
|
|
HasImages bool `json:"has_images"` // 是否有图片
|
|
|
HasVideo bool `json:"has_video"` // 是否有视频
|
|
|
CoverImageUrl string `json:"cover_image_url"` // 封面图URL(视频/文章)
|
|
@@ -295,7 +295,6 @@ func parseWeiboPosts(body []byte) ([]WeiboPostStats, error) {
|
|
|
Likes: mblog.AttitudesCount,
|
|
|
Comments: mblog.CommentsCount,
|
|
|
Reposts: mblog.RepostsCount,
|
|
|
- Pending: mblog.PendingApproval,
|
|
|
HasImages: len(mblog.PicIds) > 0,
|
|
|
HasVideo: hasVideo,
|
|
|
CoverImageUrl: mblog.PageInfo.PagePic.Url,
|
|
@@ -355,3 +354,96 @@ func GetWeiBoHistoryList(ctx context.Context, homePageUrl string) ([]WeiboPostSt
|
|
|
}
|
|
|
return hisData, nil
|
|
|
}
|
|
|
+
|
|
|
+// RedBookPostsResponse 小红书多条数据接收结构体
|
|
|
+type RedBookPostsResponse struct {
|
|
|
+ Code int `json:"code"`
|
|
|
+ Msg string `json:"msg"`
|
|
|
+ Data struct {
|
|
|
+ ResponseBody struct {
|
|
|
+ Data struct {
|
|
|
+ Note []struct {
|
|
|
+ NoteId string `json:"note_id"`
|
|
|
+ XsecToken string `json:"xsec_token"`
|
|
|
+ } `json:"notes"`
|
|
|
+ } `json:"data"`
|
|
|
+ } `json:"response_body"`
|
|
|
+ } `json:"data"`
|
|
|
+}
|
|
|
+
|
|
|
+func parseRedBookPosts(body []byte) ([]string, []string, error) {
|
|
|
+ var resp RedBookPostsResponse
|
|
|
+ if err := json.Unmarshal(body, &resp); err != nil {
|
|
|
+ return nil, nil, fmt.Errorf("JSON解析失败: %v", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if resp.Code != 200 {
|
|
|
+ return nil, nil, fmt.Errorf("API返回错误: %s", resp.Msg)
|
|
|
+ }
|
|
|
+
|
|
|
+ var linkList []string
|
|
|
+ var secTokenList []string
|
|
|
+ for i, card := range resp.Data.ResponseBody.Data.Note {
|
|
|
+ if i >= 5 { // 只取前5条
|
|
|
+ break
|
|
|
+ }
|
|
|
+ linkList = append(linkList, card.NoteId)
|
|
|
+ secTokenList = append(secTokenList, card.XsecToken)
|
|
|
+ }
|
|
|
+ return linkList, secTokenList, nil
|
|
|
+}
|
|
|
+
|
|
|
+// GetRedBookHistoryList 小红书历史作品列表
|
|
|
+func GetRedBookHistoryList(ctx context.Context, homePageUrl string) ([]RedBookNoteResponse, error) {
|
|
|
+ url := "http://120.46.92.62:6888/api/xhs/user_post"
|
|
|
+ method := "POST"
|
|
|
+
|
|
|
+ requestBody := struct {
|
|
|
+ UserId string `json:"user_id"`
|
|
|
+ Cursor string `json:"cursor"`
|
|
|
+ Proxy string `json:"proxy"`
|
|
|
+ }{
|
|
|
+ UserId: homePageUrl,
|
|
|
+ Proxy: "",
|
|
|
+ }
|
|
|
+
|
|
|
+ client := &http.Client{}
|
|
|
+
|
|
|
+ jsonData, err := json.Marshal(requestBody)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("JSON编码失败:", err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ payload := strings.NewReader(string(jsonData))
|
|
|
+ req, err := http.NewRequest(method, url, payload)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ req.Header.Add("Cookie", "abRequestId=023e90e1-a95a-58db-830a-d66c0cc67f60; a1=19566f0f66eglh42hy8peqvpak3xqglp49289p8xb50000109075; webId=d189df044ca380c74b5b97bc300db5a1; gid=yj2KKiyyyY4Yyj2KKi8iKjUYKdk1x4JxvYUdJCDAhU0TqY28CAk1Uj888y8j8W288q4Jif4i; acw_tc=0a4a949617517192833111453ec142bc6ab7f9b09590524b2d59d413f0ffb7; websectiga=a9bdcaed0af874f3a1431e94fbea410e8f738542fbb02df1e8e30c29ef3d91ac; sec_poison_id=9bc0c279-b964-4448-87df-d08559819919; web_session=0400698c340cec15e62be2555c3a4b29a1365a; xsecappid=xhs-pc-web; webBuild=4.71.0; loadts=1751719579486; unread={%22ub%22:%22685be6260000000015023bc6%22%2C%22ue%22:%2268617298000000001c0337aa%22%2C%22uc%22:23}")
|
|
|
+ req.Header.Add("Content-Type", "application/json")
|
|
|
+
|
|
|
+ res, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ defer res.Body.Close()
|
|
|
+
|
|
|
+ body, err := ioutil.ReadAll(res.Body)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ linkList, tokenList, linkErr := parseRedBookPosts(body)
|
|
|
+ if linkErr != nil {
|
|
|
+ return nil, linkErr
|
|
|
+ }
|
|
|
+ if linkList != nil {
|
|
|
+ fmt.Println(linkList)
|
|
|
+ fmt.Println(GetRedBookLinkDetail(ctx, linkList[2], tokenList[2]))
|
|
|
+ }
|
|
|
+ return nil, nil
|
|
|
+}
|