【问题标题】:SMPP - Receiving MessagesSMPP - 接收消息
【发布时间】:2016-08-11 11:00:15
【问题描述】:

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

【问题讨论】:

  • 请确保您的代码缩进良好 - 这样更容易阅读,也更容易为我们提供帮助。
  • 你怎么知道接收失败?你确定没有引发事件吗?你是如何初始化客户端对象的?
  • 你好 elyashiv。谢谢你的帮助。我很感激。我知道接收失败,因为当我通过电话发送消息时它没有通过,并且我收到一条消息说“发送失败”。这是我初始化客户端对象的方式: private static SmppClient client = new SmppClient(); UTLSystem() { 客户端 = 新的 SmppClient(); }
  • 我正在尝试编辑我的问题并根据需要添加更多代码。
  • elyashiv,我在我的问题中添加了所需的代码。请检查。非常感谢。我真的很感激。

标签: c# smpp


【解决方案1】:

请确保您的 smpp 网关已配置为接收短信​​。应该配置成收发模式。

【讨论】:

  • 这应该是评论而不是答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-06
  • 2021-12-21
  • 1970-01-01
  • 1970-01-01
  • 2010-10-10
  • 2019-10-30
  • 1970-01-01
相关资源
最近更新 更多