GO
GO代碼示例
//接口類型:達信通營銷短信接口,支持發送會員營銷短信。wx96 //賬戶注冊:請通過該地址開通賬戶http://sms.wx96.com/register.html //注意事項: //(1)調試期間,請用默認的模板進行測試,默認模板詳見接口文檔; //(2)請使用 用戶名(例如:cf_demo123)及 APIkey來調用接口,APIkey在會員中心可以獲取; //(3)該代碼僅供接入達信通短信接口參考使用,客戶可根據實際需要自行編寫; package main import ( "crypto/md5" "encoding/hex" "fmt" "io/ioutil" "net/http" "net/url" "strconv" "strings" "time" ) func GetMd5String(s string) string { h := md5.New() h.Write([]byte(s)) return hex.EncodeToString(h.Sum(nil)) } func main() { v := url.Values{} _now := strconv.FormatInt(time.Now().Unix(), 10) //fmt.Printf(_now) _account := "cf_xxxxxxx" //用戶名是登錄wx96.com賬號名(例如:cf_demo123) _password := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" //查看密碼請登錄用戶中心->短信營銷->帳戶參數設置->APIKEY _mobile := "136xxxxxxxx" _content := "尊敬的會員,您好,夏季新品已上市,請關注。退訂回TD【達信通】" v.Set("account", _account) v.Set("password", GetMd5String(_account+_password+_mobile+_content+_now)) v.Set("mobile", _mobile) v.Set("content", _content) v.Set("time", _now) body := ioutil.NopCloser(strings.NewReader(v.Encode())) //把form數據編下碼 client := &http.Client{} req, _ := http.NewRequest("POST", "http://api.yx.wx96.com/webservice/sms.php?method=Submit&format=json", body) req.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value") //fmt.Printf("%+v\n", req) //看下發送的結構 resp, err := client.Do(req) //發送 defer resp.Body.Close() //一定要關閉resp.Body data, _ := ioutil.ReadAll(resp.Body) fmt.Println(string(data), err) }