-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (64 loc) · 1.59 KB
/
main.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"encoding/json"
"encoding/xml"
"fmt"
"github.com/finalsatan/aliyun_mns/sms"
"io/ioutil"
"net/http"
)
const (
AliyunAccessKeyId = "xxxxxxxxx"
AliyunAccessKeySecret = "xxxxxxxxx"
EndPoint = "xxxxxxxxx.mns.cn-hangzhou.aliyuncs.com"
Path = "/topics/xxxxxxxxx/messages"
)
func main() {
client := sms.NewClient(AliyunAccessKeyId, AliyunAccessKeySecret, EndPoint)
dsms := sms.DirectSMS{
FreeSignName: "xxxxxx",
TemplateCode: "SMS_xxxxxxxx",
Type: "singleContent",
Receiver: "13xxxxxxxxx,17xxxxxxxxx",
SmsParams: `{"code":"211051"}`,
}
dsmsJson, err := json.Marshal(dsms)
if err != nil {
panic(err)
}
fmt.Println("DirectSMS: ", string(dsmsJson))
msgAttr := sms.MessageAttributes{
DirectSMS: string(dsmsJson),
}
message := sms.Message{
XMLNS: "http://mns.aliyuncs.com/doc/v1/",
MessageBody: "smscontent",
MessageAttributes: msgAttr,
}
data, err := xml.Marshal(message)
if err != nil {
panic(err)
}
fmt.Println(string(data))
req := sms.NewRequest(EndPoint, http.MethodPost, Path, data, map[string]string{})
resp, err := client.DoRequest(req)
if err != nil {
panic(err)
}
fmt.Println(resp)
defer resp.Body.Close()
//err = xml.NewDecoder(response.Body).Decode(msg)
retdata, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(retdata))
v := sms.MsgSendRes{}
err = xml.Unmarshal(retdata, &v)
if err != nil {
fmt.Printf("error: %v", err)
return
}
fmt.Println("message_id: ", v.MessageId)
fmt.Println("message_body_md5: ", v.MessageBodyMD5)
}