protected override IEnumerable <SendSmPDU> GetPDUs(DataCoding defaultEncoding) { SubmitSm sm = CreateSubmitSm(); sm.SourceAddress.Address = vSourceAddress; sm.DestinationAddress.Address = vDestinatinoAddress; // Urgh, typo :( sm.DataCoding = defaultEncoding; if (!string.IsNullOrEmpty(UserMessageReference)) { var msgIdBytes = SMPPEncodingUtil.GetBytesFromCString(UserMessageReference); sm.Tlv.Add(new Lib.Protocol.Tlv.Tlv(Lib.Protocol.Tlv.Tag.user_message_reference, (ushort)msgIdBytes.Length, msgIdBytes)); } if (vRegisterDeliveryNotification) { sm.RegisteredDelivery = RegisteredDelivery.DeliveryReceipt; } vMaxMessageLength = GetMaxMessageLength(defaultEncoding, false); byte[] bytes = SMPPEncodingUtil.GetBytesFromString(vText, defaultEncoding); string uni = Encoding.Unicode.GetString(bytes); string ascii = Encoding.ASCII.GetString(bytes); string utf8 = Encoding.UTF8.GetString(bytes); // Unicode encoding return 2 items for 1 char // We check vText Length first if (vText.Length > vMaxMessageLength && bytes.Length > vMaxMessageLength) // Split into multiple! { var SegID = new Random().Next(1000, 9999); // create random SegmentID vMaxMessageLength = GetMaxMessageLength(defaultEncoding, true); var messages = Split(vText, vMaxMessageLength); var totalSegments = messages.Count; // get the number of (how many) parts var udh = new Udh(SegID, totalSegments, 0); // ID, Total, part for (int i = 0; i < totalSegments; i++) { udh.MessageSequence = i + 1; // seq+1 , - parts of the message sm.SetMessageText(messages[i], defaultEncoding, udh); // send parts of the message + all other UDH settings yield return(sm); } } else { sm.SetMessageBytes(bytes); yield return(sm); } }
private void button1_Click(object sender, EventArgs e) { SMPPEncodingUtil.UCS2Encoding = Encoding.BigEndianUnicode; mmSessionBindInfo = new SessionBindInfo(); mmSessionBindInfo.SystemID = "********"; mmSessionBindInfo.Password = "******"; mmSessionBindInfo.ServerName = "*******"; mmSessionBindInfo.Port = 1234; mmSessionBindInfo.InterfaceVersion = InterfaceVersion.v34; mmSessionBindInfo.SystemType = "SMPP"; mmSessionBindInfo.AllowTransmit = true; mmSessionBindInfo.AllowReceive = true; mmSessionBindInfo.AddressNpi = NumberingPlanIndicator.Unknown; mmSessionBindInfo.AddressTon = TypeOfNumber.Unknown; mmSession = SmppClientSession.Bind(mmSessionBindInfo, 0); mmSession.PduReceived += new EventHandler <PduReceivedEventArgs>(PduReceivedEventHander); mmSubmitSm = new SubmitSm(); mmSubmitSm.DataCoding = DataCoding.UCS2; mmSubmitSm.ServiceType = "CMT"; // cellular messaging mmSubmitSm.RegisteredDelivery = RegisteredDelivery.DeliveryReceipt; mmSubmitSm.DestinationAddress.Address = "********"; // destination mmSubmitSm.DestinationAddress.Npi = NumberingPlanIndicator.ISDN; mmSubmitSm.DestinationAddress.Ton = TypeOfNumber.International; mmSubmitSm.SourceAddress.Npi = NumberingPlanIndicator.Unknown; mmSubmitSm.SourceAddress.Ton = TypeOfNumber.Aphanumeric; mmSubmitSm.SourceAddress.Address = "*********"; try { mmSubmitSm.SetMessageText(Encoding.UTF8.GetString(Encoding.UTF8.GetBytes("Текст")), DataCoding.UCS2); mmSubmitSmResp = mmSession.SendPdu(mmSubmitSm) as SubmitSmResp; MessageBox.Show(DateTime.Now.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); } MessageBox.Show(mmSubmitSmResp.MessageID + " , " + mmSubmitSmResp.Header.ErrorCode.ToString() + " , " + mmSubmitSm.GetMessageText()); }
protected override IEnumerable <SendSmPdu> GetPdUs(DataCoding defaultEncoding) { SubmitSm sm = new SubmitSm(); sm.SourceAddress.Address = VSourceAddress; sm.DestinationAddress.Address = VDestinatinoAddress; // Urgh, typo :( sm.DataCoding = defaultEncoding; if (VRegisterDeliveryNotification) { sm.RegisteredDelivery = RegisteredDelivery.DeliveryReceipt; } _vMaxMessageLength = GetMaxMessageLength(defaultEncoding, false); byte[] bytes = SmppEncodingUtil.GetBytesFromString(_vText, defaultEncoding); // Unicode encoding return 2 items for 1 char // We check vText Length first if (_vText.Length > _vMaxMessageLength && bytes.Length > _vMaxMessageLength) // Split into multiple! { var segId = new Random().Next(1000, 9999); // create random SegmentID _vMaxMessageLength = GetMaxMessageLength(defaultEncoding, true); var messages = Split(_vText, _vMaxMessageLength); var totalSegments = messages.Count; // get the number of (how many) parts var udh = new Udh(segId, totalSegments, 0); // ID, Total, part for (int i = 0; i < totalSegments; i++) { udh.MessageSequence = i + 1; // seq+1 , - parts of the message sm.SetMessageText(messages[i], defaultEncoding, udh); // send parts of the message + all other UDH settings yield return(sm); } } else { sm.SetMessageBytes(bytes); yield return(sm); } }