您的位置:首页 >  接口中心 > 短信接口DEMO-GO
  短信接口DEMO-GO
 

云通讯平台-GO语言短信接口开发示例


package main

import (

    "net/http"

    "net/url"

    "encoding/json"

    "fmt"

    "bytes"

    "io/ioutil"

    "unsafe"

)


type JsonPostSample struct {


}


func  main() {

    params := make(map[string]interface{})

    params["account"] = ""

    params["password"] = "a.123456"

    params["phone"] = "18712345678"

    params["msg"] =url.QueryEscape("【云通讯】您好,您的验证码是999999") 

    params["report"] = "false"

    bytesData, err := json.Marshal(params)

    if err != nil {

        fmt.Println(err.Error() )

        return

    }

    reader := bytes.NewReader(bytesData)

    url := "https://u.smsyun.cc/sms-partner/access/{用户帐号}/sendsms"  //请求地址请参考云通讯平台查看或者询问您的商务负责人获取

    request, err := http.NewRequest("POST", url, reader)

    if err != nil {

        fmt.Println(err.Error())

        return

    }

    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

    }

    respBytes, err := ioutil.ReadAll(resp.Body)

    if err != nil {

        fmt.Println(err.Error())

        return

    }


    str := (*string)(unsafe.Pointer(&respBytes))

    fmt.Println(*str)

}