Exemple #1
0
        static public string Code(string receiver, string message, MessageCodeType type)
        {
            if (string.IsNullOrEmpty(receiver))
            {
                throw new ArgumentNullException("Receiver is invalid.");
            }
            receiver = receiver.Trim();
            if (receiver.Length == 0)
            {
                throw new ArgumentNullException("Receiver is invalid.");
            }
            //Length of SMSC information. Here the length is 0, which means that the SMSC stored in the phone should be used. 
            //Note: This octet is optional. On some phones this octet should be omitted! 
            //(Using the SMSC stored in phone is thus implicit) 
            string data = CodeInteger(0x00);
            //First octet of the SMS-SUBMIT message. 
            data += CodeInteger(0x011);
            //TP-Message-Reference. The "00" value here lets the phone set the message reference number itself.  
            data += CodeInteger(0x00);
            //Is phone number give as internal format.
            bool bInternational = (receiver[0] == '+');
            if (bInternational)
            {
                receiver = receiver.Substring(1);                
            }
            //Address-Length. Length of phone number.            
            //If the length of the phone number is odd (11), a trailing F has been added.
            if ((receiver.Length % 2) != 0) 
            {
                receiver += "F";
            }
            data += CodeInteger(receiver.Length);
            //Type-of-Address. (91 indicates international format of the phone number).
            data += CodeInteger(bInternational ? 0x91 : 0x81);
            //The phone number in semi octets.
            data += CodeString(receiver);
            //TP-PID. Protocol identifier 
		    data += CodeInteger(0x00);

		    //TP-DCS. Data coding scheme. This message is coded according to the 7bit default alphabet. 
		    //Having "04" instead of "00" here, would indicate that the TP-User-Data field of this 
		    //message should be interpreted as 8bit rather than 7bit (used in e.g. smart messaging, OTA provisioning etc). 
            string msg;
            if (type == MessageCodeType.Bits7)
		    {
			    data += CodeInteger(0x00);
                msg = Code7Bit(message);
		    }
		    else if (type == MessageCodeType.Bits8)
		    {
			    data += CodeInteger(0x04);
                msg = Code8Bit(message);
		    }
		    else if(type == MessageCodeType.Unicode)
		    {
			    data += CodeInteger(0x08);
                msg = CodeUnicode(message);
		    }
		    else
		    {
                throw new ArgumentOutOfRangeException("Unknown message code type.");
		    }
		    //TP-Validity-Period. "AA" means 4 days. Note: This octet is optional, see bits 4 and 3 of the first octet 
            data += CodeInteger(0xAA);		
		    //TP-User-Data-Length. Length of message. The TP-DCS field indicated 7-bit data, so the length here is the number of septets (10). 
            data += CodeInteger(msg.Length / 2);		
		    //If the TP-DCS field were set to 8-bit data or Unicode, the length would be the number of octets. 
            data += msg;
            return data;
        }
Exemple #2
0
        static public string Code(string receiver, string message, MessageCodeType type)
        {
            if (string.IsNullOrEmpty(receiver))
            {
                throw new ArgumentNullException("Receiver is invalid.");
            }
            receiver = receiver.Trim();
            if (receiver.Length == 0)
            {
                throw new ArgumentNullException("Receiver is invalid.");
            }
            //Length of SMSC information. Here the length is 0, which means that the SMSC stored in the phone should be used.
            //Note: This octet is optional. On some phones this octet should be omitted!
            //(Using the SMSC stored in phone is thus implicit)
            string data = CodeInteger(0x00);

            //First octet of the SMS-SUBMIT message.
            data += CodeInteger(0x011);
            //TP-Message-Reference. The "00" value here lets the phone set the message reference number itself.
            data += CodeInteger(0x00);
            //Is phone number give as internal format.
            bool bInternational = (receiver[0] == '+');

            if (bInternational)
            {
                receiver = receiver.Substring(1);
            }
            //Address-Length. Length of phone number.
            //If the length of the phone number is odd (11), a trailing F has been added.
            if ((receiver.Length % 2) != 0)
            {
                receiver += "F";
            }
            data += CodeInteger(receiver.Length);
            //Type-of-Address. (91 indicates international format of the phone number).
            data += CodeInteger(bInternational ? 0x91 : 0x81);
            //The phone number in semi octets.
            data += CodeString(receiver);
            //TP-PID. Protocol identifier
            data += CodeInteger(0x00);

            //TP-DCS. Data coding scheme. This message is coded according to the 7bit default alphabet.
            //Having "04" instead of "00" here, would indicate that the TP-User-Data field of this
            //message should be interpreted as 8bit rather than 7bit (used in e.g. smart messaging, OTA provisioning etc).
            string msg;

            if (type == MessageCodeType.Bits7)
            {
                data += CodeInteger(0x00);
                msg   = Code7Bit(message);
            }
            else if (type == MessageCodeType.Bits8)
            {
                data += CodeInteger(0x04);
                msg   = Code8Bit(message);
            }
            else if (type == MessageCodeType.Unicode)
            {
                data += CodeInteger(0x08);
                msg   = CodeUnicode(message);
            }
            else
            {
                throw new ArgumentOutOfRangeException("Unknown message code type.");
            }
            //TP-Validity-Period. "AA" means 4 days. Note: This octet is optional, see bits 4 and 3 of the first octet
            data += CodeInteger(0xAA);
            //TP-User-Data-Length. Length of message. The TP-DCS field indicated 7-bit data, so the length here is the number of septets (10).
            data += CodeInteger(msg.Length / 2);
            //If the TP-DCS field were set to 8-bit data or Unicode, the length would be the number of octets.
            data += msg;
            return(data);
        }