This commit is contained in:
jiangyong27 2025-03-25 17:55:50 +08:00
parent d299d9503c
commit 272f7889b2
1 changed files with 15 additions and 9 deletions

View File

@ -12,13 +12,19 @@ import (
)
type GetuiSms struct {
config *GetuiConfig
token string
appid string
appkey string
masterSecret string
templateId string
token string
}
func NewGetuiSms(c *GetuiConfig) *GetuiSms {
func NewGetuiSms(appid, appkey, masterSecret, templateId string) *GetuiSms {
return &GetuiSms{
config: c,
appkey: appkey,
appid: appid,
masterSecret: masterSecret,
templateId: templateId,
}
}
@ -46,11 +52,11 @@ func (g *GetuiSms) getResult(rspBody []byte) (map[string]interface{}, error) {
func (g *GetuiSms) Token() string {
timestamp := cast.ToString(time.Now().UnixMilli())
signStr := fmt.Sprintf("%s%s%s", g.config.AppKey, timestamp, g.config.MasterSecret)
signStr := fmt.Sprintf("%s%s%s", g.appkey, timestamp, g.masterSecret)
reqUrl := "https://openapi-smsp.getui.com/v1/sps/auth_sign"
params := make(map[string]string)
params["timestamp"] = timestamp
params["appId"] = g.config.AppId
params["appId"] = g.appid
params["sign"] = util.Sha256(signStr)
reqBody, _ := json.Marshal(params)
rspBody, err := HttpPostJson(reqUrl, nil, reqBody)
@ -72,13 +78,13 @@ func (g *GetuiSms) Token() string {
return g.token
}
func (g *GetuiSms) Send(tmpId, phone string, data map[string]string) error {
func (g *GetuiSms) Send(phone string, data map[string]string) error {
reqUrl := "https://openapi-smsp.getui.com/v1/sps/push_sms_list"
params := make(map[string]interface{})
params["authToken"] = g.Token()
params["appId"] = g.config.AppId
params["smsTemplateId"] = tmpId
params["appId"] = g.appid
params["smsTemplateId"] = g.templateId
params["smsParam"] = data
params["recNum"] = []string{goutil.Md5(phone)}
reqBody, _ := json.Marshal(params)