Base on gorequest to test webhook(Provide from Wechat)and send a post requsest
PS. This passage will not provision proxy, you may need a laddar or any other method to get the package.
1. Install gorequest
- We can use
go get
command to install this package.
$ go get github.com/parnurzeal/gorequest
2. Open a robot of Wechat or DingTalk
- This passage we use Wechat to test webhook.
- We can use phone to add a robot, DingTalk need set in PC platform.
PS. DingTalk now need security verify
- After we can get a url of webhook
- DingTalk need to set fliter or security, any details are in document of DingTalk api.
3. Create a request use Golang
Code:
package main
import (
"fmt"
"github.com/parnurzeal/gorequest"
)
func main() {
fmt.Println("Hello world!")
url := "https://qyapi.weixin.qq.com/cgi-bin/" // You need update this url to yourself.
resp, body, err := gorequest.New().Post(url).Set("Content-Type", "application/json").
SendMap(map[string]interface{}{
"msgtype": "text",
"text": map[string]interface{}{
"content": "This is a test message",
},
}).
End()
if err != nil {
fmt.Println("err:", err)
}
fmt.Println(resp)
fmt.Println(body)
}
- This just a pattern how to send message through webhook
- When send message successfully, we can get this response.
Hopefully, this can be useful for you.
- I don’t like those passage just paste much code, and can not achieve what we want to do. This passage is just to make you know how to use golang to send request to webhook.