瀏覽代碼

新增发送钉钉消息

rdluck 3 年之前
父節點
當前提交
2bec007bac
共有 3 個文件被更改,包括 72 次插入9 次删除
  1. 41 8
      controllers/sms.go
  2. 1 1
      models/db.go
  3. 30 0
      models/sms_record.go

+ 41 - 8
controllers/sms.go

@@ -3,6 +3,9 @@ package controllers
 import (
 	"hongze/hongze_robot/models"
 	"hongze/hongze_robot/utils"
+	"time"
+
+	"github.com/blinkbean/dingtalk"
 )
 
 //短信管理
@@ -10,7 +13,6 @@ type SmsController struct {
 	BaseCommonController
 }
 
-
 // @Title 短信转发接口
 // @Description 短信转发接口
 // @Param	request	body company.CompanyApplyApproveReq true "type json string"
@@ -22,14 +24,45 @@ func (this *SmsController) SmsSend() {
 		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")
+	sign := this.GetString("Sign")
+	address := this.GetString("Address")
+	body := this.GetString("Body")
+	name := this.GetString("Name")
+	date := this.GetString("Date")
+	utils.FileLog.Info(" %s; %s; %s; %s; %s", sign, address, body, name, date)
 
-	utils.FileLog.Info(" %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())
+		cli.SendMarkDownMessageBySlice("测试测试", msg)
+
+		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 = "发送成功"
-}
+}

+ 1 - 1
models/db.go

@@ -14,6 +14,6 @@ func init() {
 
 	//注册对象
 	orm.RegisterModel(
-
+		new(SmsRecord),
 	)
 }

+ 30 - 0
models/sms_record.go

@@ -0,0 +1,30 @@
+package models
+
+import (
+	"github.com/astaxie/beego/orm"
+	"time"
+)
+
+type SmsRecord struct {
+	Id         int `orm:"column(id);pk"`
+	Body       string
+	Mobile     string
+	SmsDate    string
+	CreateTime time.Time
+}
+
+//新增视频
+func AddSmsRecord(item *SmsRecord) (newId int64, err error) {
+	o := orm.NewOrm()
+	newId, err = o.Insert(item)
+	return
+}
+
+func GetSmsRecordCount(mobile, smsDate string) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count
+			FROM sms_record AS a 
+            WHERE mobile=? AND sms_date=? `
+	err = o.Raw(sql, mobile, smsDate).QueryRow(&count)
+	return
+}