package controllers import ( "hongze/hongze_robot/models" "hongze/hongze_robot/utils" "strconv" "time" "github.com/blinkbean/dingtalk" ) //短信管理 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 } //判断记录是否存在 if count <= 0 { var dingToken = []string{"5f9ae772343b20af806e1f8a6c27a3d8c1b57d8c36f468ab0a12d7eca1cf423c"} var smsDateTime string if date != "" { smsDateInt64, _ := strconv.ParseInt(date, 10, 64) tm := time.Unix(smsDateInt64/1e3, 0) smsDateTime = tm.Format(utils.FormatDateTime) } if smsDateTime == "" { smsDateTime = date } msg := []string{ "### " + address, "---", "- " + body + "", "- " + smsDateTime, } cli := dingtalk.InitDingTalk(dingToken, "hongze") //cli.SendTextMessage("content", dingtalk.WithAtAll()) err = cli.SendMarkDownMessageBySlice("华瑞信息", msg) if err != nil { br.Msg = "失败,请联系技术" br.ErrMsg = "发送钉钉消息失败;Err:" + err.Error() return } record := new(models.SmsRecord) record.CreateTime = time.Now() record.Mobile = address record.SmsDate = date record.Body = body _, err = models.AddSmsRecord(record) if err != nil { br.Msg = "失败,请联系技术" br.ErrMsg = "新增记录失败;Err:" + err.Error() return } } 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") //}