Exemplo n.º 1
0
        protected void Button4_Click(object sender, EventArgs e)
        {
            string strScript = TextBox3.Text;
            string strSrc    = TextBox1.Text;

            SendRetValue retObj = new SendRetValue();

            testObj.AdapterSendResult(strScript, strSrc, ref retObj);
            Response.Write(retObj.OldRetValue + "<br/>"
                           + retObj.RetValue.ToString() + "<br/>"
                           + retObj.IsNeedResend.ToString() + "<br/>"
                           + retObj.RetInfo + "<br/>");
//             Microsoft.JScript.ArrayObject oo = (Microsoft.JScript.ArrayObject)testObj.RunJscriptCode(strScript);
//             for (int i = 0; i < (int)oo.length;i++ )
//             {
//                 if (i==0)
//                 {
//                     Response.Write(((Microsoft.JScript.JSObject)oo[i])["aaaa"].ToString() + "\r\n<br/>");
//                 }
//                 else
//                 Response.Write(oo[i].ToString()+"\r\n<br/>");
//             }
            //oo.
            //Response.Write(oo["aaa"].ToString());
        }
Exemplo 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);
        }
 /// <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);
 }