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

云通訊平臺-GO語言短信接口開發(fā)示例


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"  //請求地址請參考云通訊平臺查看或者詢問您的商務(wù)負(fù)責(zé)人獲取

    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)

}


免费视频观无码一区,国内精品一区二区无码,99精品无码视频在线播放,ā片国产在线播放