Вот простой пример кода с использованием протокола smpp в C #.
Кстати, у ardan studio dll есть некоторые проблемы с кодированием и декодированием данных.
TON и NPİ задаются статическими в dll ardan studio, поэтому мы изменили его, затем использовали этот код, иначе он работает, но вы не можете использовать другой набор символов.
using ArdanStudios.Common.SmppClient;
using ArdanStudios.Common.SmppClient.App;
public class SMPPClientService
{
public static readonly object CounterLock = new object();
private static bool isConnected = false;
private ESMEManager SMPPConnectClient()
{
var smppServerPort = Library.GetAppSetting(SMPP_Server_Port).Split(';');
string server = "xxx.xx.xx.xxx";
short port = 6101;
string shortLongCode = "MESSAGETİTLE";
string systemId = "USername";
string password = "password";
DataCodings dataCoding = DataCodings.Latin1;
ESMEManager connectionManager = new ESMEManager("EricssonTest", shortLongCode, new ESMEManager.CONNECTION_EVENT_HANDLER(ConnectionEventHandler), null, null, null, null, new ESMEManager.LOG_EVENT_HANDLER(LogEventHandler), null);
connectionManager.AddConnections(1, ConnectionModes.Transmitter, server, port, systemId, password, "Transmitter", dataCoding);
return connectionManager;
}
private static void LogEventHandler(LogEventNotificationTypes logEventNotificationType, string logKey, string shortLongCode, string message)
{
}
private static void ConnectionEventHandler(string logKey, ConnectionEventTypes connectionEventType, string message)
{
if (ConnectionEventTypes.Connected == connectionEventType)
{
lock (CounterLock)
{
isConnected = true;
}
}
}
private string Msisdn(string receiver)
{
var tmp = receiver.Replace("/", "")
.Replace(" ", "")
.Replace("-", "");
if (tmp.Length == 10)
return 90 + receiver;
if (tmp.Length == 11 && tmp[0] == '0')
return 9 + tmp;
return tmp;
}
public int SMPPSendMessage(string messageText, string phoneNumber)
{
var result = 0;
var pql = new PSmsSendLogs();
try
{
using (var connectionManager = SMPPConnectClient())
{
phoneNumber = Msisdn(phoneNumber);
DataCodings submitDataCoding = DataCodings.Latin1;
DataCodings encodeDataCoding = DataCodings.Latin1;
List<SubmitSm> submitSm = null;
List<SubmitSmResp> submitSmResp = null;
while (true)
{
Thread.Sleep(1000);
if (isConnected)
{
*// put code here to wait until connection is being establish.İt works Async so it coulnt be connected when we called send method*
break;
}
}
result = connectionManager.SendMessageLarge(phoneNumber, null, Ton.Alphanumeric, Npi.Unknown, submitDataCoding, encodeDataCoding, messageText, out submitSm, out submitSmResp);
}
}
catch (Exception ex)
{
result = 0;
}
return result;
}
#endregion
}