首页 > 其他 > 详细

go 钉钉报警

时间:2019-04-04 14:59:08      阅读:278      评论:0      收藏:0      [点我收藏+]

代码

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io/ioutil"
    "net/http"
)

const webhook_url = "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

func dingToInfo(s string) bool {
    content, data := make(map[string]string), make(map[string]interface{})
    content["content"] = s
    data["msgtype"] = "text"
    data["text"] = content
    b, _ := json.Marshal(data)

    resp, err := http.Post(webhook_url,
        "application/json",
        bytes.NewBuffer(b))
    if err != nil {
        fmt.Println(err)
    }
    defer resp.Body.Close()
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
    return true
}

func main()  {
    dingToInfo("报警")
}

go 钉钉报警

原文:https://blog.51cto.com/hequan/2374161

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!