package service import ( "WorldEpcho/src/config" "encoding/json" "fmt" "io/ioutil" "net/http" "net/url" "strings" ) //查询数字人聊天的意识流Id参数 type HuaSoulFindParam struct { Auth string `from:"auth" json:"code"` ISLIUid string `from:"ISLIUid" json:"ISLIUid"` } //响应 type ResponseIsLIUCode struct { Code int `json:"code"` } func HuaSoulFindISLIUID(ISLIU_id string) bool { /* 创建一个请求参数对象 */ FindParam := HuaSoulFindParam{ Auth: config.Conf.SoulAuth, ISLIUid: ISLIU_id, } fmt.Println(FindParam) find_url := config.Conf.SoulUrl + "/soul/find" fmt.Println("find quest_url", find_url) /* 参数处理 */ postData := url.Values{} postData.Add("auth", FindParam.Auth) postData.Add("ISLIUid", FindParam.ISLIUid) // 发送POST请求 resp, err := http.Post(find_url, "application/x-www-form-urlencoded", strings.NewReader(postData.Encode())) if err != nil { fmt.Println("会话响应失败,请稍后重试:", err) return false } defer resp.Body.Close() // 读取响应的body数据 body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("读取会话响应数据失败,请稍后重试:", err) return false } // 解析Json var IsLiuCode ResponseIsLIUCode err = json.Unmarshal(body, &IsLiuCode) if err != nil { fmt.Println("查询意识流id状态值失败:", err) return false } // 使用解析后的参数 fmt.Println("查询意识流id的Code为:", IsLiuCode.Code) if IsLiuCode.Code == 1 { return true } return false }