moreapi_service.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. package service
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "net/http"
  7. "strings"
  8. )
  9. type MoreapiService struct{}
  10. // 获取抖音作品数据
  11. type DouyinStatisticResponse struct {
  12. Code int `json:"code"`
  13. Data struct {
  14. AwemeDetail struct {
  15. Statistics struct {
  16. DiggCount int `json:"digg_count"` // 点赞数
  17. CommentCount int `json:"comment_count"` // 评论数
  18. CollectCount int `json:"collect_count"` // 收藏数
  19. ShareCount int `json:"share_count"` // 分享数
  20. } `json:"statistics"`
  21. } `json:"aweme_detail"`
  22. } `json:"data"`
  23. }
  24. // 获取抖音作品数据
  25. func (s MoreapiService) GetDouyinStatistic(shareText string) (likes, comments, collects, shares int, err error) {
  26. url := "http://120.46.92.62:6888/api/douyin/aweme_detail_v4"
  27. method := "POST"
  28. //awemeId = "7519726524871462153"
  29. //shareText = "6.99 M@j.cn 03/18 uSy:/ - 你怎么哭着脸 # 沈妙 # 永劫无间 # 街头狂欢 # 涂鸦少女 https://v.douyin.com/z4go6Y8l458/ 复制此链接,打开Dou音搜索,直接观看视频!"
  30. requestBody := struct {
  31. AwemeId string `json:"aweme_id"`
  32. ShareText string `json:"share_text"`
  33. Proxy string `json:"proxy"`
  34. }{
  35. AwemeId: "",
  36. ShareText: shareText,
  37. Proxy: "",
  38. }
  39. // 封装请求体
  40. jsonData, err := json.Marshal(requestBody)
  41. if err != nil {
  42. fmt.Println("JSON编码失败:", err)
  43. return 0, 0, 0, 0, err
  44. }
  45. payload := strings.NewReader(string(jsonData))
  46. client := &http.Client{}
  47. req, err := http.NewRequest(method, url, payload)
  48. if err != nil {
  49. // fmt.Println(err)
  50. return 0, 0, 0, 0, err
  51. }
  52. req.Header.Add("Cookie", "")
  53. req.Header.Add("Content-Type", "application/json")
  54. res, err := client.Do(req)
  55. if err != nil {
  56. // fmt.Println(err)
  57. return 0, 0, 0, 0, err
  58. }
  59. defer res.Body.Close()
  60. body, err := ioutil.ReadAll(res.Body)
  61. if err != nil {
  62. //fmt.Println("解析互动数据失败:", err)
  63. return 0, 0, 0, 0, err
  64. }
  65. fmt.Println(string(body))
  66. // 解析响应数据
  67. var response DouyinStatisticResponse
  68. err = json.Unmarshal(body, &response)
  69. if err != nil {
  70. fmt.Println("解析互动数据失败:", err)
  71. return 0, 0, 0, 0, fmt.Errorf("解析JSON失败: %v", err)
  72. }
  73. statistics := response.Data.AwemeDetail.Statistics
  74. likes, comments, collects, shares = statistics.DiggCount, statistics.CommentCount, statistics.CollectCount, statistics.ShareCount
  75. // 打印结果
  76. fmt.Println("点赞数:", likes)
  77. fmt.Println("评论数:", comments)
  78. fmt.Println("收藏数:", collects)
  79. fmt.Println("分享数(可作为浏览量参考):", shares)
  80. return likes, comments, collects, shares, nil
  81. }
  82. // 获取快手作品数据
  83. type KuaishouStatisticResponse struct {
  84. Code int `json:"code"`
  85. Data struct {
  86. Photos []struct {
  87. CollectCount int `json:"collect_count"` // 收藏数
  88. CommentCount int `json:"comment_count"` // 评论数
  89. LikeCount int `json:"like_count"` // 点赞数
  90. ForwardCount int `json:"forward_count"`
  91. ViewCount int `json:"view_count"` // 浏览数
  92. ShareCount int `json:"share_count"` // 分享数
  93. } `json:"photos"`
  94. } `json:"data"`
  95. }
  96. // 获取快手作品数据
  97. func (s MoreapiService) GetKuaishouStatistic(shareText string) (likes, comments, collects, shares int, err error) {
  98. url := "http://120.46.92.62:6888/api/ks/aweme_detail"
  99. method := "POST"
  100. //photoId = "3xhsja9s5xfr3ts"
  101. //shareText = "https://www.kuaishou.com/f/X-16itgqSzQ64163"
  102. requestBody := struct {
  103. PhotoId string `json:"photo_id"`
  104. ShareText string `json:"share_text"`
  105. Proxy string `json:"proxy"`
  106. }{
  107. PhotoId: "",
  108. ShareText: shareText,
  109. Proxy: "",
  110. }
  111. // 封装请求体
  112. jsonData, err := json.Marshal(requestBody)
  113. if err != nil {
  114. fmt.Println("JSON编码失败:", err)
  115. return 0, 0, 0, 0, err
  116. }
  117. payload := strings.NewReader(string(jsonData))
  118. client := &http.Client{}
  119. req, err := http.NewRequest(method, url, payload)
  120. if err != nil {
  121. // fmt.Println(err)
  122. return 0, 0, 0, 0, err
  123. }
  124. req.Header.Add("Cookie", "")
  125. req.Header.Add("Content-Type", "application/json")
  126. res, err := client.Do(req)
  127. if err != nil {
  128. // fmt.Println(err)
  129. return 0, 0, 0, 0, err
  130. }
  131. defer res.Body.Close()
  132. body, err := ioutil.ReadAll(res.Body)
  133. if err != nil {
  134. //fmt.Println("解析互动数据失败:", err)
  135. return 0, 0, 0, 0, err
  136. }
  137. fmt.Println(string(body))
  138. // 解析响应数据
  139. var response KuaishouStatisticResponse
  140. err = json.Unmarshal(body, &response)
  141. if err != nil {
  142. fmt.Println("解析互动数据失败:", err)
  143. return 0, 0, 0, 0, fmt.Errorf("解析JSON失败: %v", err)
  144. }
  145. photo := response.Data.Photos[0]
  146. likes, comments, collects, shares = photo.LikeCount, photo.CommentCount, photo.CollectCount, photo.ViewCount
  147. // 打印结果
  148. fmt.Println("点赞数:", likes)
  149. fmt.Println("评论数:", comments)
  150. fmt.Println("收藏数:", collects)
  151. fmt.Println("分享数(可作为浏览量参考):", shares)
  152. return likes, comments, collects, shares, nil
  153. }
  154. // 获取b站作品数据
  155. type BilibiliStatisticResponse struct {
  156. Code int `json:"code"`
  157. Data struct {
  158. VideoData struct {
  159. Stat struct {
  160. Like int `json:"like"` // 点赞数
  161. Reply int `json:"reply"` // 评论数
  162. Favorite int `json:"favorite"` // 收藏数
  163. Share int `json:"share"` // 分享数
  164. Coin int `json:"coin"` // 投币数
  165. View int `json:"view"` // 浏览数
  166. } `json:"stat"`
  167. } `json:"videoData"`
  168. } `json:"data"`
  169. }
  170. // 获取b站作品数据
  171. func (s MoreapiService) GetBilibiliStatistic(bvId string) (likes, comments, collects, shares int, err error) {
  172. url := "http://120.46.92.62:6888/api/bilibili/video_data"
  173. method := "POST"
  174. bvId = "BV1KUM2z1Ecu"
  175. requestBody := struct {
  176. BvId string `json:"bvid"`
  177. Proxy string `json:"proxy"`
  178. }{
  179. BvId: bvId,
  180. Proxy: "",
  181. }
  182. // 封装请求体
  183. jsonData, err := json.Marshal(requestBody)
  184. if err != nil {
  185. fmt.Println("JSON编码失败:", err)
  186. return 0, 0, 0, 0, err
  187. }
  188. payload := strings.NewReader(string(jsonData))
  189. client := &http.Client{}
  190. req, err := http.NewRequest(method, url, payload)
  191. if err != nil {
  192. // fmt.Println(err)
  193. return 0, 0, 0, 0, err
  194. }
  195. req.Header.Add("Cookie", "")
  196. req.Header.Add("Content-Type", "application/json")
  197. res, err := client.Do(req)
  198. if err != nil {
  199. // fmt.Println(err)
  200. return 0, 0, 0, 0, err
  201. }
  202. defer res.Body.Close()
  203. body, err := ioutil.ReadAll(res.Body)
  204. if err != nil {
  205. //fmt.Println("解析互动数据失败:", err)
  206. return 0, 0, 0, 0, err
  207. }
  208. fmt.Println(string(body))
  209. // 解析响应数据
  210. var response BilibiliStatisticResponse
  211. err = json.Unmarshal(body, &response)
  212. if err != nil {
  213. fmt.Println("解析互动数据失败:", err)
  214. return 0, 0, 0, 0, fmt.Errorf("解析JSON失败: %v", err)
  215. }
  216. stat := response.Data.VideoData.Stat
  217. likes, comments, collects, shares = stat.Like, stat.Reply, stat.Favorite, stat.View
  218. // 打印结果
  219. fmt.Println("点赞数:", likes)
  220. fmt.Println("评论数:", comments)
  221. fmt.Println("收藏数:", collects)
  222. fmt.Println("分享数(可作为浏览量参考):", shares)
  223. return likes, comments, collects, shares, nil
  224. }