• go DEMO

    go DEMO

    功能说明:该接口要求提前在云片后台添加模板,提交短信时,系统会自动匹配审核通过的模板,匹配成功任意一个模板即可发送。系统已提供的默认模板添加签名后可以直接使用。

    1. package main
    2. import (
    3. "net/http"
    4. "io/ioutil"
    5. "net/url"
    6. "fmt"
    7. )
    8. // bingone
    9. func main(){
    10. // 修改为您的apikey(https://www.yunpian.com)登录官网后获取
    11. apikey := "xxxxxxxxxxxxxxxxxx"
    12. // 修改为您要发送的手机号码,多个号码用逗号隔开
    13. mobile := "xxxxxxxxxxxxxxxxxx"
    14. // 发送内容
    15. text := "【云片网】您的验证码是1234"
    16. // 发送模板编号
    17. tpl_id := 1
    18. // 语音验证码
    19. code := "1234"
    20. company := "云片网"
    21. // 发送模板内容
    22. tpl_value := url.Values{"#code#":{code},"#company#":{company}}.Encode()
    23. // 获取user信息url
    24. url_get_user := "https://sms.yunpian.com/v2/user/get.json";
    25. // 智能模板发送短信url
    26. url_send_sms := "https://sms.yunpian.com/v2/sms/single_send.json";
    27. // 指定模板发送短信url
    28. url_tpl_sms := "https://sms.yunpian.com/v2/sms/tpl_single_send.json";
    29. // 发送语音短信url
    30. url_send_voice := "https://voice.yunpian.com/v2/voice/send.json";
    31. data_get_user := url.Values{"apikey": {apikey}}
    32. data_send_sms := url.Values{"apikey": {apikey}, "mobile": {mobile},"text":{text}}
    33. data_tpl_sms := url.Values { "apikey": {apikey},"mobile": {mobile},
    34. "tpl_id": {fmt.Sprintf("%d", tpl_id)},"tpl_value": {tpl_value}}
    35. data_send_voice := url.Values{"apikey": {apikey}, "mobile": {mobile},"code":{code}}
    36. httpsPostForm(url_get_user,data_get_user)
    37. httpsPostForm(url_send_sms,data_send_sms)
    38. httpsPostForm(url_tpl_sms,data_tpl_sms)
    39. httpsPostForm(url_send_voice,data_send_voice)
    40. }
    41. func httpsPostForm(url string,data url.Values) {
    42. resp, err := http.PostForm(url,data)
    43. if err != nil {
    44. // handle error
    45. }
    46. defer resp.Body.Close()
    47. body, err := ioutil.ReadAll(resp.Body)
    48. if err != nil {
    49. // handle error
    50. }
    51. fmt.Println(string(body))
    52. }