1. 程式人生 > >go 釘釘報警

go 釘釘報警

ack content UNC dal code new close pre ()

代碼

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 釘釘報警