package youngee_talent_service import ( "bytes" "encoding/json" "fmt" "github.com/tidwall/gjson" "io/ioutil" "net/http" "youngmini_server/app/model/youngee_talent_model" ) const ( moreApiPrefix = "http://120.46.92.62:6888" ) func getDouyinInfo(shareText string) *youngee_talent_model.DouyinInfoResp { // 1. 构造请求体 reqBody := map[string]string{ "share_text": shareText, } jsonBytes, err := json.Marshal(reqBody) if err != nil { fmt.Println("请求体编码失败:", err) return nil } // 2. 发起 POST 请求 url := moreApiPrefix + "/api/douyin/user_data" resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonBytes)) if err != nil { fmt.Println("请求失败:", err) return nil } defer resp.Body.Close() // 3. 读取响应 respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("读取响应失败:", err) return nil } jsonStr := string(respBytes) // 4. 判断状态码 if gjson.Get(jsonStr, "data.status_code").Int() != 0 { fmt.Println("接口返回错误:", gjson.Get(jsonStr, "data.status_msg").String()) return nil } // 5. 解析字段 return &youngee_talent_model.DouyinInfoResp{ FollowerCount: gjson.Get(jsonStr, "data.user.follower_count").Int(), TotalFavorited: gjson.Get(jsonStr, "data.user.total_favorited").Int(), AwemeCount: gjson.Get(jsonStr, "data.user.aweme_count").Int(), Gender: int(gjson.Get(jsonStr, "data.user.gender").Int()), IPLocation: gjson.Get(jsonStr, "data.user.ip_location").String(), } }