40 lines
830 B
Go
40 lines
830 B
Go
package sms
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestSendSMS(t *testing.T) {
|
|
|
|
config := Config{
|
|
AccessKeyID: "LTAI5tM1X4HuqUwT8D74qXAH",
|
|
AccessKeySecret: "gxsC1QK12NSKH1HkCqKR1EnMdAy3ad",
|
|
Endpoint: "dysmsapi.aliyuncs.com",
|
|
SignName: "蓝色兄弟",
|
|
RetryTimes: 0,
|
|
Timeout: 15,
|
|
}
|
|
|
|
smsService, err := NewService(config)
|
|
if err != nil {
|
|
t.Errorf("创建短信服务失败: %v", err)
|
|
return
|
|
}
|
|
|
|
phoneNumber := "" // 替换为实际手机号
|
|
templateCode := "SMS_274900579" // 替换为实际模板ID
|
|
|
|
params := map[string]string{
|
|
"code": "123456",
|
|
}
|
|
|
|
err = smsService.SendSMS(context.Background(), []string{phoneNumber}, templateCode, params)
|
|
if err != nil {
|
|
t.Errorf("发送短信失败: %v", err)
|
|
return
|
|
}
|
|
|
|
t.Logf("已发送至 %s\n", phoneNumber)
|
|
}
|