Пример #1
0
        void tmrMO_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                string   msg      = "";
                string   mobile   = "";
                DateTime datetime = DateTime.Now;
                string   md5p     = MD5Helper.GetMD5(password);
                string   post     = string.Format("Account={0}&Password={1}", account, md5p);
                string   t        = HTTPRequest.PostWebRequest(moUrl, post, System.Text.Encoding.UTF8);
                Console.WriteLine("原始MO查询消息: " + t);
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(t);
                XmlElement root = null;
                root = doc.DocumentElement;
                XmlNodeList listNodes = root.ChildNodes;
                foreach (XmlNode node in listNodes)
                {
                    if (node.Name == "response")
                    {
                        int c = int.Parse(node.InnerText);
                        if (c == 0)
                        {
                            return;
                        }
                        if (c < 0)
                        {
                            Console.WriteLine(GetErrorMsg(c));
                            return;
                        }
                    }
                    else
                    {
                        foreach (XmlNode cNode in node.ChildNodes)
                        {
                            switch (cNode.Name)
                            {
                            case "phone":
                                mobile = cNode.InnerText;
                                break;

                            case "content":
                                msg = HttpUtility.UrlDecode(cNode.InnerText);
                                break;

                            case "sendTime":

                                if (!DateTime.TryParse(cNode.InnerText, out datetime))
                                {
                                    datetime = DateTime.Now;
                                }
                                break;
                            }
                        }
                        if (DeliverEvent != null)
                        {
                            DeliverEventArgs re = new DeliverEventArgs(Guid.NewGuid().ToString(), datetime, msg, mobile, SrcID, "");
                            DeliverEvent(this, re);
                            string tr = JsonSerialize.Instance.Serialize <DeliverEventArgs>(re);
                            LogClient.LogHelper.LogInfo("WFLTQY", "MO ->", tr);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                LogClient.LogHelper.LogInfo("WFLTQY", "MO Error ->", ex.Message);
            }
        }
Пример #2
0
 public void SendSMS(PlainSMS sms)
 {
     try
     {
         string post = "";
         for (int i = 0; i < sms.Number.Count; i++)
         {
             string md5p = MD5Helper.GetMD5(password);
             post = "Account=" + account + "&Password="******"&SubCode=&Phone=" + sms.Number[i] + "&Content=" + sms.Content + sms.Signature + "&SendTime=";
             string      t     = HTTPRequest.PostWebRequest(sendUrl, post, System.Text.Encoding.UTF8);
             bool        ok    = false;
             string      rmsg  = "";
             string      msgid = "";
             XmlDocument doc   = new XmlDocument();
             doc.LoadXml(t);
             XmlElement root = null;
             root = doc.DocumentElement;
             XmlNodeList listNodes = root.ChildNodes;
             foreach (XmlNode node in listNodes)
             {
                 if (node.Name == "response")
                 {
                     int c = int.Parse(node.InnerText);
                     if (c <= 0)
                     {
                         msgid = System.Guid.NewGuid().ToString();
                         rmsg  = GetSendErrorMsg(c);
                         break;
                     }
                 }
                 else
                 {
                     ok   = true;
                     rmsg = "短信提交成功.";
                     foreach (XmlNode n in node.ChildNodes)
                     {
                         switch (n.Name)
                         {
                         case "smsID":
                             msgid = n.InnerText;
                             break;
                         }
                     }
                 }
             }
             int r = 0;
             if (!ok)
             {
                 r = 101;
             }
             SendEventArgs se     = new SendEventArgs(sms, msgid, ok, (ushort)(2000 + r), rmsg, 1, 1);
             string        result = JsonSerialize.Instance.Serialize <SendEventArgs>(se);
             Console.WriteLine("短信发送结果:" + result);
             ExSendEventArgs ese = new ExSendEventArgs(se);
             if (ok)
             {
                 //sends.Add(se.Serial,ese);
                 sends.Enqueue(ese);
                 LogClient.LogHelper.LogInfo("WFLTQY", "SendSMS OK ->", result);
             }
             else
             {
                 LogClient.LogHelper.LogInfo("WFLTQY", "SendSMS Fail ->", result);
             }
             if (SendEvent != null)
             {
                 SendEvent(this, se);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         LogClient.LogHelper.LogInfo("WFLTQY", "SendSMS Error ->", ex.Message);
     }
 }
Пример #3
0
        void tmrReport_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (reportProcess)
            {
                return;
            }
            reportProcess = true;
            try
            {
                if (sends.Count > 0)
                {
                    var ese = sends.Dequeue();

                    if ((DateTime.Now - ese.Time).TotalDays >= 2)
                    {
                        ReportEventArgs re = new ReportEventArgs(ese.SendEventArgs.SerialNumber, true, 2100, "状态报告超时,默认成功.", DateTime.Now);
                        ReportEvent(this, re);
                        string ttr = JsonSerialize.Instance.Serialize <ReportEventArgs>(re);
                        Console.WriteLine("超时返回状态报告:" + JsonSerialize.Instance.Serialize <ReportEventArgs>(re));
                        LogClient.LogHelper.LogInfo("WFLTQY", "GetReport Timeout ->", ttr);
                        reportProcess = false;
                        tmrReport_Elapsed(null, null);
                        return;
                    }



                    string   msgid    = "";
                    bool     ok       = true;
                    DateTime datetime = DateTime.Now;
                    string   md5p     = MD5Helper.GetMD5(password);
                    string   post     = string.Format("Account={0}&Password={1}&SmsID={2}", account, md5p, ese.SendEventArgs.SerialNumber);
                    string   t        = HTTPRequest.PostWebRequest(statusUrl, post, System.Text.Encoding.UTF8);
                    MessageHelper.Instance.WirteTest("提交返回原始内容: " + t);
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(t);
                    XmlElement root = null;
                    root = doc.DocumentElement;
                    XmlNodeList listNodes = root.ChildNodes;
                    foreach (XmlNode node in listNodes)
                    {
                        if (node.Name == "response")
                        {
                            int c = int.Parse(node.InnerText);
                            if (c == 0)
                            {
                                sends.Enqueue(ese);
                                reportProcess = false;
                                return;
                            }
                            if (c < 0)
                            {
                                sends.Enqueue(ese);
                                Console.WriteLine("获取状态报告:" + GetSendErrorMsg(c));
                                reportProcess = false;
                                return;
                            }
                        }
                        else
                        {
                            foreach (XmlNode cNode in node.ChildNodes)
                            {
                                switch (cNode.Name)
                                {
                                case "stat":
                                    if (cNode.InnerText == "0")
                                    {
                                        ok = true;
                                    }
                                    else
                                    {
                                        ok = false;
                                    }
                                    break;

                                case "smsID":
                                    msgid = cNode.InnerText;
                                    break;

                                case "phone":

                                    break;
                                }
                            }
                            if (ReportEvent != null)
                            {
                                ushort statecode;
                                string statetext = "发送成功。";
                                statecode = 2100;
                                if (!ok)
                                {
                                    statetext = "发送失败。";
                                }

                                ReportEventArgs re = new ReportEventArgs(msgid, ok, statecode, statetext, datetime);
                                ReportEvent(this, re);
                                string tr = JsonSerialize.Instance.Serialize <ReportEventArgs>(re);
                                Console.WriteLine("返回状态报告:" + tr);
                                LogClient.LogHelper.LogInfo("WFLTQY", "GetReport Process ->", tr);
                            }
                        }
                    }
                }

                //List<string> rkeys = new List<string>();
                //foreach (string key in sends.Keys)
                //{
                //    if ((DateTime.Now - sends[key].Time).TotalDays >= 2)
                //    {
                //        ReportEventArgs re = new ReportEventArgs(sends[key].SendEventArgs.Serial, true, 2100, "状态报告超时,默认成功.", DateTime.Now);
                //        ReportEvent(this, re);
                //        string ttr = JsonSerialize.Instance.Serialize<ReportEventArgs>(re);
                //        Console.WriteLine("超时返回状态报告:" + JsonSerialize.Instance.Serialize<ReportEventArgs>(re));
                //        LogClient.LogHelper.LogInfo("WFLTQY", "GetReport Timeout ->", ttr);
                //        rkeys.Add(key);
                //    }
                //}
                //foreach (string key in rkeys)
                //{
                //    sends.Remove(key);
                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                LogClient.LogHelper.LogInfo("WFLTQY", "GetReport Error ->", ex.Message);
            }
            reportProcess = false;
        }