// Copyright 2019 utimes.cc. All rights reserved. // Use of this source code is governed by utimes.cc. package data_api_check import ( "gd_auth_check/common.in/config" "encoding/json" "fmt" "github.com/astaxie/beego/orm" "io/ioutil" "net/http" "strings" "strconv" ) type Text struct { Content string `json:"content"` } type At struct { AtMobiles []string `json:"atMobiles"` IsAtAll bool `json:"isAtAll"` } type TextMsg struct { MsgType string `json:"msgtype"` Text Text `json:"text"` At At `json:"at"` } 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() if err != nil { fmt.Println("send error:", err) return } fmt.Println(resp.StatusCode) body, _ := ioutil.ReadAll(resp.Body) fmt.Println(string(body)) } func ormStringToInt(m orm.Params, key string) int64 { if m[key] == nil { return 0 } str, ok := m[key].(string) if ok == false { return 0 } ret, err := strconv.ParseInt(str, 10, 64) if err != nil { return 0 } return ret } func ormStringToFloat(m orm.Params, key string) float64 { if m[key] == nil { return 0 } str, ok := m[key].(string) if ok == false { return 0 } ret, err := strconv.ParseFloat(str, 64) if err != nil { return 0 } return ret }