我是SMPP的新手,我正在使用JamatechSMPP(一个用于SMPP的开源.NET库)连接到SMSC。我成功地能够发送消息但是我无法接收。 Jamatech帮助文档说,当收到消息但接收失败时,将引发一个名为“client_MessageReceived”的事件,我不确定如何在收到消息时提出该事件。
class UTSystem
{
private static SmppClient client;
UTSystem()
{
client = new SmppClient();
}
public static SmppClient ConnectToSMSC()
{
try
{
client.Shutdown();
SmppConnectionProperties properties = client.Properties;
properties.SystemID = "xxxxxxxx";
properties.Password = "xxxxxxx";
properties.Port = xxxx; //IP port to use
properties.Host = "xxxxxxxxxxx"; //SMSC host name or IP Address
properties.SystemType = "SMPP";
properties.DefaultServiceType = ServiceType.CELLULAR_MESSAGING;
properties.AddressNpi = NumberingPlanIndicator.Unknown;
properties.AddressTon = TypeOfNumber.Unknown;
client.AutoReconnectDelay = 3000;
client.KeepAliveInterval = 15000;
//Start smpp client
client.ForceConnect();
return client;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return client;
}
}
public static void ReceiveSMS()
{
try
{
ConnectToSMSC();
client.MessageReceived += new EventHandler < MessageEventArgs > (client_MessageReceived);
}
catch (Exception ex) {}
}
static public void client_MessageReceived(object sender, MessageEventArgs e)
{
//The event argument e contains more information about the received message
TextMessage textMsg = e.ShortMessage as TextMessage; //This is the received text message
int res = SaveMsg(textMsg.SourceAddress.ToString(), textMsg.Text.ToString());
}
请确保您的smpp网关配置为接收SMS。它应配置为收发器模式。