/// <summary> /// 把短信发送到MQ /// 负责拆包,递交出去的PlainSMS /// </summary> /// <param name="sms"></param> public void SendSMS(SMSDTO sms) { foreach (var smsnumber in sms.SMSNumbers) { if (smsnumber.NumberCount > this.GatewayConfig.MaxPackageSize) { List <string> Numbers = smsnumber.Numbers.Split(',').ToList(); for (int i = 0; i < Numbers.Count; i = i + this.GatewayConfig.MaxPackageSize) { var numbers = Numbers.Skip(i).Take(this.GatewayConfig.MaxPackageSize).ToList(); PlainSMS tmp = PlainSMS.CreatePlainSMS(sms.Message, numbers, smsnumber.Operator); this.SendMQHelper.PublishMessage(JsonConvert.SerializeObject(tmp), sms.Message.SMSLevel); } } else { PlainSMS tmp = PlainSMS.CreatePlainSMS(sms.Message, smsnumber); this.SendMQHelper.PublishMessage(JsonConvert.SerializeObject(tmp), sms.Message.SMSLevel); } } }
private static bool SMSMQHelper_RecieveMessage(RabbitMQHelper mq, string message) { try { MessageTools.MessageHelper.Instance.WirteTest(message); var sms = JsonConvert.DeserializeObject <SMSDTO>(message); SMSOriginalSend.Send(sms); foreach (var smsnumber in sms.SMSNumbers) { try { GatewayHelper gateway = GetGatewayByOperator(sms.Message.Channel, smsnumber.Operator); if (gateway == null) { SendFail(PlainSMS.CreatePlainSMS(sms.Message, smsnumber), "没有找到可用网关!", 2022); continue; } SMSDTO dto = new SMSDTO() { Message = sms.Message }; dto.SMSNumbers = new List <SMSNumber>() { smsnumber }; gateway.SendSMS(dto); } catch (Exception ex) { //记录异常 LogHelper.LogError("SendQueue", "SMSMQHelper_RecieveMessage", "发送短信时发生异常:" + ex.ToString()); SendFail(PlainSMS.CreatePlainSMS(sms.Message, smsnumber), "发送时失败!", 99); } } return(true); } catch (Exception ex) { LogHelper.LogError("SendQueue", "SMSMQHelper_RecieveMessage", "解析短信时发生异常:" + ex.ToString()); LogHelper.LogError("SendQueue", "SMSMQHelper_RecieveMessage", message); // throw ex; return(true); } }