package services import ( "errors" "fmt" "github.com/blinkbean/dingtalk" "hongze/hongze_robot/cache" "hongze/hongze_robot/models" "hongze/hongze_robot/utils" "strings" "time" ) func SendSms() { time.Sleep(time.Second) var err error defer func() { if err != nil { go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "SendSms Err:"+err.Error(), utils.EmailSendToUsers) } }() configItem, err := cache.GetSmsConfigByCache("mobile") if err != nil { return } if configItem.ConfigValue == "" { err = errors.New("mobile-val is empty") return } items, err := models.GetSmsRecord() if err != nil { return } var dingToken = []string{} if utils.RunMode == "release" { dingToken = []string{ "5f9ae772343b20af806e1f8a6c27a3d8c1b57d8c36f468ab0a12d7eca1cf423c", "a3125f68a3b627443aa6756e2e973547d0bf3a346668f0f2794fb6d845e2ce68", "c13598ccb03fc6a2bfa2a7673237c9b375ba0e778a0f0db56ba358b01a9a8d89", } } else { dingToken = []string{ "d2506ab774a3978dac6e69f59814b6f3f669cdde6ceefad67c109e34038de87e", } } for _, v := range items { if strings.Contains(configItem.ConfigValue, v.Mobile) { smsDateTime := v.SmsDateTime.Format(utils.FormatDateTime) msg := []string{ "### " + v.Mobile, "---", "- " + v.Body + "", "- " + smsDateTime, } cli := dingtalk.InitDingTalk(dingToken, "hongze") //cli.SendTextMessage("content", dingtalk.WithAtAll()) err = cli.SendMarkDownMessageBySlice("华瑞信息", msg) if err != nil { return } models.ModifySmsRecordIsSend(v.Mobile, v.SmsDate) time.Sleep(1 * time.Second) } } } func AddUnionCode() { list, err := models.GetSmsRecordList() if err != nil { fmt.Println("GetSmsRecordList Err:" + err.Error()) return } for _, v := range list { fmt.Println(v.Id, v.Mobile) unionCode := utils.MD5(v.Mobile + v.Body + v.SmsDate) err = models.ModifySmsRecordUnicode(unionCode, v.Id) if err != nil { fmt.Println("ModifySmsRecordUnicode Err:" + err.Error()) return } } } //func init() { // fmt.Println("start 111") // AddUnionCode() // fmt.Println("end 111") //}