package services

import (
	"eta/eta_mini_api/utils"
	"io"
	"net/http"
	"time"
)

func HttpGet(url string) (body []byte, err error) {
	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))
	return
}