sms.go 787 B

123456789101112131415161718192021222324252627282930313233343536
  1. package dao
  2. import (
  3. "context"
  4. "net/http"
  5. "net/url"
  6. "go-common/library/log"
  7. )
  8. const _smsURL = "http://ops-mng.bilibili.co/api/sendsms"
  9. func (d *Dao) SendSMS(msg string) (err error) {
  10. var (
  11. req *http.Request
  12. res struct {
  13. Result bool `json:"result"`
  14. }
  15. )
  16. params := url.Values{}
  17. params.Set("phone", d.c.SMS.Phone)
  18. params.Set("message", msg)
  19. params.Set("token", d.c.SMS.Token)
  20. if req, err = d.smsClient.NewRequest("GET", _smsURL+"?"+params.Encode(), "", nil); err != nil {
  21. return
  22. }
  23. if err = d.smsClient.Do(context.TODO(), req, &res); err != nil {
  24. log.Error("ops-mng sendsms url(%s) error(%v)", _smsURL+"?"+params.Encode(), err)
  25. return
  26. }
  27. if !res.Result {
  28. log.Error("ops-mng sendsms url(%s) error(%v)", _smsURL+"?"+params.Encode(), res.Result)
  29. }
  30. return
  31. }