package services import ( "encoding/json" "eta/eta_mini_api/models" "eta/eta_mini_api/utils" "fmt" "io" "net/http" "strconv" "time" "github.com/rdlucklib/rdluck_tools/paging" ) type ReportList struct { List []*models.ReportList Paging *paging.PagingItem } type ReportResp[T any] struct { Ret int Data T Msg string ErrMsg string } type ReportDetailResp struct { Report *models.ReportDetail `description:"报告"` Status int `description:"报告状态"` } func GetReportList(chartPermissionId, level, rangeType, currentIndex, pageSize int) (resp *ReportResp[ReportList], err error) { url := utils.ETA_MINI_BRIDGE_URL + "/report/list?" url += fmt.Sprintf("RangeType=%d&ChartPermissionId=%d&Level=%d&PageSize=%d&CurrentIndex=%d", rangeType, chartPermissionId, level, pageSize, currentIndex) fmt.Println(url) client := &http.Client{} // 提交请求 req, err := http.NewRequest("GET", url, nil) if err != nil { return } nonce := utils.GetRandStringNoSpecialChar(16) timestamp := time.Now().Format(utils.FormatDateTimeUnSpace) signature := utils.GetSign(nonce, timestamp, utils.ETA_MINI_APPID, utils.ETA_MINI_APP_SECRET) //增加header选项 req.Header.Add("Nonce", nonce) req.Header.Add("Timestamp", timestamp) req.Header.Add("Appid", utils.ETA_MINI_APPID) req.Header.Add("Signature", signature) req.Header.Set("Content-Type", "application/json") response, err := client.Do(req) if err != nil { return } defer response.Body.Close() body, err := io.ReadAll(response.Body) if err != nil { return } utils.FileLog.Info("result:" + string(body)) err = json.Unmarshal(body, &resp) if err != nil { return resp, err } return resp, nil } func GetReportDetail(reportId, userId int) (resp *ReportResp[ReportDetailResp], err error) { url := utils.ETA_MINI_BRIDGE_URL + "/report/detail?" url += fmt.Sprintf("ReportId=%d&UserId=%d", reportId, userId) fmt.Println(url) client := &http.Client{} // 提交请求 req, err := http.NewRequest("GET", url, nil) if err != nil { return } nonce := utils.GetRandStringNoSpecialChar(16) timestamp := time.Now().Format(utils.FormatDateTimeUnSpace) signature := utils.GetSign(nonce, timestamp, utils.ETA_MINI_APPID, utils.ETA_MINI_APP_SECRET) //增加header选项 req.Header.Add("Nonce", nonce) req.Header.Add("Timestamp", timestamp) req.Header.Add("Appid", utils.ETA_MINI_APPID) req.Header.Add("Signature", signature) req.Header.Set("Content-Type", "application/json") response, err := client.Do(req) if err != nil { return } defer response.Body.Close() body, err := io.ReadAll(response.Body) if err != nil { return } utils.FileLog.Info("result:" + string(body)) err = json.Unmarshal(body, &resp) if err != nil { return resp, err } return resp, nil } func GetReportDailyList(currentIndex, pageSize int) (resp *ReportResp[ReportList], err error) { url := utils.ETA_MINI_BRIDGE_URL + "/report/daily/list" if currentIndex >= 0 && pageSize > 0 { url += "?PageSize=" + strconv.Itoa(pageSize) url += "&CurrentIndex=" + strconv.Itoa(currentIndex) } fmt.Println(url) client := &http.Client{} // 提交请求 req, err := http.NewRequest("GET", url, nil) if err != nil { return &ReportResp[ReportList]{}, err } nonce := utils.GetRandStringNoSpecialChar(16) timestamp := time.Now().Format(utils.FormatDateTimeUnSpace) signature := utils.GetSign(nonce, timestamp, utils.ETA_MINI_APPID, utils.ETA_MINI_APP_SECRET) //增加header选项 req.Header.Add("Nonce", nonce) req.Header.Add("Timestamp", timestamp) req.Header.Add("Appid", utils.ETA_MINI_APPID) req.Header.Add("Signature", signature) req.Header.Set("Content-Type", "application/json") response, err := client.Do(req) if err != nil { return &ReportResp[ReportList]{}, err } defer response.Body.Close() body, err := io.ReadAll(response.Body) if err != nil { return &ReportResp[ReportList]{}, err } utils.FileLog.Info("result:" + string(body)) err = json.Unmarshal(body, &resp) if err != nil { return resp, err } return resp, nil }