package edb_data import ( "encoding/json" "errors" "fmt" "hongze/hongze_open_api/models/response/edb" "hongze/hongze_open_api/utils" "io/ioutil" "net/http" "strings" ) // EdbDetail 指标详情 func EdbDetail(uniqueCode string) (edbInfoDetail *edb.BaseEdbInfoDetailResp, err error, msg string) { param := make(map[string]interface{}) param["UniqueCode"] = uniqueCode urlStr := `open/edb/detail` resp, err := postRefreshEdbData(param, urlStr) if err != nil { return } if resp.Ret != 200 { msg = resp.Msg err = errors.New(resp.ErrMsg) return } dataBytes, err := json.Marshal(resp.Data) if err != nil { return } err = json.Unmarshal(dataBytes, &edbInfoDetail) if err != nil { return } return } // postRefreshEdbData 刷新指标数据 func postRefreshEdbData(param map[string]interface{}, urlStr string) (resp *edb.BaseResponse, err error) { postUrl := utils.EDB_LIB_URL + urlStr postData, err := json.Marshal(param) if err != nil { return } result, err := HttpPost(postUrl, string(postData), "application/json") if err != nil { return } utils.FileLog.Info("postRefreshEdbData:" + postUrl + ";" + string(postData) + ";result:" + string(result)) err = json.Unmarshal(result, &resp) if err != nil { return } return resp, nil } func HttpPost(url, postData string, params ...string) ([]byte, error) { body := ioutil.NopCloser(strings.NewReader(postData)) client := &http.Client{} req, err := http.NewRequest("POST", url, body) if err != nil { return nil, err } contentType := "application/x-www-form-urlencoded;charset=utf-8" if len(params) > 0 && params[0] != "" { contentType = params[0] } req.Header.Set("Content-Type", contentType) req.Header.Set("authorization", utils.MD5(utils.APP_EDB_LIB_NAME_EN+utils.EDB_LIB_Md5_KEY)) resp, err := client.Do(req) defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) fmt.Println("HttpPost:" + string(b)) return b, err }