コード例 #1
0
        public SGIP_BIND_RESP(byte[] bytes)
        {
            //header 20
            int    i = 0;
            string s = null;

            byte[] buffer = new byte[SGIP_MESSAGE.Length];
            Buffer.BlockCopy(bytes, 0, buffer, 0, buffer.Length);
            this._Header = new SGIP_MESSAGE(buffer);


            //Result 1
            i           += SGIP_MESSAGE.Length;
            this._Result = (uint)bytes[i++];

            //Result 8
            buffer = new byte[8];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            this._Reserve = s;
        }
コード例 #2
0
        private string _Reserve;    // 8 Octet String  保留,扩展用

        public SGIP_BIND_RESP(uint Result, uint SrcNodeSequence, uint DateSequence, uint Sequence_Id)
        {
            this._Header = new SGIP_MESSAGE(SGIP_MESSAGE.Length + BodyLength, SGIP_COMMAND.SGIP_BIND_RESP, SrcNodeSequence, DateSequence, Sequence_Id);

            this._Result  = Result;
            this._Reserve = "null";
        }
コード例 #3
0
 public SGIP_UNBIND_RESP
 (
     uint SrcNodeSequence
     , uint DateSequence
     , uint Sequence_Id
 )
 {
     this._Header = new SGIP_MESSAGE(SGIP_MESSAGE.Length, SGIP_COMMAND.SGIP_UNBIND_RESP, SrcNodeSequence, DateSequence, Sequence_Id);
 }
コード例 #4
0
ファイル: SGIP_BIND.cs プロジェクト: aspdotnetmvc/mvc
        public SGIP_BIND(uint LoginType, string LoginName, string LoginPassword, uint Sequence_Id)
        {
            this._Header = new SGIP_MESSAGE(SGIP_MESSAGE.Length + BodyLength, SGIP_COMMAND.SGIP_BIND, Sequence_Id);

            this._LoginType     = LoginType;
            this._LoginName     = LoginName;
            this._LoginPassword = LoginPassword;
            this._Reserve       = "";
        }
コード例 #5
0
ファイル: SGIP_SUBMIT.cs プロジェクト: aspdotnetmvc/mvc
        internal void SetHeader()
        {
            if (string.IsNullOrEmpty(WapURL))
            {
                //byte[] buf;
                switch (this._MessageCoding)
                {
                case 8:
                    _Msg_Content_Bytes = Encoding.BigEndianUnicode.GetBytes(this._MessageContent);
                    break;

                case 15:     //gb2312
                    _Msg_Content_Bytes = Encoding.GetEncoding("gb2312").GetBytes(this._MessageContent);
                    break;

                case 0:     //ascii
                case 3:     //短信写卡操作
                case 4:     //二进制信息
                default:
                    _Msg_Content_Bytes = Encoding.ASCII.GetBytes(this._MessageContent);
                    break;
                }

                if (this.Pk_total > 1) //长短信
                {
                    this.TP_udhi = 1;
                    byte[] tp_udhiHead = new byte[6];
                    tp_udhiHead[0] = 0x05;
                    tp_udhiHead[1] = 0x00;
                    tp_udhiHead[2] = 0x03;
                    tp_udhiHead[3] = 0x0A;
                    tp_udhiHead[4] = (byte)this.Pk_total;
                    tp_udhiHead[5] = (byte)this.Pk_number;
                    byte[] Msg_Content_Bytes_Temp = new byte[_Msg_Content_Bytes.Length + 6];
                    int    index = 0;
                    tp_udhiHead.CopyTo(Msg_Content_Bytes_Temp, index);
                    index += tp_udhiHead.Length;
                    _Msg_Content_Bytes.CopyTo(Msg_Content_Bytes_Temp, index);
                    _Msg_Content_Bytes = Msg_Content_Bytes_Temp;
                }
            }
            else
            {
                _Msg_Content_Bytes  = WapPush.GetInstance().toBytes(this._MessageContent, WapURL);
                this._MessageCoding = 0x04;
                this.TP_pid         = 1;
                this.TP_udhi        = 1;
            }

            this._MessageLength = (uint)_Msg_Content_Bytes.Length;
            this._BodyLength    = (int)(FixedBodyLength + this._MessageLength);
            this._Header        = new SGIP_MESSAGE((uint)(SGIP_MESSAGE.Length + this._BodyLength), SGIP_COMMAND.SGIP_SUBMIT, this._Sequence_Id);
        }
コード例 #6
0
 public SGIP_REPORT_RESP
 (
     uint Result
     , string Reserve
     , uint SrcNodeSequence
     , uint DateSequence
     , uint Sequence_Id
 )
 {
     this._Header  = new SGIP_MESSAGE(SGIP_MESSAGE.Length + Bodylength, SGIP_COMMAND.SGIP_REPORT_RESP, SrcNodeSequence, DateSequence, Sequence_Id);
     this._Result  = Result;
     this._Reserve = Reserve;
 }
コード例 #7
0
ファイル: SGIP_BIND.cs プロジェクト: aspdotnetmvc/mvc
        //public SGIP_Bind
        // (
        //  uint LoginType
        //  , string LoginName
        //  , string LoginPassword
        //  , uint SrcNodeSequence
        //  , uint DateSequence
        //  , uint Sequence_Id
        // )
        //{
        //    this._Header = new SIGP_MESSAGE(SIGP_MESSAGE.Length + BodyLength, SIGP_COMMAND.SGIP_BIND,SrcNodeSequence,DateSequence, Sequence_Id);

        //    this._LoginType = LoginType;
        //    this._LoginName = LoginName;
        //    this._LoginPassword = LoginPassword;
        //    this._Reserve = "";
        //}

        public SGIP_BIND(byte[] bytes)
        {
            int    i = 0;
            string s = null;

            byte[] buffer = new byte[SGIP_MESSAGE.Length];
            Buffer.BlockCopy(bytes, 0, buffer, 0, SGIP_MESSAGE.Length);
            this._Header = new SGIP_MESSAGE(buffer);

            //LoginType 1
            i += SGIP_MESSAGE.Length;
            this._LoginType = (uint)bytes[i++];

            //LoginName 16
            buffer = new byte[16];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            this._LoginName = s;

            //LoginPassword 16
            i     += 16;
            buffer = new byte[16];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            this._LoginPassword = s;

            //LoginPassword 16
            i     += 16;
            buffer = new byte[8];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            this._Reserve = s;
        }
コード例 #8
0
        private string _Reserve;       //8 Octet String保留,扩展用


        public SGIP_REPORT(byte[] bytes)
        {
            int    i = 0;
            string s = null;

            byte[] buffer = new byte[SGIP_MESSAGE.Length];
            Buffer.BlockCopy(bytes, 0, buffer, 0, SGIP_MESSAGE.Length);
            this._Header = new SGIP_MESSAGE(buffer);

            //SrcNodeSequence 4
            i     += SGIP_MESSAGE.Length;
            buffer = new byte[4];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            Array.Reverse(buffer);
            this._SrcNodeSequence = BitConverter.ToUInt32(buffer, 0);

            //DateSequence 4
            i     += 4;
            buffer = new byte[4];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            Array.Reverse(buffer);
            this._DateSequence = BitConverter.ToUInt32(buffer, 0);


            //Sequence_Id 4
            i     += 4;
            buffer = new byte[4];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            Array.Reverse(buffer);
            this._Sequence_Id = BitConverter.ToUInt32(buffer, 0);

            //ReportType 1
            i += 4;
            this._ReportType = (uint)bytes[i++];

            //UserNumber 21
            buffer = new byte[21];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            if (s != null && s.Length > 11 && s.Substring(0, 2) == "86")
            {
                s = s.Substring(2, s.Length - 2);
            }
            this._UserNumber = s;


            //State 1
            i              += 21;
            this._State     = (uint)bytes[i++];
            this._ErrorCode = (uint)bytes[i++];


            //Linkid 8
            buffer = new byte[8];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            this._Reserve = s;
        }
コード例 #9
0
ファイル: SGIP12.cs プロジェクト: aspdotnetmvc/mvc
        void _server_DataReceived(SocketAsyncEventArgs send, byte[] data)
        {
            try
            {
                SGIP_MESSAGE header = new SGIP_MESSAGE(data);

                switch (header.Command_Id)
                {
                case SGIP_COMMAND.SGIP_BIND:
                    SGIP_BIND bind = new SGIP_BIND(data);
                    DebugLog.Instance.Write <SGIP_BIND>("Server Received -> SGIP_BIND", bind);
                    uint BindResult = 0;
                    if (bind.LoginType == (uint)LoginTypes.SmgToSp || bind.LoginType == (uint)LoginTypes.SpToSmg)
                    {
                        if ((bind.LoginName == _setting.LocalLoginName) && (bind.LoginPassword == _setting.LocalLoginPassword))
                        {
                            BindResult = 0;
                        }
                        else
                        {
                            BindResult = 1;
                        }
                    }
                    else
                    {
                        BindResult = 4;
                    }
                    SGIP_BIND_RESP sgip_bind_resp = new SGIP_BIND_RESP(BindResult, header.SrcNodeSequence, header.DateSequence, header.Sequence_Id);
                    ServerSend(send, sgip_bind_resp);
                    DebugLog.Instance.Write <SGIP_BIND_RESP>("Server Send -> SGIP_BIND_RESP", sgip_bind_resp);
                    break;

                case SGIP_COMMAND.SGIP_REPORT:
                    // Thread.Sleep(100);//调试代码,上线去掉
                    SGIP_REPORT report = new SGIP_REPORT(data);
                    DebugLog.Instance.Write <SGIP_REPORT>("Server Received -> SGIP_REPORT", report);
                    SGIP_REPORT_RESP reportResp = new SGIP_REPORT_RESP(0, "", header.SrcNodeSequence, header.DateSequence, header.Sequence_Id);
                    ServerSend(send, reportResp);
                    DebugLog.Instance.Write <SGIP_REPORT_RESP>("Server Send -> SGIP_REPORT_RESP", reportResp);

                    if (report.ReportType == 0)
                    {
                        bool     result = false;
                        ushort   resultCode;
                        string   resultMsg = "";
                        string   sTime     = report.DateSequence.ToString().PadLeft(10, '0');
                        int      mm        = System.Convert.ToInt32(sTime.Substring(0, 2));
                        int      dd        = System.Convert.ToInt32(sTime.Substring(2, 2));
                        int      hh        = System.Convert.ToInt32(sTime.Substring(4, 2));
                        int      m         = System.Convert.ToInt32(sTime.Substring(6, 2));
                        int      s         = System.Convert.ToInt32(sTime.Substring(8, 2));
                        DateTime time      = new DateTime(DateTime.Now.Year, mm, dd, hh, m, s);

                        switch (report.State)
                        {
                        case 0:         //成功
                        case 1:         //状态报告返回,网关等待发送.
                            result     = true;
                            resultCode = ((ushort)PlatformCode.SGIP + (ushort)SystemCode.ReportBack);
                            break;

                        default:
                            resultCode = ((ushort)PlatformCode.SGIP + (ushort)SystemCode.ReportBack);
                            resultMsg  = report.ErrorCode.ToString();
                            break;
                        }
                        string          serial = report.SrcNodeSequence.ToString() + report.DateSequence.ToString() + report.Sequence_Id.ToString();
                        ReportEventArgs args   = new ReportEventArgs(serial, result, resultCode, resultMsg, time);
                        ReportEvent(this, args);
                    }
                    break;

                case SGIP_COMMAND.SGIP_UNBIND:
                    SGIP_UNBIND_RESP unbindResp = new SGIP_UNBIND_RESP(header.SrcNodeSequence, header.DateSequence, header.Sequence_Id);
                    DebugLog.Instance.Write("Server Received -> SGIP_UNBIND");
                    ServerSend(send, unbindResp);
                    DebugLog.Instance.Write <SGIP_UNBIND_RESP>("Server Send -> SGIP_UNBIND_RESP", unbindResp);
                    break;

                case SGIP_COMMAND.SGIP_DELIVER:
                    SGIP_DELIVER deliver = new SGIP_DELIVER(data);
                    DebugLog.Instance.Write <SGIP_DELIVER>("Server Received -> SGIP_DELIVER", deliver);
                    SGIP_DELIVER_RESP deliverResp = new SGIP_DELIVER_RESP(0, "", header.SrcNodeSequence, header.DateSequence, header.Sequence_Id);
                    ServerSend(send, deliverResp);
                    DebugLog.Instance.Write <SGIP_DELIVER_RESP>("Server Send -> SGIP_DELIVER_RESP", deliverResp);
                    if (DeliverEvent != null)
                    {
                        string serial = header.SrcNodeSequence.ToString() + header.DateSequence.ToString() + header.Sequence_Id.ToString();
                        DeliverEvent(this, new DeliverEventArgs(serial, DateTime.Now, deliver.MessageContent, deliver.UserNumber, deliver.SPNumber, ""));
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                DebugLog.Instance.Write <Exception>("Server Received -> Exception", ex);
            }
        }
コード例 #10
0
ファイル: SGIP12.cs プロジェクト: aspdotnetmvc/mvc
        void _client_DataReceived(byte[] data)
        {
            SGIP_MESSAGE header;

            try
            {
                header = new SGIP_MESSAGE(data);
            }
            catch (Exception ex)
            {
                OnClientNetworkError(ex);
                return;
            }
            switch (header.Command_Id)
            {
            case SGIP_COMMAND.SGIP_BIND_RESP:
                SGIP_BIND_RESP sgip_bind_resp;
                try
                {
                    sgip_bind_resp = new SGIP_BIND_RESP(data);
                }
                catch (Exception ex)
                {
                    OnClientNetworkError(ex);
                    return;
                }
                DebugLog.Instance.Write <SGIP_BIND_RESP>("Client Received -> SGIP_BIND_RESP", sgip_bind_resp);

                switch (sgip_bind_resp.Result)
                {
                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(sgip_bind_resp.Result)));
                    break;
                }
                break;

            case SGIP_COMMAND.SGIP_SUBMIT_RESP:
                SGIP_SUBMIT_RESP submit_resp;
                try
                {
                    submit_resp = new SGIP_SUBMIT_RESP(data);
                }
                catch (Exception ex)
                {
                    OnClientNetworkError(ex);
                    return;
                }
                DebugLog.Instance.Write <SGIP_SUBMIT_RESP>("Client Received -> SGIP_SUBMIT_RESP", submit_resp);
                string        serial = header.SrcNodeSequence.ToString() + header.DateSequence.ToString() + header.Sequence_Id.ToString();
                SlidingWindow send   = SWGet(serial);
                if (send.Status == WindowStatus.Idle)
                {
                    return;
                }
                SWClr(serial);

                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 = serial;
                    SendEvent(this, send.Report);
                }
                break;

            case SGIP_COMMAND.SGIP_UNBIND:
                SGIP_UNBIND_RESP unbindResp;
                try
                {
                    unbindResp = new SGIP_UNBIND_RESP(header.SrcNodeSequence, header.DateSequence, header.Sequence_Id);
                }
                catch (Exception ex)
                {
                    OnClientNetworkError(ex);
                    return;
                }
                DebugLog.Instance.Write("Client Received -> SGIP_UNBIND");

                ClientSend(unbindResp);
                DebugLog.Instance.Write <SGIP_UNBIND_RESP>("Client Send -> SGIP_UNBIND_RESP", unbindResp);
                Thread.Sleep(1000);
                _connect = false;
                break;
            }
        }
コード例 #11
0
        public SGIP_DELIVER(byte[] bytes)
        {
            int    i = 0;
            string s = null;

            byte[] buffer = new byte[SGIP_MESSAGE.Length];
            Buffer.BlockCopy(bytes, 0, buffer, 0, SGIP_MESSAGE.Length);
            this._Header = new SGIP_MESSAGE(buffer);

            //UserNumber 21
            i     += SGIP_MESSAGE.Length;
            buffer = new byte[21];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            if (s != null && s.Length > 11 && s.Substring(0, 2) == "86")
            {
                s = s.Substring(2, s.Length - 2);
            }
            this._UserNumber = s;

            //SPNumber 21
            i     += 21;
            buffer = new byte[21];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            this._SPNumber = s;

            //
            i                  += 21;
            this._TP_pid        = (uint)bytes[i++];
            this._TP_udhi       = (uint)bytes[i++];
            this._MessageCoding = (uint)bytes[i++];

            //MessageLength 4
            buffer = new byte[4];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            Array.Reverse(buffer);
            this._MessageLength = BitConverter.ToUInt32(buffer, 0);

            //MessageContent
            i     += 4;
            buffer = new byte[this._MessageLength];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            switch (this._MessageCoding)
            {
            case 8:
                this._MessageContent = Encoding.BigEndianUnicode.GetString(buffer).Trim();
                break;

            case 15:     //gb2312
                this._MessageContent = Encoding.GetEncoding("gb2312").GetString(buffer).Trim();
                break;

            case 0:     //ascii
            case 3:     //短信写卡操作
            case 4:     //二进制信息
            default:
                this._MessageContent = Encoding.ASCII.GetString(buffer).ToString();
                break;
            }

            //Linkid 8
            i     += (int)this._MessageLength;
            buffer = new byte[8];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            this._LinkID = s;
        }