/// <summary>
 /// 往发送队列或者中转表中存储
 /// </summary>
 /// <param name="objSmsTask"></param>
 /// <param name="iBusinessID"></param>
 private void SendMessageQueueEx(SmsTaskEx objSmsTask, int iBusinessID)
 {
     if (iBusinessID != 1 || QueueManage <SmsTaskEx> .IsOverSelectLen(SmsSetIni.TaskQueuePath, SmsSetIni.QueueMaxlen))//如果不是HTTP类型或者消息队列已满
     {
         //添加进等待发送表
         if (objTaskBll.Add(objSmsTask))
         {
             //添加成功
         }
         else
         {
             //添加失败
         }
     }
     else   //添加进消息队列
     {
         QueueManage <SmsTaskEx> .SendQueue(SmsSetIni.TaskQueuePath, objSmsTask);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 发送线程执行函数
        /// </summary>
        /// <param name="iThreadNumber"></param>
        private static void SendProc(object iThreadNumber)
        {
            string strShow = string.Format("线程:{0}启动", iThreadNumber.ToString( ));

            ShowInfo(strShow);
            Thread.Sleep(500);
            SmsTaskEx        objSmsTask = new SmsTaskEx();
            SmsSpgateEx      objSpgate  = new SmsSpgateEx();
            string           strContent = string.Empty;
            string           strParams  = string.Empty;
            string           strPortUrl = string.Empty;
            string           strRet     = string.Empty;
            MapScriptEx      objMap     = new MapScriptEx();
            DataAdapterClass objAdapter = new DataAdapterClass();

            Model.SendRetValue objRetValue = new Model.SendRetValue();
            SmsHistory         objHist     = new SmsHistory();
            DateTime           oldLogTime  = DateTime.Now;

            while (!m_bExit)
            {
                if ((int)iThreadNumber == 0)
                {
                    TimeSpan tSpan     = DateTime.Now - oldLogTime;
                    int      iInterval = SmsSetIni.QueryInterval;
                    if (tSpan.TotalSeconds > iInterval)
                    {
                        strPortUrl = SmsSetIni.KeepQueryUrl + "OnlineQuery.aspx?";
                        oldLogTime = DateTime.Now;
                        strParams  = "url=" + HttpUtility.UrlEncode(SmsSetIni.KeepOnlineUrl) + "&" + DateTime.Now.ToString("yyyyMMddhhmmss");
                        strRet     = SmsHttpSend.HttpSendMessge(ref strPortUrl, ref strParams, 30000, 0, 2);
                    }
                }
                Thread.Sleep(SmsSetIni.SendThreadInterval);
                try
                {
                    objSmsTask = QueueManage <SmsTaskEx> .GetSingleMessage(SmsSetIni.TaskQueuePath);

                    if (objSmsTask == null)
                    {
                        //Thread.Sleep(100);
                        continue;
                    }
                    //strShow = string.Format("线程:{0}从消息队列中读取到数据。 。 。", iThreadNumber.ToString());
                    //ShowInfo(strShow);
                    //拿到后,从缓存中获取通道信息,获取通道各参数后发送
                    if (!DataCache.GetCacheSpgate(objSmsTask.SpgateNo, ref objSpgate))
                    {
                        //通道不存在,保存失败历史
                        continue;
                    }
                    strContent = ConvertString(objSmsTask.MsgContent, objSpgate.EncodeType);
                    strParams  = string.Format(objSpgate.SendParams, objSmsTask.PhoneList.Substring(0, objSmsTask.PhoneList.Length - 1),
                                               strContent, objSmsTask.PhoneNum, objSmsTask.SubPort + objSmsTask.SubPortEx, objSmsTask.SpgateNo);
                    strPortUrl = objSpgate.PortUrl;
                    //发送
                    strRet = SmsHttpSend.HttpSendMessge(ref strPortUrl, ref strParams, objSpgate.TimeOut, objSpgate.EncodeType, objSpgate.SendType);
                    //先处理PostError[-1111]返回值
                    if (strRet.IndexOf("PostError[-1111]") == 0)
                    {
                        //POST异常,重发
                        objHist.Add(objSmsTask, 1, "", strRet);
                        continue;
                    }
                    string strPtMsgID = string.Empty;
                    //拿到结果后,匹配返回值
                    if (!DataCache.GetCacheMapScript(objSpgate.MtScriptID, ref objMap))   //如果没有匹配到映射脚本
                    {
                        //无映射脚本,默认成功
                        objHist.Add(objSmsTask, 0, strPtMsgID, "无映射脚本,默认成功");
                        continue;
                    }
                    //找到了脚本
                    if (!objAdapter.AdapterSendResult(objMap.ScriptCode, strRet, ref objRetValue))
                    {
                        //映射异常,算成功
                        objHist.Add(objSmsTask, 0, strPtMsgID, objRetValue.RetInfo);
                        continue;
                    }
                    if (objRetValue.RetValue == 0) //发送成功了
                    {
                        objHist.Add(objSmsTask, objRetValue.RetValue, strPtMsgID, objRetValue.RetInfo);
                    }
                    else
                    {
                        if (objRetValue.IsNeedResend != 1)  //需要重发
                        {
                            //处理重发
                            //objHist.Add(objSmsTask, objRetValue.RetValue, strPtMsgID, objRetValue.RetInfo);
                        }
                        else
                        {
                            //保存失败历史
                            //objHist.Add(objSmsTask, objRetValue.RetValue, strPtMsgID, objRetValue.RetInfo);
                        }
                        objHist.Add(objSmsTask, objRetValue.RetValue, strPtMsgID, objRetValue.RetInfo);
                    }
                    //根据匹配到的返回值决定是否需要重发此数据,如果不重发,则保存至历史表中
                    //保存发送历史
                    ShowInfo(strRet);
                }
                catch (Exception e)
                {
                    ShowInfo(e.Message);
                    Thread.Sleep(2000);
                }
            }
            strShow = string.Format("线程:{0}退出", iThreadNumber.ToString());
            ShowInfo(strShow);
        }