version python
import requests,json
def sender(url, msg):
"""
:param url: webhook地址
:param msg: 需要发送的消息
:return:
"""
payload_message = {
"msg_type": "text",
"content": {
"text": msg,
}
}
headers = {
'Content-Type': 'application/json'}
requests.request("POST", url, headers=headers, data=json.dumps(payload_message))
url = "your webhook" #
sender(url, "hello everyOne")
golang version
package server
import (
"fmt"
"github.com/spf13/viper"
"net/http"
"strings"
)
func SendMsg(msg string) {
// json
contentType := "application/text"
// data
sendData := `{
"msg_type": "text",
"content": {"text": "` + msg + `"}
}`
// request
data := strings.NewReader(sendData)
fmt.Println(data)
result, err := http.Post("your webhook", contentType, data)
if err != nil {
fmt.Printf("post failed, err:%v\n", err)
return
}
defer result.Body.Close()
}