sms.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package controllers
  2. import (
  3. "hongze/hongze_robot/models"
  4. "hongze/hongze_robot/services"
  5. "hongze/hongze_robot/utils"
  6. "strconv"
  7. "time"
  8. )
  9. //短信管理
  10. type SmsController struct {
  11. BaseCommonController
  12. }
  13. // @Title 短信转发接口
  14. // @Description 短信转发接口
  15. // @Param request body company.CompanyApplyApproveReq true "type json string"
  16. // @Success Ret=200 转发成功
  17. // @router /send [post]
  18. func (this *SmsController) SmsSend() {
  19. br := new(models.BaseResponse).Init()
  20. var err error
  21. defer func() {
  22. if err != nil {
  23. utils.FileLog.Info("send msg err: %s", err.Error())
  24. }
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. sign := this.GetString("Sign")
  29. address := this.GetString("Address")
  30. body := this.GetString("Body")
  31. name := this.GetString("Name")
  32. date := this.GetString("Date")
  33. utils.FileLog.Info("send msg: %s; %s; %s; %s; %s", sign, address, body, name, date)
  34. count, err := models.GetSmsRecordCount(address, date)
  35. if err != nil && err.Error() != utils.ErrNoRow() {
  36. br.Msg = "失败,请联系技术"
  37. br.ErrMsg = "失败;Err:" + err.Error()
  38. return
  39. }
  40. //判断记录是否存在
  41. if count <= 0 {
  42. var tm time.Time
  43. if date != "" {
  44. smsDateInt64, _ := strconv.ParseInt(date, 10, 64)
  45. tm = time.Unix(smsDateInt64/1e3, 0)
  46. }
  47. record := new(models.SmsRecord)
  48. record.CreateTime = time.Now()
  49. record.ModifyTime = time.Now()
  50. record.IsSend = 0
  51. record.SmsDateTime = tm
  52. record.Mobile = address
  53. record.SmsDate = date
  54. record.Body = body
  55. _, err = models.AddSmsRecord(record)
  56. if err != nil {
  57. br.Msg = "失败,请联系技术"
  58. br.ErrMsg = "新增记录失败;Err:" + err.Error()
  59. return
  60. }
  61. }
  62. go services.SendSms()
  63. br.Ret = 200
  64. br.Success = true
  65. br.Msg = "发送成功"
  66. }
  67. //func init() {
  68. // fmt.Println("start")
  69. // smsDate:=`1620290685894`
  70. // int64, err := strconv.ParseInt(smsDate, 10, 64)
  71. // fmt.Println(err)
  72. // tm:=time.Unix(int64/1e3,0)
  73. // fmt.Println(tm)
  74. // fmt.Println(tm.Format(utils.FormatDateTime))
  75. // fmt.Println("end")
  76. //}