Go语言
# 常规使用
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"unsafe"
)
func SendMessage() error {
channelCode := "4d2dac865118761a14d10d7d3afe7c35"
message1 := make(map[string]interface{})
message1["head"] = "测试标题"
message1["body"] = "测试内容"
bytesData, err := json.Marshal(message1)
if err != nil {
fmt.Println(err.Error() )
return nil
}
reader := bytes.NewReader(bytesData)
url := fmt.Sprintf("https://www.phprm.com/services/push/send/%s", channelCode)
request, err := http.NewRequest("POST", url, reader)
if err != nil {
fmt.Println(err.Error())
return nil
}
request.Header.Set("Content-Type", "application/json;charset=UTF-8")
client := http.Client{}
resp, err := client.Do(request)
if err != nil {
fmt.Println(err.Error())
return nil
}
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err.Error())
return nil
}
str := (*string)(unsafe.Pointer(&respBytes))
fmt.Println(*str)
return nil
}
func main() {
SendMessage()
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Last Updated: 2024/12/12, 21:28:26