package controllers import ( "hongze/hongze_robot/cache" "hongze/hongze_robot/models" "hongze/hongze_robot/services" "hongze/hongze_robot/utils" "strconv" "strings" "time" ) //短信管理 type SmsController struct { BaseCommonController } // @Title 短信转发接口 // @Description 短信转发接口 // @Param request body company.CompanyApplyApproveReq true "type json string" // @Success Ret=200 转发成功 // @router /send [post] func (this *SmsController) SmsSend() { br := new(models.BaseResponse).Init() var err error defer func() { if err != nil { utils.FileLog.Info("send msg err: %s", err.Error()) } this.Data["json"] = br this.ServeJSON() }() sign := this.GetString("Sign") address := this.GetString("Address") body := this.GetString("Body") name := this.GetString("Name") date := this.GetString("Date") utils.FileLog.Info("send msg: %s; %s; %s; %s; %s", sign, address, body, name, date) count, err := models.GetSmsRecordCount(address, date) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "失败,请联系技术" br.ErrMsg = "失败;Err:" + err.Error() return } item, err := cache.GetSmsConfigByCache("mobile") if err != nil { br.Msg = "失败,请联系技术" br.ErrMsg = "获取配置信息失败;Err:" + err.Error() return } if item.ConfigValue == "" { br.Msg = "失败,请联系技术" br.ErrMsg = "配置信息为空" return } isAdd := false //判断记录是否存在 if count <= 0 && strings.Contains(item.ConfigValue, address) { var tm time.Time if date != "" { smsDateInt64, _ := strconv.ParseInt(date, 10, 64) tm = time.Unix(smsDateInt64/1e3, 0) } record := new(models.SmsRecord) record.CreateTime = time.Now() record.ModifyTime = time.Now() record.IsSend = 0 record.SmsDateTime = tm record.Mobile = address record.SmsDate = date record.Body = body _, err = models.AddSmsRecord(record) if err != nil { br.Msg = "失败,请联系技术" br.ErrMsg = "新增记录失败;Err:" + err.Error() return } isAdd = true } if isAdd { go services.SendSms() } br.Ret = 200 br.Success = true br.Msg = "发送成功" } //func init() { // fmt.Println("start") // smsDate:=`1620290685894` // int64, err := strconv.ParseInt(smsDate, 10, 64) // fmt.Println(err) // tm:=time.Unix(int64/1e3,0) // fmt.Println(tm) // fmt.Println(tm.Format(utils.FormatDateTime)) // fmt.Println("end") //}