sms_send.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package services
  2. import (
  3. "github.com/blinkbean/dingtalk"
  4. "hongze/hongze_robot/models"
  5. "hongze/hongze_robot/utils"
  6. "time"
  7. )
  8. func SendSms() {
  9. time.Sleep(time.Second)
  10. var err error
  11. defer func() {
  12. if err != nil {
  13. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "SendSms Err:"+err.Error(), utils.EmailSendToUsers)
  14. }
  15. }()
  16. items, err := models.GetSmsRecord()
  17. if err != nil {
  18. return
  19. }
  20. var dingToken = []string{
  21. "5f9ae772343b20af806e1f8a6c27a3d8c1b57d8c36f468ab0a12d7eca1cf423c",
  22. "a3125f68a3b627443aa6756e2e973547d0bf3a346668f0f2794fb6d845e2ce68",
  23. "c13598ccb03fc6a2bfa2a7673237c9b375ba0e778a0f0db56ba358b01a9a8d89",
  24. }
  25. for _, v := range items {
  26. smsDateTime := v.SmsDateTime.Format(utils.FormatDateTime)
  27. msg := []string{
  28. "### " + v.Mobile,
  29. "---",
  30. "- <font color=#00ff00 size=6>" + v.Body + "</font>",
  31. "- " + smsDateTime,
  32. }
  33. cli := dingtalk.InitDingTalk(dingToken, "hongze")
  34. //cli.SendTextMessage("content", dingtalk.WithAtAll())
  35. err = cli.SendMarkDownMessageBySlice("华瑞信息", msg)
  36. if err != nil {
  37. return
  38. }
  39. models.ModifySmsRecordIsSend(v.Mobile,v.SmsDate)
  40. }
  41. }