using CommonUtil;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using Operater.DAL;
|
using Operater.DbModel;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace ReceiveSmsMq
|
{
|
public class ReceiveSmsHandle
|
{
|
public static void ReceiveSms(string message)
|
{
|
Console.WriteLine(message);
|
JObject messJob = (JObject)JsonConvert.DeserializeObject(message.Replace(" ", ""));
|
if (string.IsNullOrEmpty(messJob["status"].ToString()))
|
{
|
//短信回复
|
string mobile = messJob["mobile"].ToString();
|
string smscontent = messJob["content"].ToString();
|
string sendid= messJob["msgid"].ToString();
|
//根据sendid查询记录
|
var history_where_expression = Expressionable.Create<SmsSendhistory>().And(m => m.Sendid == sendid).ToExpression();
|
var sendhistory = new SmsSendhistoryDAL().GetFirst(history_where_expression);
|
if (sendhistory != null)
|
{
|
//添加回复内容
|
SmsSendhistory smsSendhistory = new SmsSendhistory
|
{
|
Id = Guid.NewGuid().ToString(),
|
Mobile = mobile,
|
Succedsmscount = 1,
|
Sendstatus = 0,
|
Sendtime = DateTime.Now,
|
Smscontent = smscontent,
|
Memo = "1",
|
Memberid = sendhistory.Memberid,
|
Isshowsend = 0,
|
Mainid = sendhistory.Mainid,
|
Sendid = sendid,
|
IsRead = 0,
|
ReaLsuccedsmscount = 1
|
};
|
bool issuccess = new SmsSendhistoryDAL().Insert(smsSendhistory);
|
if (issuccess)
|
{
|
//修改短信任务状态
|
SmsSend updateSmssend = new SmsSend
|
{
|
Sendstatus = 8,
|
};
|
int successcount = new SmsSendDAL().Update(updateSmssend, m => new { m.Sendstatus }, s => s.Id == sendhistory.Mainid);
|
}
|
}
|
|
}
|
else
|
{
|
//短信回执
|
string status = messJob["status"].ToString().Equals("1") ? "1" : "2"; //1成功 2失败
|
string desc_state = messJob["status"].ToString().Equals("1") ? "DELIVRD" : messJob["desc_state"].ToString();
|
string sendid = messJob["msgid"].ToString();
|
if (status == "2")
|
{
|
//根据sendid查询记录
|
var history_where_expression = Expressionable.Create<SmsSendhistory>().And(m => m.Sendid == sendid).ToExpression();
|
var sendhistory = new SmsSendhistoryDAL().GetSingle(history_where_expression);
|
//修改发送记录为失败
|
SmsSendhistory smsSendhistory = new SmsSendhistory
|
{
|
Sendstatus=1
|
};
|
int his_successcount = new SmsSendhistoryDAL().Update(smsSendhistory, m => new { m.Sendstatus }, s => s.Id == sendhistory.Id);
|
//修改任务为失败
|
SmsSend updateSmssend = new SmsSend
|
{
|
Sendstatus = 9,
|
};
|
int send_successcount = new SmsSendDAL().Update(updateSmssend, m => new { m.Sendstatus }, s => s.Id == sendhistory.Mainid);
|
//补短信
|
int member_successcount = new SmsMemberDAL().ExecuteCommand($"update sms_member set smscount=smscount+{sendhistory.Succedsmscount} where id='{sendhistory.Memberid}'");
|
if (member_successcount == 0)
|
{
|
LogUtil.Error($"补短信失败,任务id:{sendhistory.Mainid},执行sql:update sms_member set smscount=smscount+{sendhistory.Succedsmscount} where id='{sendhistory.Memberid}' ,mq消息:{message}", "补短信失败");
|
}
|
}
|
|
}
|
|
}
|
}
|
}
|