SMPP - 接收消息

时间:2016-08-11 11:00:16

标签: c# smpp

我是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());
}

1 个答案:

答案 0 :(得分:0)

请确保您的smpp网关配置为接收SMS。应该将其配置为收发器模式。