heyuntao
2023-10-23 45e3e2f4b3a55c3949c8a5bc5e6928f0cc2cacb1
no message
已修改4个文件
91 ■■■■ 文件已修改
api/Api.Operater/Controllers/sms/SmsBusinessController.cs 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/SmsSendTool/Program.cs 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/SmsSendTool/SendMain.cs 50 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/SmsSendTool/appsettings.json 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/Api.Operater/Controllers/sms/SmsBusinessController.cs
@@ -1,4 +1,5 @@
using CommonUtil;
using CommonUtil.Web;
using Microsoft.AspNetCore.Mvc;
using Operater.DAL;
using Operater.DbModel;
@@ -100,6 +101,10 @@
            };
            bool issuccess = new SmsSendDAL().Insert(smsSend);
            //发送待审核消息
            string shCount = "1";
            string warStr = "您有待审核的任务\n>类型:待审核\n>数量:" + shCount + "\n>查看:[点击处理](https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7a9a40880081340d&redirect_uri=https%3A%2F%2Fsms.ushopvip.com%2Fpages%2Fad_page%2Ftrans&response_type=code&scope=snsapi_base&state=gzh#wechat_redirect)";
            SendQwGroup.SendMessage(warStr);
            return Success(issuccess);
        }
api/SmsSendTool/Program.cs
@@ -4,6 +4,8 @@
using SqlSugar;
using System;
using System.Threading;
using System.Collections.Generic;
using CommonUtil.Web;
namespace SmsSendTool
{
@@ -28,6 +30,24 @@
                                sendMain.SendSms(smssend.Id);
                            }
                        }
                        //查询长时间未完成的任务
                        List<int?> sstaus =new  List<int?>{0,1,2,3,4,5 };
                        var send_where_expression1 = Expressionable.Create<SmsSend>().And(m => sstaus.Contains(m.Sendstatus)).And(m=>m.Wantsendtime>DateTime.Now.AddMinutes(30)).And(m => m.Isshowsend == 0).ToExpression();
                        var smssendlist1 = new SmsSendDAL().ListGet(send_where_expression1, t => t.Createtime, DbEnum.OrderType.Asc);
                        if (smssendlist1 != null && smssendlist1.Count > 0)
                        {
                            Console.WriteLine("发送长时间未完成任务消息");
                            var timer = new Timer(v => SendMessage(smssendlist1.Count, 1), null, 0, 5 * 60 * 1000);
                        }
                        //查询待审核的任务
                        var send_where_expression2 = Expressionable.Create<SmsSend>().And( m => m.Sendstatus == 0).And(m => m.Isshowsend == 0).ToExpression();
                        var smssendlist2 = new SmsSendDAL().ListGet(send_where_expression2, t => t.Createtime, DbEnum.OrderType.Asc);
                        if (smssendlist2 != null && smssendlist2.Count > 0)
                        {
                            Console.WriteLine("发送待审核任务消息");
                            var timer = new Timer(v => SendMessage(smssendlist2.Count, 2), null, 0, 5 * 60 * 1000);
                        }
                    }
                    catch (Exception ex)
@@ -44,5 +64,20 @@
            Console.ReadLine();
        }
        public static void SendMessage(int strcount,int type)
        {
            switch (type)
            {
                case 1:
                    string warStr1 = "长时间未发送完成任务\n>类型:任务异常\n>数量:" + strcount;
                    SendQwGroup.SendMessage(warStr1);
                    break;
                case 2:
                    string warStr2 = "您有待审核的任务\n>类型:待审核\n>数量:" + strcount + "\n>查看:[点击处理](https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7a9a40880081340d&redirect_uri=https%3A%2F%2Fsms.ushopvip.com%2Fpages%2Fad_page%2Ftrans&response_type=code&scope=snsapi_base&state=gzh#wechat_redirect)";
                    SendQwGroup.SendMessage(warStr2);
                    break;
            }
        }
    }
}
api/SmsSendTool/SendMain.cs
@@ -1,4 +1,5 @@
using CommonUtil;
using CommonUtil.Web;
using Operater.DAL;
using Operater.DbModel;
using SqlSugar;
@@ -20,7 +21,7 @@
                if (smssend == null)
                {
                    Console.WriteLine($"任务ID:{id},任务不存在");
                    UpdateSmsSendStatus(6, "任务不存在", id);
                   // UpdateSmsSendStatus(6, "任务不存在", id);
                    return true;
                }
                //判断任务状态是否是审核通过
@@ -33,7 +34,7 @@
                if (smssend.Isshowsend == 1)
                {
                    Console.WriteLine($"任务ID:{id},任务已被删除");
                    UpdateSmsSendStatus(6, "任务已被删除", id);
                  //  UpdateSmsSendStatus(6, "任务已被删除", id);
                    return true;
                }
                //判断定时时间是否大于当前时间
@@ -44,7 +45,7 @@
                }
                //修改发送状态为发送中
                UpdateSmsSendStatus(4, "", id);
                UpdateSmsSendStatus(4, "", id, DateTime.Now);
                //发送短信
                Send(smssend);
@@ -79,13 +80,15 @@
            if (!MobileUtils.IsPhone(smsSend.Mobile))
            {
                Console.WriteLine($"任务ID:{smsSend.Id},手机号不正确");
                UpdateSmsSendStatus(7, "手机号不正确", smsSend.Id);
                UpdateSmsSendStatus(7, "手机号不正确", smsSend.Id, DateTime.Now);
                SendQwGroup.SendMessage($"手机号不正确:{smsSend.Id}");
                return;
            }
            if (smscontent.Contains("?????"))
            {
                LogUtil.Error($"发送异常,id:{smsSend.Id}");
                UpdateSmsSendStatus(7, "短信异常", smsSend.Id);
                UpdateSmsSendStatus(7, "短信异常", smsSend.Id, DateTime.Now);
                SendQwGroup.SendMessage($"文案异常:{smsSend.Id}");
                return;
            }
            int thisSmsCount= smscontent.Length <= 70 ? 1 : smscontent.Length % 70 == 0 ? (smscontent.Length / 70) : (smscontent.Length / 70 + 1);//短信计费
@@ -98,7 +101,8 @@
            if (memberinfo == null)
            {
                LogUtil.Error($"用户不存在,id:{smsSend.Id}");
                UpdateSmsSendStatus(7, "用户不存在", smsSend.Id);
                UpdateSmsSendStatus(7, "用户不存在", smsSend.Id, DateTime.Now);
                SendQwGroup.SendMessage($"用户不存在:{smsSend.Id}");
                return;
            }
            else
@@ -106,9 +110,18 @@
                if(memberinfo.Smscount< thisSmsCount)
                {
                    LogUtil.Error($"余额不足,id:{smsSend.Id}");
                    UpdateSmsSendStatus(7, "余额不足", smsSend.Id);
                    UpdateSmsSendStatus(7, "余额不足", smsSend.Id, DateTime.Now);
                    SendQwGroup.SendMessage($"余额不足:{smsSend.Id}");
                    return;
                }
            }
            //检查短信状态
            //根据ID获取任务
            var smssend = new SmsSendDAL().GetSingle(s => s.Id == smsSend.Id);
            if (smssend.Sendstatus != 4)
            {
                Console.WriteLine($"手机号:{smsSend.Mobile},状态已变更,不执行");
                return;
            }
            string jsonsend= "{mobile:\"" + smsSend.Mobile + "\",content:\"" + smscontent.Replace("\"", "“").Replace("'", "’") + "\",appendid:\"\",\"uid\":\"\"}";
@@ -123,7 +136,7 @@
                if (scount == 0)
                {
                    LogUtil.Error($",id:{smsSend.Id}");
                    UpdateSmsSendStatus(7, "扣费失败", smsSend.Id);
                    UpdateSmsSendStatus(7, "扣费失败", smsSend.Id, DateTime.Now);
                    return;
                }
@@ -131,7 +144,7 @@
                //插入发送成功记录
                string inserthistorysql = $"INSERT INTO `sms_sender`.`sms_sendhistory`(`id`, `mobile`, `succedsmscount`, `sendstatus`, `sendtime`, `smscontent`, `memo`, `memberid`, `isshowsend`, `mainid`, `sendid`, `isread`) VALUES ('{Guid.NewGuid().ToString()}', '{smsSend.Mobile}', {thisSmsCount}, 0, '{DateTime.Now}', '{smscontent}', '1', '{smsSend.Memberid}', 0, '{smsSend.Id}', '{sendid}', 0);";
                //查看是否存在发送记录
                var record_where_expression = Expressionable.Create<SmsSendhistory>().And(m => m.Mainid == smsSend.Id).ToExpression();
                var record_where_expression = Expressionable.Create<SmsSendhistory>().And(m => m.Mainid == smsSend.Id).And(m=>m.Memo=="1").ToExpression();
                var exist_record = new SmsSendhistoryDAL().ListGet(record_where_expression);
                if (exist_record != null&&exist_record.Count>0)
                {
@@ -175,6 +188,18 @@
            else
            {
                Console.WriteLine($"手机号:{smsSend.Mobile},发送失败");
                //查看是否存在发送记录
                var record_where_expression = Expressionable.Create<SmsSendhistory>().And(m => m.Mainid == smsSend.Id).And(m => m.Memo == "1").ToExpression();
                var exist_record = new SmsSendhistoryDAL().ListGet(record_where_expression);
                if (exist_record != null && exist_record.Count > 0)
                {
                    //删除记录
                    foreach (var record in exist_record)
                    {
                        new SmsSendhistoryDAL().Delete("", record.Id);
                    }
                }
                SmsSendhistory sendhistory = new SmsSendhistory
                {
                    Id = Guid.NewGuid().ToString(),
@@ -191,16 +216,17 @@
                    IsRead = 0,
                    ReaLsuccedsmscount = realSmsCount
                };
                bool issuccess = new SmsSendDAL().Insert(smsSend);
                bool issuccess = new SmsSendhistoryDAL().Insert(sendhistory);
                //修改短信任务状态
                UpdateSmsSendStatus(7, "发送失败", smsSend.Id);
                UpdateSmsSendStatus(7, "发送失败", smsSend.Id,DateTime.Now);
                SendQwGroup.SendMessage($"短信异常:{smsSend.Id}"+ "strResult:"+ strResult);
                LogUtil.Error($"短信异常:{smsSend.Id}", "公共号短信异常");
            }
           
        }
        public bool UpdateSmsSendStatus(int status,string memo,string id)
        public bool UpdateSmsSendStatus(int status,string memo,string id,DateTime sendtime)
        {
            SmsSend updateSmssend = new SmsSend
            {
api/SmsSendTool/appsettings.json
@@ -26,6 +26,7 @@
    }
  },
  "AllowedHosts": "*",
  "qw_webhook": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=1e5a8b47-b108-40a6-9a29-d629863bd066",
  "DbConnection": [
    {
      //测试