|
@@ -8,16 +8,17 @@ import (
|
|
|
"fmt"
|
|
|
"gd_vehicle/consts"
|
|
|
"gd_vehicle/errors"
|
|
|
- "io/ioutil"
|
|
|
- "net/http"
|
|
|
- "strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
|
|
|
"gd_vehicle/common.in/cache"
|
|
|
"gd_vehicle/common.in/config"
|
|
|
+ "gd_vehicle/thirdparty"
|
|
|
+
|
|
|
+ "go.uber.org/zap"
|
|
|
|
|
|
"github.com/astaxie/beego/orm"
|
|
|
+ "github.com/tidwall/gjson"
|
|
|
|
|
|
"github.com/afex/hystrix-go/hystrix"
|
|
|
)
|
|
@@ -158,25 +159,36 @@ type TextMsg struct {
|
|
|
}
|
|
|
|
|
|
func SendToDingTalk(content string) {
|
|
|
- textMsg := TextMsg{}
|
|
|
- textMsg.MsgType = "text"
|
|
|
- textMsg.Text = Text{}
|
|
|
- textMsg.Text.Content = content
|
|
|
- webHook := config.Conf.ThirdPart.DingTalkWebhook
|
|
|
- contentByte, _ := json.Marshal(textMsg)
|
|
|
- req, err := http.NewRequest("POST", webHook, strings.NewReader(string(contentByte)))
|
|
|
- client := &http.Client{}
|
|
|
- req.Header.Set("Content-Type", "application/json")
|
|
|
- resp, err := client.Do(req)
|
|
|
- defer resp.Body.Close()
|
|
|
+ body := map[string]interface{}{
|
|
|
+ "msgtype": "text",
|
|
|
+ "text": map[string]interface{}{"content": content},
|
|
|
+ }
|
|
|
+ bytes, _ := json.Marshal(body)
|
|
|
+
|
|
|
+ h := thirdparty.HttpRequestWithHeadCommon{
|
|
|
+ Method: "POST",
|
|
|
+ Url: config.Conf.ThirdPart.RobotUrl,
|
|
|
+ Body: bytes,
|
|
|
+ TimeOut: 10 * time.Second,
|
|
|
+ }
|
|
|
+ bytes, err := h.Request()
|
|
|
if err != nil {
|
|
|
- fmt.Println("send error:", err)
|
|
|
+ l.Error("func",
|
|
|
+ zap.String("call", "RobotMsg"),
|
|
|
+ zap.String("params", content),
|
|
|
+ zap.String("error", err.Error()))
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- fmt.Println(resp.StatusCode)
|
|
|
- body, _ := ioutil.ReadAll(resp.Body)
|
|
|
- fmt.Println(string(body))
|
|
|
+ errcode := gjson.GetBytes(bytes, "errcode").Int()
|
|
|
+ errmsg := gjson.GetBytes(bytes, "errmsg").String()
|
|
|
+ if errcode != 0 {
|
|
|
+ l.Error("func",
|
|
|
+ zap.String("call", "RobotMsg"),
|
|
|
+ zap.String("params", content),
|
|
|
+ zap.String("error", errmsg))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func ReloadHystrix() {
|