123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- package services
- import (
- "context"
- "errors"
- "fmt"
- "strconv"
- "github.com/blinkbean/dingtalk"
- "hongze/hongze_robot/cache"
- "hongze/hongze_robot/models"
- "hongze/hongze_robot/utils"
- "strings"
- "time"
- )
- func SendSms() {
- time.Sleep(1 * 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) || strings.Contains(v.Body, "【华瑞资讯】") {
- smsDateTime := v.SmsDateTime.Format(utils.FormatDateTime)
- msg := []string{
- "### " + v.Mobile,
- "---",
- "- <font>" + v.Body + "</font>",
- "- " + 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)
- } else if _, ok := blackMobile[v.Mobile]; !ok {
- msgBody := "聚酯短信有: 第三方更换了手机号:" + v.Mobile
- go SendAlarmMsgByDingTalkRelease(utils.APPNAME, utils.RunMode, msgBody, 3)
- go SendAlarmMsgByEmail(utils.APPNAME, utils.RunMode, msgBody, utils.EmailSendToUsers, 3)
- }
- }
- }
- 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 CheckSmsSend(cont context.Context) (err error) {
- //未推送短信记录
- list, err := models.GetSmsRecord()
- if err != nil && err.Error() != utils.ErrNoRow() {
- utils.FileLog.Info("GetSmsRecord Err:" + err.Error())
- return err
- }
- listLen := len(list)
- if listLen > 5 {
- msgBody := "聚酯短信有: " + strconv.Itoa(listLen) + " 条未推送"
- go SendAlarmMsgByDingTalkRelease(utils.APPNAME, utils.RunMode, msgBody, 3)
- //发送短信
- SendSms()
- }
- return err
- }
|