public void Encoding_Using_BestFit()
        {
            var bytes = new GSMEncoding(true, true).GetBytes("ÁÉÍÓÚ ÀÈÌÒÙ áéíóú €");
            var valid = new byte[] {
                0x7f, 0x1f, 0x07, 0x08, 0x06, 0x20,
                0x7f, 0x1f, 0x07, 0x08, 0x06, 0x20,
                0x7f, 0x05, 0x07, 0x08, 0x06, 0x20,
                0x1b, 0x65
            };

            CollectionAssert.AreEqual(valid, bytes);
        }
Пример #2
0
        public static int Main(params string[] clparams)
        {
            string      test    = "This must be one complete sms message encoded by 7bit alphabet wihtout any parts or chunks it must be onecompete long test without interruptions or any other th";
            GSMEncoding gsmEnc  = new GSMEncoding();
            Encoding    utf8Enc = new System.Text.UTF8Encoding();

            byte[] gsmBytes  = utf8Enc.GetBytes(test);
            byte[] utf8Bytes = Encoding.Convert(gsmEnc, utf8Enc, gsmBytes);
            test = utf8Enc.GetString(utf8Bytes);

            DataContractSerializer scs  = new DataContractSerializer(typeof(DestinationAddress[]));
            DataContractSerializer scs2 = new DataContractSerializer(typeof(Hashtable));
            DataContractSerializer scs3 = new DataContractSerializer(typeof(ProviderConfiguration));
            TlvTable tlbTab             = new TlvTable();

            tlbTab.SetOptionalParamString(0x0501, "1234");
            tlbTab.SetOptionalParamString(0x0006, "4321");

            DestinationAddress[] dadress = new RoaminSMPP.Utility.DestinationAddress[]
            {
                new DestinationAddress(RoaminSMPP.Packet.Pdu.TonType.International, RoaminSMPP.Packet.Pdu.NpiType.National, "79225443636"),
                new DestinationAddress(RoaminSMPP.Packet.Pdu.TonType.International, RoaminSMPP.Packet.Pdu.NpiType.National, "79225443637")
            };

            ProviderConfiguration pc = new ProviderConfiguration()
            {
                BindingTypes     = new List <RoaminSMPP.Packet.Request.SmppBind.BindingType>(new[] { RoaminSMPP.Packet.Request.SmppBind.BindingType.BindAsTransceiver }),
                SourceNumberings = new List <TonNpiPair>
                                   (
                    new[] {
                    new TonNpiPair(Pdu.TonType.Alphanumeric, Pdu.NpiType.Unknown),    //Цифры и буквы
                    new TonNpiPair(Pdu.TonType.International, Pdu.NpiType.ISDN),      //Международный формат
                    new TonNpiPair(Pdu.TonType.NetworkSpecific, Pdu.NpiType.Unknown), //Короткий номер
                    new TonNpiPair(Pdu.TonType.Unknown, Pdu.NpiType.ISDN)             //Внутренние номера
                }
                                   ),
                DestinationNumberings = new List <TonNpiPair>
                                        (
                    new[] {
                    new TonNpiPair(Pdu.TonType.International, Pdu.NpiType.ISDN)         //Международный формат
                }
                                        ),
                EnqureLinkInterval    = new TimeSpan(0, 0, 30),
                PayloadType           = Pdu.PayloadTypeType.WDPMessage,
                SupportedSMPPVersions = new List <Pdu.SmppVersionType>(new[] { Pdu.SmppVersionType.Version3_4 }),
                SystemId  = "test.csharper.ru",
                Password  = "******",
                Host      = "213.242.207.57",
                Port      = 2775,
                TimeShift = -3
            };

            Stream stream = /*File.OpenWrite(@"D:\Temp.txt");*/
                            Console.OpenStandardOutput();
            XmlWriter xw = XmlWriter.Create(stream, new XmlWriterSettings()
            {
                Indent           = true,
                ConformanceLevel = ConformanceLevel.Auto
            });

            scs.WriteObject(xw, dadress);
            Console.WriteLine();
            scs2.WriteObject(xw, new Hashtable(tlbTab.tlvTable));
            Console.WriteLine();
            scs3.WriteObject(xw, pc);
            xw.Close();
            Console.WriteLine();
            Console.ReadKey();
            return(0);
        }
 public void SetUp()
 {
     _encoding = new GSMEncoding();
 }
        public void Encoding_Invalid_Char_Using_BestFit_Replaces_Character()
        {
            var bytes = new GSMEncoding(true, false).GetBytes(new char[] { 'º' });

            CollectionAssert.AreEqual(new byte[] { 0x3f }, bytes);
        }
Пример #5
0
 public void Encoding_Invalid_Char_Using_BestFit_Replaces_Character()
 {
     var bytes = new GSMEncoding(true, false).GetBytes(new char[] { 'º' });
     CollectionAssert.AreEqual(new byte[] { 0x3f }, bytes);
 }
Пример #6
0
 public void SetUp()
 {
     _encoding = new GSMEncoding();
 }
Пример #7
0
 public void Encoding_Using_BestFit()
 {
     var bytes = new GSMEncoding(true, true).GetBytes("ÁÉÍÓÚ ÀÈÌÒÙ áéíóú €");
     var valid = new byte[] {
         0x7f, 0x1f, 0x07, 0x08, 0x06, 0x20,
         0x7f, 0x1f, 0x07, 0x08, 0x06, 0x20,
         0x7f, 0x05, 0x07, 0x08, 0x06, 0x20,
         0x1b, 0x65
     };
     CollectionAssert.AreEqual(valid, bytes);
 }
Пример #8
0
        public List <SMSSeriesId> SendSms(Guid userId, string senderName, List <string> addresses, string message,
                                          bool transliterate           = false,
                                          bool alertOnDelivery         = false,
                                          bool registredDelivery       = true,
                                          bool replaceIfPresent        = true,
                                          string callbackNumber        = null,
                                          string callbackNumberDisplay = null,
                                          Pdu.PriorityType priority    = Pdu.PriorityType.Level2,
                                          Pdu.PrivacyType privacy      = Pdu.PrivacyType.Nonrestricted,
                                          string clientId             = null,
                                          string distributionId       = null,
                                          string smsId                = null,
                                          DateTime?deliveryTime       = null,
                                          TimeSpan?validalityPeriod   = null,
                                          ushort smsSignal            = 0,
                                          ushort sourcePort           = 0,
                                          ushort userMessageReference = 0,
                                          Dictionary <string, string> customParameters = null)
        {
            if (validalityPeriod == null)
            {
                validalityPeriod = TimeSpan.FromMinutes(10);
            }

            List <SMSSeriesId> result = new List <SMSSeriesId>();
            //Здесь будет получение провайдера для данного пользователя, исходя из имени отправителя, требуемого качества канала, жизни поставщика, статуса пользователя, клиента
            bool useRussian = true;
            //---------------------------------------------------------
            SenderNames sName = Context.GetSenderNames(userId).Where(sn => sn.Name == senderName).OrderByDescending(sn => sn.Providers.ChannelBrandwidth).FirstOrDefault();

            if (sName != null)
            {
                //---------------------------------------------------------
                //--Конфигурация провайдера, должна покрыть некоторые опции----
                ProviderConfiguration configuration = _providerConfigurationSerializer.Deserialize <ProviderConfiguration>(sName.Providers.Configuration);
                Pdu.SmppVersionType   smppVersion   = configuration.SupportedSMPPVersions.First();
                Pdu.PayloadTypeType   payloadType   = configuration.PayloadType;

                TonNpiPair outNumbering = sName.Name.IsDigital()?
                                          configuration.SourceNumberings.Where(sn => sn.Ton == Pdu.TonType.International).First():
                                          outNumbering = configuration.SourceNumberings.Where(sn => sn.Ton == Pdu.TonType.Alphanumeric).First();
                TonNpiPair destinationNumbering = configuration.DestinationNumberings
                                                  .Where(dn => dn.Ton == Pdu.TonType.International).First();
                //-------------------------------------------------------------
                string[] messages;
                if (!message.ContainsNonASCII() || transliterate)
                {
                    if (transliterate)
                    {
                        message = message.Unidecode();
                    }
                    if (configuration.Support7Bit)
                    {
                        if (message.Length > SMS_7BIT_LENGTH)
                        {
                            messages = message.SplitByLength(SMS_7BIT_CONCAT_LENGTH);
                        }
                        else
                        {
                            messages = message.SplitByLength(SMS_7BIT_LENGTH);
                        }
                    }
                    else
                    {
                        if (message.Length > SMS_8BIT_LENGTH)
                        {
                            messages = message.SplitByLength(SMS_8BIT_CONCAT_LENGTH);
                        }
                        else
                        {
                            messages = message.SplitByLength(SMS_8BIT_LENGTH);
                        }
                    }
                    useRussian = false;
                }
                else
                {
                    if (message.Length > SMS_UNICODE_LENGTH)
                    {
                        messages = message.SplitByLength(SMS_UNICODE_CONCAT_LENGTH);
                    }
                    else
                    {
                        messages = message.SplitByLength(SMS_UNICODE_LENGTH);
                    }
                }
                bool concatenated = messages.Length > 1;
                if (concatenated)
                {
                    concatRefNum = concatRefNum.CycleInc();
                }
                for (byte i = 0; i < messages.Length; ++i)
                {
                    MessageLcd2 req;

                    if (addresses.Count > 1)
                    {
                        req = new SmppSubmitMulti();
                    }
                    else
                    {
                        req = new SmppSubmitSm();
                    }

                    byte[] bMessage;

                    if (configuration.Support7Bit && !useRussian)
                    {
                        bMessage = new GSMEncoding().GetBytes(messages[i]);
                        if (configuration.Need7BitPacking)
                        {
                            bMessage = GSMEncoding.Encode7Bit(bMessage, concatenated ? 5 : 0);
                        }
                    }
                    else if (!useRussian)
                    {
                        bMessage = Encoding.ASCII.GetBytes(messages[i]);
                    }
                    else
                    {
                        bMessage = Encoding.UTF8.GetBytes(messages[i].Endian2UTF());
                    }
                    if (useRussian)
                    {
                        req.DataCoding = RoaminSMPP.Packet.Pdu.DataCodingType.Unicode;
                    }
                    else
                    {
                        req.DataCoding = Pdu.DataCodingType.SMSCDefault;
                    }
                    req.AlertOnMsgDelivery = Convert.ToByte(alertOnDelivery);
                    if (useRussian)
                    {
                        req.LanguageIndicator = Pdu.LanguageType.UCS2_16Bit;
                    }
                    else if (configuration.Support7Bit)
                    {
                        req.LanguageIndicator = Pdu.LanguageType.GSM7BitDefaultAlphabet;
                    }
                    else
                    {
                        req.LanguageIndicator = Pdu.LanguageType.Unspecified;
                    }
                    req.PayloadType        = payloadType;
                    req.PriorityFlag       = priority;
                    req.PrivacyIndicator   = privacy;
                    req.ProtocolId         = smppVersion;
                    req.RegisteredDelivery = registredDelivery?
                                             Pdu.RegisteredDeliveryType.OnSuccessOrFailure:
                                             Pdu.RegisteredDeliveryType.None;
                    req.ReplaceIfPresentFlag = replaceIfPresent;
                    req.ScheduleDeliveryTime = deliveryTime == null ? null : deliveryTime.Value.GetDateString(configuration.TimeShift);
                    req.SmsSignal            = smsSignal;
                    req.SourceAddress        = sName.Name;
                    req.SourceAddressTon     = outNumbering.Ton;
                    req.SourceAddressNpi     = outNumbering.Npi;
                    req.SourceAddressSubunit = RoaminSMPP.Packet.Pdu.AddressSubunitType.MobileEquipment;
                    req.SourcePort           = sourcePort;
                    req.UserMessageReference = userMessageReference;
                    req.ValidityPeriod       = validalityPeriod == null ? null : validalityPeriod.Value.GetDateString();
                    if (!string.IsNullOrEmpty(callbackNumber))
                    {
                        req.CallbackNum = callbackNumber;
                        if (string.IsNullOrEmpty(callbackNumberDisplay))
                        {
                            req.CallbackNumAtag = callbackNumberDisplay;
                        }
                        req.CallbackNumPresInd = 1;
                    }
                    if (concatenated)
                    {
                        //Добавляем EI UDH для сочленяемых сообщений
                        byte[] concatBytes = new byte[6];
                        concatBytes[0] = 5;
                        concatBytes[1] = 0;
                        concatBytes[2] = 3;
                        concatBytes[3] = concatRefNum;
                        concatBytes[4] = (byte)messages.Length;
                        concatBytes[5] = (byte)(i + 1);
                        byte[] resulting = new byte[bMessage.Length + concatBytes.Length];
                        concatBytes.CopyTo(resulting, 0);
                        bMessage.CopyTo(resulting, concatBytes.Length);
                        bMessage = resulting;
                    }
                    req.ShortMessage = bMessage;
                    if (req is SmppSubmitSm)
                    {
                        SmppSubmitSm simple = req as SmppSubmitSm;
                        simple.DestinationAddress    = addresses[0];
                        simple.DestinationAddressTon = destinationNumbering.Ton;
                        simple.DestinationAddressNpi = destinationNumbering.Npi;
                    }
                    if (req is SmppSubmitMulti)
                    {
                        SmppSubmitMulti complex = req as SmppSubmitMulti;
                        complex.DestinationAddresses = addresses.Select
                                                       (
                            address => new DestinationAddress(destinationNumbering.Ton, destinationNumbering.Npi, address)
                                                       ).ToArray();
                    }
                    if (concatenated && !string.IsNullOrEmpty(callbackNumber))
                    {
                        req.EsmClass = 195;
                    }
                    else if (concatenated)
                    {
                        req.EsmClass = 67;
                    }
                    else if (!string.IsNullOrEmpty(callbackNumber))
                    {
                        req.EsmClass = 131;
                    }
                    else
                    {
                        req.EsmClass = 3;
                    }
                    SMSSeriesId id = EnqueueSMS(userId, sName.Id, sName.ProviderId, req, clientId, distributionId, smsId, customParameters);
                    if (!id.Equals(SMSSeriesId.Empty))
                    {
                        result.Add(id);
                    }
                }
            }
            return(result);
        }