Exemplo n.º 1
0
 void SWSet(SlidingWindow send)
 {
     lock (_sendWindows)
     {
         for (int i = 0; i < _sendWindows.Length; i++)
         {
             if (_sendWindows[i].Status == WindowStatus.Idle)
             {
                 _sendWindows[i]        = send;
                 _sendWindows[i].Status = WindowStatus.Fill;
                 _sendsCount++;
                 return;
             }
         }
     }
 }
Exemplo n.º 2
0
        private List <SlidingWindow> GetSend(SMS sms)
        {
            List <SlidingWindow> submits = new List <SlidingWindow>();

            //拆分长消息
            int pkSize;
            int pkNum = SMSSplit.GetSplitNumber(sms.Content, sms.Signature, out pkSize);

            if (pkNum > 1)
            {
                for (int j = 0; j < sms.Number.Count; j++)
                {
                    string content = sms.Content;
                    //发送号码
                    for (int i = 0; i < pkNum; i++)
                    {
                        Submit submit = new Submit(Sequence.Instance.CreateID());

                        submit.Pk_total  = (uint)pkNum;;
                        submit.Pk_number = (uint)(i + 1);;

                        submit.WapURL          = "";
                        submit.MsgType         = 6;                                                                 //  uint    6=MT 消息(SP 发给终端,包括WEB 上发送的点对点短消息);
                        submit.NeedReport      = sms.StatusReport == StatusReportType.Disable ? (byte)0 : (byte)1;; //  uint    0=不要求返回状态报告; 1=要求返回状态报告;
                        submit.Priority        = 1;
                        submit.ServiceID       = _setting.ServiceID;
                        submit.FeeType         = _setting.FeeType;
                        submit.FeeCode         = _setting.FeeCode;
                        submit.FixedFee        = "0";
                        submit.ValidTime       = _setting.ValidTime; //Util.Get_MMDDHHMMSS_String(DateTime.Now.AddHours(5)) + "032+";  // 存活有效期,格式遵循SMPP3.3协议。
                        submit.AtTime          = "";                 //Util.Get_MMDDHHMMSS_String(DateTime.Now) + "032+";     //      短消息定时发送时间,格式遵循SMPP3.3 以上版本协议。
                        submit.SrcTermID       = _setting.SrcID + sms.SPNumber;
                        submit.ChargeTermID    = _setting.ChargeTermID;
                        submit.DestTermID      = sms.Number.ToArray();
                        submit.DestTermIDCount = (uint)submit.DestTermID.Length;
                        submit.Reserve         = "";
                        submit.ProductID       = "";
                        submit.LinkID          = sms.LinkID;
                        submit.MsgFormat       = 8;//15;
                        submit.WapURL          = sms.WapURL;
                        submit.MsgSrc          = _setting.MsgSrc;

                        submit.MsgContent = SMSSplit.GetSubString(content, pkSize);
                        content           = content.Substring(submit.MsgContent.Length);
                        if (submit.Pk_number == pkNum)
                        {
                            submit.MsgContent = submit.MsgContent + sms.Signature;
                        }
                        submit.SetHeader();

                        SMS tsms = new SMS();
                        tsms.Account      = sms.Account;
                        tsms.Audit        = sms.Audit;
                        tsms.Channel      = sms.Channel;
                        tsms.Content      = submit.MsgContent;
                        tsms.Filter       = sms.Filter;
                        tsms.Level        = sms.Level;
                        tsms.Number       = sms.Number;
                        tsms.SendTime     = sms.SendTime;
                        tsms.SerialNumber = sms.SerialNumber;
                        tsms.StatusReport = sms.StatusReport;
                        tsms.Signature    = sms.Signature;
                        tsms.SPNumber     = sms.SPNumber;
                        tsms.WapURL       = sms.WapURL;

                        SlidingWindow _send = new SlidingWindow();
                        _send.Report    = new SendEventArgs(tsms, "", false, ((ushort)PlatformCode.SMGP + (ushort)SystemCode.SendReady), "", (ushort)submit.Pk_total, (ushort)submit.Pk_number);
                        _send.MSG       = submit;
                        _send.SendCount = 0;
                        _send.SendTime  = DateTime.Now;
                        _send.Status    = WindowStatus.Fill;
                        submits.Add(_send);
                    }
                }
            }
            else
            {
                for (int j = 0; j < sms.Number.Count; j++)
                {
                    Submit submit = new Submit(Sequence.Instance.CreateID());

                    submit.Pk_total  = 1;
                    submit.Pk_number = 1;

                    submit.WapURL          = "";
                    submit.MsgType         = 6;                                                                 //  uint    6=MT 消息(SP 发给终端,包括WEB 上发送的点对点短消息);
                    submit.NeedReport      = sms.StatusReport == StatusReportType.Disable ? (byte)0 : (byte)1;; //  uint    0=不要求返回状态报告; 1=要求返回状态报告;
                    submit.Priority        = 1;
                    submit.ServiceID       = _setting.ServiceID;;
                    submit.FeeType         = _setting.FeeType;
                    submit.FeeCode         = _setting.FeeCode;
                    submit.FixedFee        = "0";
                    submit.ValidTime       = _setting.ValidTime; //Util.Get_MMDDHHMMSS_String(DateTime.Now.AddHours(5)) + "032+";  // 存活有效期,格式遵循SMPP3.3协议。
                    submit.AtTime          = "";                 //Util.Get_MMDDHHMMSS_String(DateTime.Now) + "032+";     //      短消息定时发送时间,格式遵循SMPP3.3 以上版本协议。
                    submit.SrcTermID       = _setting.SrcID + sms.SPNumber;
                    submit.ChargeTermID    = _setting.ChargeTermID;
                    submit.DestTermID      = sms.Number.ToArray();
                    submit.DestTermIDCount = (uint)submit.DestTermID.Length;
                    submit.Reserve         = "";
                    submit.ProductID       = "";
                    submit.LinkID          = sms.LinkID;
                    submit.MsgFormat       = 15;
                    submit.WapURL          = sms.WapURL;
                    submit.MsgSrc          = _setting.MsgSrc;
                    //信息内容

                    submit.MsgContent = sms.Content + sms.Signature;
                    submit.SetHeader();


                    SMS tsms = new SMS();
                    tsms.Account      = sms.Account;
                    tsms.Audit        = sms.Audit;
                    tsms.Channel      = sms.Channel;
                    tsms.Content      = submit.MsgContent;
                    tsms.Filter       = sms.Filter;
                    tsms.Level        = sms.Level;
                    tsms.Number       = sms.Number;
                    tsms.SendTime     = sms.SendTime;
                    tsms.SerialNumber = sms.SerialNumber;
                    tsms.StatusReport = sms.StatusReport;
                    tsms.Signature    = sms.Signature;
                    tsms.SPNumber     = sms.SPNumber;
                    tsms.WapURL       = sms.WapURL;

                    SlidingWindow _send = new SlidingWindow();
                    _send.Report    = new SendEventArgs(tsms, "", false, ((ushort)PlatformCode.SMGP + (ushort)SystemCode.SendReady), "", (ushort)1, (ushort)1);
                    _send.MSG       = submit;
                    _send.SendCount = 0;
                    _send.SendTime  = DateTime.Now;
                    _send.Status    = WindowStatus.Fill;
                    submits.Add(_send);
                }
            }

            return(submits);
        }
Exemplo n.º 3
0
        void _sc_DataReceived(byte[] data)
        {
            MessageHeader head;

            _dtLastTransferTime = DateTime.Now;
            try
            {
                head = new MessageHeader(data);
            }
            catch (Exception ex)
            {
                OnNetworkError(ex);
                return;
            }

            switch ((SMGP3_COMMAND)head.Command)
            {
            case SMGP3_COMMAND.Login_Resp:
                Login_Resp login_Resp;
                try
                {
                    login_Resp = new Login_Resp(data);
                }
                catch (Exception ex)
                {
                    OnNetworkError(ex);
                    return;
                }
                DebugLog.Instance.Write <Login_Resp>("Received -> Login_Resp", login_Resp);
                switch (login_Resp.Status)
                {
                case 0:
                    _connect = true;
                    autoConnectEvent.Set();
                    OnSMSEvent(new SMSEventArgs(SMS_Event.SP_CONNECT, "登录成功"));
                    break;

                default:
                    OnSMSEvent(new SMSEventArgs(SMS_Event.SP_CONNECT_ERROR, StateDictionary.stateRespDictionary(login_Resp.Status)));
                    break;
                }
                break;

            case SMGP3_COMMAND.Submit_Resp:
                Submit_Resp submit_resp;

                try
                {
                    submit_resp = new Submit_Resp(data);
                }
                catch (Exception ex)
                {
                    OnNetworkError(ex);
                    return;
                }

                DebugLog.Instance.Write <Submit_Resp>("Received -> Submit_Resp", submit_resp);

                SlidingWindow send = SWGet(head.SequenceID);
                if (send.Status == WindowStatus.Idle)
                {
                    return;
                }
                SWClr(head.SequenceID);

                if (SendEvent != null)
                {
                    send.Report.Succeed = false;
                    switch (submit_resp.Result)
                    {
                    case 0:
                        send.Report.Succeed = true;
                        break;

                    default:
                        send.Report.Describe = StateDictionary.stateRespDictionary(submit_resp.Result);
                        break;
                    }
                    send.Report.Serial = submit_resp.MsgID;
                    SendEvent(this, send.Report);
                }
                break;

            case SMGP3_COMMAND.Deliver:
                Deliver deliver = new Deliver(data);
                DebugLog.Instance.Write <Deliver>("Received -> Deliver", deliver);
                Deliver_Resp deliverResp = new Deliver_Resp(deliver.MsgID, 0, deliver.Header.SequenceID);
                Send(deliverResp);
                DebugLog.Instance.Write <Deliver_Resp>("Send -> Deliver_Resp", deliverResp);

                if (deliver.IsReport == 1)
                {
                    Report report = new Report(deliver.Report);

                    bool   result        = false;
                    string resultMessage = "";
                    ushort resultCode    = ((ushort)PlatformCode.SMGP + (ushort)SystemCode.ReportBack);

                    DateTime time;
                    try
                    {
                        time = new DateTime(DateTime.Now.Year, System.Convert.ToInt32(report.Done_date.Substring(2, 2)), System.Convert.ToInt32(report.Done_date.Substring(4, 2)), System.Convert.ToInt32(report.Done_date.Substring(6, 2)), System.Convert.ToInt32(report.Done_date.Substring(8, 2)), 0);
                    }
                    catch
                    {
                        time = DateTime.Now;
                    }

                    switch (report.Stat.ToUpper())
                    {
                    case "DELIVRD":
                    case "RETRIEV":
                        result = true;
                        break;

                    case "EXPIRED":
                    case "DELETED":
                    case "UNDELIV":
                    case "ACCEPTD":
                    case "UNKNOWN":
                    case "REJECTD":
                    default:
                        resultMessage = report.Stat;
                        break;
                    }
                    ReportEventArgs args = new ReportEventArgs(report.Id, result, resultCode, resultMessage, time);
                    ReportEvent(this, args);
                }
                else
                {
                    //处理deliver
                    if (DeliverEvent != null)
                    {
                        DeliverEvent(this, new DeliverEventArgs(deliver.MsgID.ToString(), DateTime.Now, deliver.MsgContent, deliver.SrcTermID, deliver.DestTermID, "", deliver.LinkID));
                    }
                }
                break;

            case SMGP3_COMMAND.Active_Test:
                Active_Test_Resp active_test_resp1 = new Active_Test_Resp(data);
                active_test_resp1.Header.Command = SMGP3_COMMAND.Active_Test_Resp;
                Send(active_test_resp1);
                break;

            case SMGP3_COMMAND.Active_Test_Resp:
                //Active_Test_Resp active_test_resp2 = new Active_Test_Resp(data);
                //SWClr(active_test_resp2.SequenceID);
                break;

            case SMGP3_COMMAND.Exit:
                _connect = false;
                break;
            }
        }