package yunpian import ( "errors" "fmt" "stat/common/log" ypclnt "github.com/yunpian/yunpian-go-sdk/sdk" ) //YunPian 云片短信 type YunPian struct { Apikey string Tmpl string } //Send 发送验证码 func (yun *YunPian) Send(mobile string, code string) error { text := fmt.Sprintf(yun.Tmpl, code) clnt := ypclnt.New(yun.Apikey) param := ypclnt.NewParam(2) param[ypclnt.MOBILE] = mobile param[ypclnt.TEXT] = text resp := clnt.Sms().SingleSend(param) if resp == nil { log.Error("YunPian send error", log.Any("mobile", mobile), log.Any("code", code)) return errors.New("SingleSend error") } if !resp.IsSucc() { log.Error("YunPian send fail:", log.Any("resp", resp)) return errors.New("SingleSend fail") } return nil }