dao.go 920 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package monitor
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/app/service/main/videoup/conf"
  7. "go-common/library/log"
  8. xhttp "go-common/library/net/http/blademaster"
  9. )
  10. // Dao is message dao.
  11. type Dao struct {
  12. c *conf.Config
  13. client *xhttp.Client
  14. uri string
  15. }
  16. // New new a message dao.
  17. func New(c *conf.Config) (d *Dao) {
  18. //http://ops-mng.bilibili.co/api/sendsms&message=test&token=
  19. d = &Dao{
  20. c: c,
  21. client: xhttp.NewClient(c.HTTPClient.Read),
  22. uri: c.Host.Monitor + "/api/sendsms",
  23. }
  24. return
  25. }
  26. // Send send message to upper.
  27. func (d *Dao) Send(c context.Context, msg string) (err error) {
  28. params := url.Values{}
  29. params.Set("phone", d.c.Monitor.Tels)
  30. params.Set("message", msg)
  31. params.Set("token", "f5a658b2-5926-4b71-96c3-7d3777b7d256")
  32. if err = d.client.Get(c, d.uri, "", params, nil); err != nil {
  33. log.Info("sms error(%v)", err)
  34. fmt.Printf("sms error(%v)", err)
  35. }
  36. return
  37. }