Beispiel #1
0
        /// <summary>
        /// 按序号读取短信
        /// </summary>
        /// <param name="index">序号</param>
        /// <returns>信息字符串 (中心号码,手机号码,发送时间,短信内容)</returns>
        public string ReadMsgByIndex(int index)
        {
            string temp = string.Empty;
            //string msgCenter, phone, msg, time;
            PDUEncoding pe = new PDUEncoding();
            try
            {
                temp = SendAT("AT+CMGR=" + index.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (temp.Trim() == "ERROR")
            {
                throw new Exception("没有此短信");
            }
            temp = temp.Split((char)(13))[2];       //取出PDU串(char)(13)为0x0a即\r 按\r分为多个字符串 第3个是PDU串

            //pe.PDUDecoder(temp, out msgCenter, out phone, out msg, out time);

            if (AutoDelMsg)
            {
                try
                {
                    DelMsgByIndex(index);
                }
                catch
                {

                }
            }

            return pe.PDUDecoder(temp);
            //return msgCenter + "," + phone + "," + time + "," + msg;
        }
Beispiel #2
0
        /// <summary>
        /// 获取未读信息列表
        /// </summary>
        /// <returns>未读信息列表(中心号码,手机号码,发送时间,短信内容)</returns>
        public string[] GetUnreadMsg()
        {
            string[] result = new string[255];
            string[] temp = null;
            string tmp = string.Empty;

            tmp = SendAT("AT+CMGL=0");
            if (tmp.Substring(tmp.Length - 4, 3).Trim() == "OK")
            {
                temp = tmp.Split('\r');
            }

            PDUEncoding pe = new PDUEncoding();
            int i = 0;
            foreach (string str in temp)
            {
                if (str != null && str.Length != 0 && str.Substring(0, 2).Trim() != "+C" && str.Substring(0, 2) != "OK")
                {
                    result[i] = pe.PDUDecoder(str);
                    i++;
                }
            }

            return result;
        }