static SmppClient CreateSmppClient(ISmppConfiguration config) { var client = new SmppClient(); client.Name = config.Name; //client.SmppEncodingService = new SmppEncodingService(System.Text.Encoding.UTF8); client.ConnectionStateChanged += new EventHandler <ConnectionStateChangedEventArgs>(client_ConnectionStateChanged); client.StateChanged += new EventHandler <StateChangedEventArgs>(client_StateChanged); client.MessageSent += new EventHandler <MessageEventArgs>(client_MessageSent); client.MessageDelivered += new EventHandler <MessageEventArgs>(client_MessageDelivered); client.MessageReceived += new EventHandler <MessageEventArgs>(client_MessageReceived); SmppConnectionProperties properties = client.Properties; properties.SystemID = config.SystemID; // "mysystemid"; properties.Password = config.Password; // "mypassword"; properties.Port = config.Port; // 2034; //IP port to use properties.Host = config.Host; // "196.23.3.12"; //SMSC host name or IP Address properties.SystemType = config.SystemType; // "mysystemtype"; properties.DefaultServiceType = config.DefaultServiceType; // "mydefaultservicetype"; properties.DefaultEncoding = config.Encoding; //Resume a lost connection after 30 seconds client.AutoReconnectDelay = config.AutoReconnectDelay; //Send Enquire Link PDU every 15 seconds client.KeepAliveInterval = config.KeepAliveInterval; return(client); }
static void Main(string[] args) { smppConfig = GetSmppConfiguration(); SMPPEncodingUtil.UCS2Encoding = Encoding.UTF8; var client = CreateSmppClient(smppConfig); client.Start(); // must wait until connected before start sending while (client.ConnectionState != SmppConnectionState.Connected) { Thread.Sleep(100); } TextMessage msg = new TextMessage(); msg.DestinationAddress = "255455388333"; //Receipient number msg.SourceAddress = "255344338333"; //Originating number //msg.Text = "Hello, this is my test message!"; msg.Text = @"السلام عليكم ورحمة الله وبركاته هذه رسالة عربية متعددة الاسطر"; msg.RegisterDeliveryNotification = true; //I want delivery notification for this message msg.UserMessageReference = Guid.NewGuid().ToString(); Console.WriteLine($"msg.UserMessageReference: {msg.UserMessageReference}"); client.SendMessage(msg); Console.ReadLine(); }
static void Main(string[] args) { smppConfig = GetSmppConfiguration(); SMPPEncodingUtil.UCS2Encoding = Encoding.BigEndianUnicode; var client = CreateSmppClient(smppConfig); client.Start(); // must wait until connected before start sending while (client.ConnectionState != SmppConnectionState.Connected) { Thread.Sleep(100); } TextMessage msg = new TextMessage(); msg.DestinationAddress = "255455388333"; //Receipient number msg.SourceAddress = "255344338333"; //Originating number //msg.Text = "Hello, this is my test message!"; msg.Text = "السلام عليكم"; msg.RegisterDeliveryNotification = true; //I want delivery notification for this message client.SendMessage(msg); Console.ReadLine(); }
public bool SendSMSC(string pBody, string pTargetPhone) { bool result = false; try { smppConfig = GetSmppConfiguration(); var client = CreateSmppClient(smppConfig); client.Start(); // must wait until connected before start sending while (client.ConnectionState != SmppConnectionState.Connected) { Thread.Sleep(100); } TextMessage msg = new TextMessage(); msg.DestinationAddress = pTargetPhone; //Receipient number msg.SourceAddress = "4094949"; //Originating number msg.Text = pBody; msg.RegisterDeliveryNotification = true; //I want delivery notification for this message client.SendMessage(msg); result = true; } catch (Exception) { result = false; } return(result); }
static void Main(string[] args) { //Common.Logging.LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(); var encSrv = new SmppEncodingService(); var hexBytes = "000000dd0000000500000000019182410001013334363439323836383039000501657669636572746961000400000000000000008569643a323533303932393134353232363637333732207375623a30303120646c7672643a303031207375626d697420646174653a3133303932393136353220646f6e6520646174653a3133303932393136353220737461743a44454c49565244206572723a3030303020746578743a1b3c657669534d531b3e0a534d532064652050727565042300030300000427000102001e001332353330393239313435323236363733373200"; var packet = StringToByteArray(hexBytes); var bodyBytes = packet.Skip(16).ToArray(); var pdu = PDU.CreatePDU(PDUHeader.Parse(new ByteBuffer(packet), encSrv), encSrv); pdu.SetBodyData(new ByteBuffer(bodyBytes)); var receiptedMessageId = pdu.GetOptionalParamString(JamaaTech.Smpp.Net.Lib.Protocol.Tlv.Tag.receipted_message_id); //Assert.AreEqual("253092914522667372", pdu.ReceiptedMessageId); Trace.WriteLine("Start"); //Trace.Listeners.Add(new ConsoleTraceListener()); smppConfig = GetSmppConfiguration(); //SMPPEncodingUtil.UCS2Encoding = Encoding.UTF8; var client = CreateSmppClient(smppConfig); client.Start(); // must wait until connected before start sending while (client.ConnectionState != SmppConnectionState.Connected) { Thread.Sleep(100); } var input = ""; do { Console.Write("Enter Dest: "); input = Console.ReadLine(); if ("q".Equals(input, StringComparison.InvariantCultureIgnoreCase)) { break; } var dest = input; Console.Write("Enter Msg: "); var msgTxt = Console.ReadLine(); if (string.IsNullOrEmpty(msgTxt)) { msgTxt = @"السلام عليكم ورحمة الله وبركاته هذه رسالة عربية متعددة الاسطر"; } TextMessage msg = new TextMessage(); msg.DestinationAddress = dest; //Receipient number msg.SourceAddress = smppConfig.SourceAddress; //Originating number //msg.Text = "Hello, this is my test message!"; msg.Text = msgTxt; msg.RegisterDeliveryNotification = true; //I want delivery notification for this message msg.UserMessageReference = Guid.NewGuid().ToString(); Console.WriteLine($"msg.UserMessageReference: {msg.UserMessageReference}"); Trace.WriteLine($"msg.UserMessageReference: {msg.UserMessageReference}"); //client.SendMessage(msg); client.BeginSendMessage(msg, SendMessageCompleteCallback, client); Console.ReadLine(); } while (true); }
static void Main(string[] args) { Common.Logging.LogManager.Adapter = new Common.Logging.Simple.DebugLoggerFactoryAdapter(); var encSrv = new SmppEncodingService(); var hexBytes = "000000dd0000000500000000019182410001013334363439323836383039000501657669636572746961000400000000000000008569643a323533303932393134353232363637333732207375623a30303120646c7672643a303031207375626d697420646174653a3133303932393136353220646f6e6520646174653a3133303932393136353220737461743a44454c49565244206572723a3030303020746578743a1b3c657669534d531b3e0a534d532064652050727565042300030300000427000102001e001332353330393239313435323236363733373200"; var packet = StringToByteArray(hexBytes); var bodyBytes = packet.Skip(16).ToArray(); var pdu = PDU.CreatePDU(PDUHeader.Parse(new ByteBuffer(packet), encSrv), encSrv); pdu.SetBodyData(new ByteBuffer(bodyBytes)); var receiptedMessageId = pdu.GetOptionalParamString(JamaaTech.Smpp.Net.Lib.Protocol.Tlv.Tag.receipted_message_id); //Assert.AreEqual("253092914522667372", pdu.ReceiptedMessageId); _Log.Info("Start"); //Trace.Listeners.Add(new ConsoleTraceListener()); smppConfig = GetSmppConfiguration(); //SMPPEncodingUtil.UCS2Encoding = Encoding.UTF8; client = CreateSmppClient(smppConfig); client.Start(); // must wait until connected before start sending while (client.ConnectionState != SmppConnectionState.Connected) { Thread.Sleep(100); } // Accept command input bool bQuit = false; do { // Hit Enter in the terminal once the binds are up to see this prompt Console.WriteLine("Commands"); Console.WriteLine("send 123456 hello"); Console.WriteLine("quit"); Console.WriteLine(""); Console.Write("\n#>"); string command = Console.ReadLine(); if (command.Length == 0) { continue; } switch (command.Split(' ')[0].ToString()) { case "quit": case "exit": case "q": bQuit = true; break; default: ProcessCommand(command); break; } if (bQuit) { break; } } while (true); if (client != null) { client.Dispose(); } }