package speechNlu import ( "bytes" "encoding/json" "fmt" "io" "net/http" "speech-nlu-parse/global" "speech-nlu-parse/pkg/logger" "time" ) type FeedBackReq struct { ActionType int `json:"action_type"` Timestamp int64 `json:"timestamp"` Imei string `json:"imei"` Os string `json:"os"` ClientIp string `json:"client_ip"` Brand string `json:"brand"` Data []map[string]interface{} `json:"data"` } type FeedBackReqData struct { Sid string `json:"sid"` Duration int `json:"duration"` Ext struct { District string `json:"district"` City string `json:"city"` Province string `json:"province"` } `json:"ext"` } type FeedBackResp struct { Code int `json:"code"` Msg string `json:"msg"` Source string `json:"source"` } func FeedBackNews(actionType, duration int, ip, sid, uid string) (*FeedBackResp, error) { //url := "http://apis.duiopen.com/feedback/letingv4?productId=279629895&apikey=0c74988953dd4ed4bf31955527802cf3&uid=111" url := global.SpeechSetting.FeedBackUrl + "?productId=" + global.SpeechSetting.ProductId + "&apikey=" + global.SpeechSetting.ApiKey + "&uid=" + uid request := FeedBackReq{ ActionType: actionType, Timestamp: time.Now().Unix(), ClientIp: ip, //ip Brand: "gree", Data: []map[string]interface{}{ { "sid": sid, //"m6J2LW-4z-H2dtxea5Sv6_voziweppX1K_aGb7fKtdjq3y36awwXd_NeoKgBXD7a" "duration": duration, //138 }, }, } field := logger.Fields{ "FeedBackNews_request": request, "FeedBackNews_url": url, } reqData, err := json.Marshal(request) if err != nil { global.Logger.WithFields(field).Error(err.Error()) return nil, err } start := time.Now() client := http.Client{Timeout: 2 * time.Second} req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(reqData)) if err != nil { global.Logger.WithFields(field).Error(err.Error()) return nil, err } res, err := client.Do(req) if err != nil { global.Logger.WithFields(field).Error(err.Error()) return nil, err } defer res.Body.Close() field["cost_time_cmd"] = fmt.Sprintf("%fs", time.Since(start).Seconds()) body, err := io.ReadAll(res.Body) if err != nil { global.Logger.WithFields(field).Error(err.Error()) return nil, err } field["GetGridConList_response"] = string(body) var response FeedBackResp if err := json.Unmarshal(body, &response); err != nil { global.Logger.WithFields(field).Error(err.Error()) return nil, err } global.Logger.WithFields(field).Info("FeedBackNews") return &response, nil }