45 lines
931 B
Go
45 lines
931 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
endpoint := "http://127.0.0.1:8080/api/v1/sms/send"
|
|
if len(os.Args) > 1 {
|
|
endpoint = os.Args[1]
|
|
}
|
|
|
|
// 阿里云 msgContent 是模板参数 JSON;请替换为测试账号、签名和模板。
|
|
body := []byte(`{
|
|
"config": {
|
|
"serviceType": "1",
|
|
"regionId": "cn-hangzhou",
|
|
"accessKeyId": "your-access-key-id",
|
|
"accessKeySecret": "your-access-key-secret",
|
|
"signName": "your-sign-name",
|
|
"templateId": "SMS_000000001"
|
|
},
|
|
"params": {
|
|
"phoneNumber": "13800008000",
|
|
"msgContent": "{\"code\":\"123456\"}"
|
|
}
|
|
}`)
|
|
|
|
response, err := http.Post(endpoint, "application/json", bytes.NewReader(body))
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer response.Body.Close()
|
|
responseBody, err := io.ReadAll(response.Body)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Printf("HTTP %d\n%s", response.StatusCode, responseBody)
|
|
}
|