12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package controllers
- import (
- "hongze/hongze_robot/models"
- "hongze/hongze_robot/utils"
- "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"}
- msg := []string{
- "### " + address,
- "---",
- "- <font color=#00ff00 size=6>" + body + "</font>",
- "- " + date,
- }
- 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 = "发送成功"
- }
|