write the relatively rough, there is the wrong place to correct, not English, some of the variables with pinyin name, disturb
Package Sendmsgimport ("bytes" "Crypto/hmac" "Crypto/sha1" "Encoding/base64" "Encoding/json" "FMT" " Io/ioutil "" Net/http "" Net/url "" StrConv "" Strings "" Time ") const (AK =" xxxxxxx "SK = "xxxxxxx" Requesturl = "http://dysmsapi.aliyuncs.com/?" signature= "actionstr =" &action=sendsms&format=json&outid=123 "datestr =" &Version=2017-05-25 "Msgtemplete =" &signatureversion=1.0&templatecode= template id&templateparam= "singStr =" &SignatureMe thod=hmac-sha1&signaturenonce= "singname =" ®ionid=cn-hangzhou&signname= "lianJIe =" & " Signlinajie = "get&%2f&")//simplemessage ... type simplemessage struct {message string ' JSON: ' message ' ' Cod E string ' JSON: ' Code ' '}//messagecontent ... type messagecontent struct {code string ' JSON: ' Code ' '}//sendmsg Send SMS Func Sendmsg (phone, msgjson string) bool {body: = "Send msg" content: = URL. QUeryescape (Msgjson) signstring: = Setquerystr (phone, content, "skw493jei3j34ij34i") Singstr: = Signlinajie + URL. Queryescape (signstring) Sign: = Hmac4go (SINGSTR, Sk+lianjie) Client: = &http. client{} var req *http. Request req, err = http. Newrequest ("GET", Requesturl+url. Queryescape (sign) +lianjie+signstring, strings. Newreader (body)) Var resp *http. Response resp, err = client. Do (req) if err! = Nil {fmt. Println ("HTTP Get error.", err) return false} FMT. Println (resp. Body) Defer resp. Body.close () var bodys []byte bodys, err = Ioutil. ReadAll (resp. Body) If err! = Nil {fmt. Println ("http ReadAll body Error", err) return false} FMT. Println (String (bodys)) var msg simplemessage if Len (bodys) > 0 {err = json. Unmarshal (Bodys, &msg) if err! = Nil {fmt. PRINTLN ("http JSON body error", err) return false} FMT. PRINTLN (msg)} if Msg. Code = = "OK" { return true} return false}//setquerystr set query request func setquerystr (phone, content string, id Int64) string { var cstzone = time. Fixedzone ("GMT", 0) KeyTime: = time. Now (). In (Cstzone). Format ("2006-01-02t15:04:05z") singnames: = URL. Queryescape ("Signname") buf: = bytes. buffer{} buf. WriteString ("accesskeyid=") buf. WriteString (AK) buf. WriteString (ACTIONSTR) buf. WriteString ("&phonenumbers=") buf. WriteString (phone + singname + singnames + singstr) buf. WriteString (StrConv. Formatint (ID, ten) + Msgtemplete + content) buf. WriteString ("×tamp=" + URL. Queryescape (keyTime) + datestr) signstring: = buf. String () return Signstring}//hmac4go encrypts the Func hmac4go (name, SK String) string {mac: = HMAC. New (SHA1. New, []byte (SK)) Mac. Write ([]byte (name)) Encodestring: = base64. Stdencoding.encodetostring (Mac. Sum (nil)) return encodestring}