Ejemplo n.º 1
0
        public List <DecodedMessage> GetUnreadMsg()
        {
            List <DecodedMessage> list = new List <DecodedMessage>();

            string[] strArray = null;
            string   str      = string.Empty;
            string   str2     = this.SendAT("AT+CMGL=0");
            bool     flag     = str2.Contains("OK");

            if (flag)
            {
                strArray = str2.Split(new char[]
                {
                    '\r'
                });
            }
            PDUEncoding pduEncoding = new PDUEncoding();

            string[] array = strArray;
            for (int i = 0; i < array.Length; i++)
            {
                string strPDU = array[i];
                bool   flag2  = strPDU != null && strPDU.Length > 18;
                if (flag2)
                {
                    list.Add(pduEncoding.PDUDecoder(strPDU));
                }
            }
            return(list);
        }
Ejemplo n.º 2
0
        public int SendMsg(string phone, string msg)
        {
            Thread.Sleep(5000);
            int         num         = 0;
            PDUEncoding pduEncoding = new PDUEncoding();

            pduEncoding.ServiceCenterAddress = this._MsgCenterNo;
            string str = string.Empty;

            foreach (CodedMessage codedMessage in pduEncoding.PDUEncoder(phone, msg))
            {
                this._GsmCom.DataReceived -= new EventHandler(this.sp_DataReceived);
                this._GsmCom.Write("AT+CMGS=" + codedMessage.Length.ToString() + "\r");
                Thread.Sleep(1000);
                this._GsmCom.ReadTo(">");
                this._GsmCom.DiscardInBuffer();
                this._GsmCom.DataReceived += new EventHandler(this.sp_DataReceived);
                string message;
                do
                {
                    message = this.SendAT(codedMessage.PduCode + "\u001a");
                }while (!message.Contains("OK"));
                bool flag = !message.Contains("OK");
                if (flag)
                {
                    throw new Exception(message);
                }
                num++;
            }
            return(num);
        }
Ejemplo n.º 3
0
        public DecodedMessage ReadMsgByIndex(int index)
        {
            string      str         = string.Empty;
            PDUEncoding pduEncoding = new PDUEncoding();
            string      str2;

            try
            {
                str2 = this.SendAT("AT+CMGR=" + index.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            bool flag = str2.Trim() == "ERROR";

            if (flag)
            {
                throw new Exception("没有此短信");
            }
            string strPDU = str2.Split(new char[]
            {
                '\r'
            })[2];
            bool autoDelMsg = this.AutoDelMsg;

            if (autoDelMsg)
            {
                try
                {
                    this.DeleteMsgByIndex(index);
                }
                catch
                {
                }
            }
            return(pduEncoding.PDUDecoder(strPDU));
        }