diff --git a/services/sms/client.go b/services/sms/client.go index 03112d3..0885e07 100644 --- a/services/sms/client.go +++ b/services/sms/client.go @@ -83,17 +83,6 @@ func (c *Client) SendSms(req *SendSmsRequest) (resp *SendSmsResponse, err error) err = errors.New("type is empty") return } - - if req.Expired == 0 { - err = errors.New("expired is empty") - return - } - - if req.Code == 0 { - err = errors.New("code is empty") - return - } - resp = CreateSendSmsResponse() err = c.DoAction(req, resp) return diff --git a/services/sms/client_test.go b/services/sms/client_test.go index 7c9498e..bd7cabb 100644 --- a/services/sms/client_test.go +++ b/services/sms/client_test.go @@ -94,12 +94,39 @@ func TestClient_SendFeiShuWebHook(t *testing.T) { fmt.Println(resp3) } -func TestClient_SendSms(t *testing.T) { +func TestClient_SendSmsCode(t *testing.T) { req := CreateSendSmsRequest(SendSmsParam{ - Mobile: "18320021439", - Type: SmsTypeBindPhone, - Code: 123456, - Expired: 5, + Mobile: "18320021439", + Type: SmsTypeBindPhone, + Replaces: []Item{{ + Key: ReplaceKeyCode, + Value: "6379", + }, { + Key: ReplaceKeySecond, + Value: "120", + }}, + }) + + req.Domain = requests.Host{ + Default: "127.0.0.1:8804", + } + + sms, err := client.SendSms(req) + if err != nil { + panic(err) + } + + fmt.Println(sms) +} + +func TestClient_SendSmsUrl(t *testing.T) { + req := CreateSendSmsRequest(SendSmsParam{ + Mobile: "18320021439", + Type: TemplateTypeOrderComplete, + Replaces: []Item{{ + Key: ReplaceKeyUrl, + Value: "http://www.baidu.com", + }}, }) req.Domain = requests.Host{ diff --git a/services/sms/email.go b/services/sms/email.go index 54a59e4..e55261b 100644 --- a/services/sms/email.go +++ b/services/sms/email.go @@ -32,7 +32,7 @@ func CreateSendEmailRequest(param SendEmailParam) (req *SendEmailRequest) { Body: param.Body, FromName: param.FromName, } - req.InitWithApiInfo(HOST, VERSION, "/email/send") + req.InitWithApiInfo(HOST, VERSION, "/v1/email/send") req.Method = requests.POST return } diff --git a/services/sms/feishu.go b/services/sms/feishu.go index f3ae8d7..004100d 100644 --- a/services/sms/feishu.go +++ b/services/sms/feishu.go @@ -44,7 +44,7 @@ func CreateSendFeiShuWebHookRequest(param SendFeiShuWebHookParam) (req *SendFeiS Title: param.Title, TitleColor: param.TitleColor, } - req.InitWithApiInfo(HOST, VERSION, "/feishu/webhook_send") + req.InitWithApiInfo(HOST, VERSION, "/v1/feishu/webhook_send") req.Method = requests.POST return } diff --git a/services/sms/sms.go b/services/sms/sms.go index 2556326..35beb37 100644 --- a/services/sms/sms.go +++ b/services/sms/sms.go @@ -5,12 +5,24 @@ import ( "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses" ) +type ReplaceKey = string + +const ( + ReplaceKeyCode ReplaceKey = "${code}" // 验证码 + ReplaceKeySecond ReplaceKey = "${second}" // 秒数 + ReplaceKeyUrl ReplaceKey = "${url}" // 链接 +) + +type Item struct { + Key ReplaceKey // 要替换的key + Value string // 要替换的值 +} + type SendSmsRequest struct { *requests.JsonRequest - Mobile string `position:"Json" field:"mobile"` - Type string `position:"Json" field:"type"` - Expired int64 `position:"Json" field:"expired"` - Code int64 `position:"Json" field:"code"` + Mobile string `position:"Json" field:"mobile"` + Type string `position:"Json" field:"type"` + Replaces []Item `position:"Json" field:"replaces"` } type SendSmsResponse struct { @@ -20,15 +32,16 @@ type SendSmsResponse struct { type SmsType = string const ( - SmsTypeRegister SmsType = "reg" // 注册 - SmsTypeBindPhone SmsType = "bind_phone" // 绑定手机号 + SmsTypeRegister SmsType = "reg" // 注册 + SmsTypeBindPhone SmsType = "bind_phone" // 绑定手机号 + TemplateTypeOrderComplete SmsType = "kf_order_complete" // 客服工单完成 + TemplateTypeKFOrderAdditional SmsType = "kf_order_additional" // 客服工单完成 ) type SendSmsParam struct { - Mobile string // 手机号 - Type SmsType // 验证码类型 - Expired int64 // 过期时间,秒数 - Code int64 // 验证码 + Mobile string // 手机号 + Type SmsType // 验证码类型 + Replaces []Item } func CreateSendSmsRequest(param SendSmsParam) (req *SendSmsRequest) { @@ -36,10 +49,9 @@ func CreateSendSmsRequest(param SendSmsParam) (req *SendSmsRequest) { JsonRequest: &requests.JsonRequest{}, Mobile: param.Mobile, Type: param.Type, - Expired: param.Expired, - Code: param.Code, + Replaces: param.Replaces, } - req.InitWithApiInfo(HOST, VERSION, "/sms/agg/send") + req.InitWithApiInfo(HOST, VERSION, "/v1/sms/send") req.Method = requests.POST return }