12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package third
- import (
- "encoding/json"
- "errors"
- "eta/eta_api/models"
- "eta/eta_api/utils"
- "fmt"
- "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
- }
- return
- }
- func DwSendTemplatedMsg(reportId int) error {
- url := fmt.Sprintf("%swechat/send_template_msg?ReportId=%d", utils.ETAMiniBridgeUrl, reportId)
- body, err := HttpGet(url)
- if err != nil {
- return err
- }
- result := new(models.BaseResponse)
- if err := json.Unmarshal(body, &result); err != nil {
- return err
- }
- if result.Ret != 200 {
- err = errors.New(string(body))
- return err
- }
- return nil
- }
|