SoulFindAPI.go 1.51 KB
Newer Older
Ford committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
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
}