Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        static void LoadChannel()
        {
            var channels = ChannelDB.GetChannels();
            var gateways = GatewayConfigDB.GetConfigs();

            foreach (var ch in channels)
            {
                List <GatewayHelper> gatewayHelpers = new List <GatewayHelper>();
                List <string>        gatewayIds     = ChannelDB.GetGatewaysByChannel(ch.ChannelID);
                foreach (var gid in gatewayIds)
                {
                    var gatewayconfig = gateways.FirstOrDefault(g => g.Gateway == gid);
                    if (gatewayconfig == null)
                    {
                        throw new Exception(ch.ChannelName + " 找不到网关" + gid + "的配置");
                    }
                    GatewayHelper gh = new GatewayHelper(gatewayconfig);
                    gatewayHelpers.Add(gh);
                }
                Channels.Add(ch.ChannelID, gatewayHelpers);
            }
        }