sms优化
This commit is contained in:
parent
7c96d7163b
commit
3652d43f34
@ -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
|
||||
|
@ -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{
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user