浏览代码

Merge branch 'bzq/custom_dw_mini' of eta_server/eta_chart_lib into custom

鲍自强 8 月之前
父节点
当前提交
114f51da74
共有 2 个文件被更改,包括 33 次插入22 次删除
  1. 6 0
      services/dw_mini/base_mini_lib.go
  2. 27 22
      services/dw_mini/dw_mini.go

+ 6 - 0
services/dw_mini/base_mini_lib.go

@@ -18,9 +18,15 @@ func HttpPost(url, postData, token string) ([]byte, error) {
 	req.Header.Add("Authorization", token)
 	req.Header.Set("Content-Type", "application/json")
 	resp, err := client.Do(req)
+	if err != nil {
+		return nil, err
+	}
 	defer resp.Body.Close()
 	b, err := io.ReadAll(resp.Body)
 	fmt.Println("HttpPost:" + string(b))
+	if utils.RunMode == "debug" {
+		return b, err
+	}
 	str := string(b)
 	str = strings.Trim(str, `"`)
 	b = utils.DesBase64Decrypt([]byte(str), utils.ETA_MINI_DES_KEY)

+ 27 - 22
services/dw_mini/dw_mini.go

@@ -7,27 +7,41 @@ import (
 	"eta/eta_chart_lib/utils"
 )
 
+type MyChartIsCollect struct {
+	IsCollect bool
+}
+
+type BaseResponse struct {
+	Ret     int
+	Msg     string
+	ErrMsg  string
+	ErrCode string
+	Data    MyChartIsCollect
+}
+
+type MyChartIsCollectReq struct {
+	UniqueCode string
+}
+
+type MyChartCollectReq struct {
+	UniqueCode  string
+	ChartName   string
+	ChartImage  string
+	ChartInfoId int
+}
+
+type MyChartCollectCancelReq struct {
+	UniqueCode string
+}
+
 func GetMyChartIsCollect(token string, uniqueCode string) (isCollect bool, err error) {
 	url := utils.ETA_MINI_URL + "mychart/isCollect"
-	type MyChartIsCollectReq struct {
-		UniqueCode string
-	}
 	req := MyChartIsCollectReq{UniqueCode: uniqueCode}
 	reqBody, _ := json.Marshal(req)
 	result, err := HttpPost(url, string(reqBody), token)
 	if err != nil {
 		return
 	}
-	type MyChartIsCollect struct {
-		IsCollect bool
-	}
-	type BaseResponse struct {
-		Ret     int
-		Msg     string
-		ErrMsg  string
-		ErrCode string
-		Data    MyChartIsCollect
-	}
 	var resp BaseResponse
 	if err = json.Unmarshal(result, &resp); err != nil {
 		return
@@ -42,12 +56,6 @@ func GetMyChartIsCollect(token string, uniqueCode string) (isCollect bool, err e
 
 func MyChartCollect(token, uniqueCode, chartName, chartImage string, chartInfoId int) (resp *models.BaseResponse, err error) {
 	url := utils.ETA_MINI_URL + "mychart/collect"
-	type MyChartCollectReq struct {
-		UniqueCode  string
-		ChartName   string
-		ChartImage  string
-		ChartInfoId int
-	}
 	req := MyChartCollectReq{
 		UniqueCode:  uniqueCode,
 		ChartName:   chartName,
@@ -70,9 +78,6 @@ func MyChartCollect(token, uniqueCode, chartName, chartImage string, chartInfoId
 
 func MyChartCollectCancel(token string, uniqueCode string) (resp *models.BaseResponse, err error) {
 	url := utils.ETA_MINI_URL + "mychart/collectCancel"
-	type MyChartCollectCancelReq struct {
-		UniqueCode string
-	}
 	req := MyChartCollectCancelReq{UniqueCode: uniqueCode}
 	reqBody, _ := json.Marshal(req)
 	result, err := HttpPost(url, string(reqBody), token)