sms.go 625 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package sms
  2. import (
  3. "sync"
  4. "github.com/runningwater/gohub/pkg/config"
  5. )
  6. // Message 短信消息结构体
  7. type Message struct {
  8. Template string
  9. Data map[string]string
  10. Content string
  11. }
  12. // SMS 发送短信的操作类
  13. type SMS struct {
  14. Driver Driver
  15. }
  16. var once sync.Once
  17. var internalSMS *SMS
  18. func NewSMS() *SMS {
  19. once.Do(func() {
  20. internalSMS = &SMS{
  21. Driver: &AliyunDriver{},
  22. }
  23. })
  24. return internalSMS
  25. }
  26. // Send 发送短信
  27. func (s *SMS) Send(phone string, message Message) bool {
  28. // 调用短信驱动的发送方法
  29. return s.Driver.Send(phone, message, config.GetStringMapString("sms.aliyun"))
  30. }