通过 SMPP 发送短信

发布于 2024-08-25 09:02:58 字数 95 浏览 7 评论 0原文

如何通过 SMPP 直接发送短信?我的提供商提供了 SMPP 接口来发送短信,我如何连接到它?是否有任何库或示例可以指导我如何使用 SMPP 发送?也许使用 PHP?还是C#?

How do I send SMS directly via SMPP? My provider provides an SMPP interface to send SMS, how do I connect it to it? Are there any libraries or examples that can educate me on using SMPP to send? Perhaps using PHP? or C#?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

没有你我更好 2024-09-01 09:03:06

我建议 SMPP 使用 Kannel,但有几个问题。

谁是您的聚合器?他们应该为此提供一些帮助。

我知道 OpenMarket 使用多种 SDK 语言支持 SMPP 和 HTTP

I would suggest Kannel for SMPP but a couple of questions.

Who is your Aggregator? They should offer some assistance for this.

I know OpenMarket does SMPP as well as HTTP with a multiple SDK languages

总攻大人 2024-09-01 09:03:06

Devshock 组件很酷...我猜他们在某个时候发布了源代码?

我相信我仍然拥有那个。

但编写自己的 smpp 库并不难...

SMPP 3.4 规范相当简单。

您基本上要做三件事:

  • 管理套接字连接 - .net 堆栈使这变得非常容易并且
    高效
  • 发送格式正确的 PDU,
  • 将接收到的字节解码为 PDU

Ola,如果您仍然需要,可以给我发邮件。

干杯。

编辑
一些提供商,例如我使用的提供商(高科技信息系统)还为您提供一个 http 网关,您可以通过该网关发布您的流量。

您可能会寻求将其作为 SMPP 的替代方案。

我见过的 SMPP 的一个缺点是网络连接不稳定,导致频繁断开连接。

HTTP 网关选项不会受到此影响,而且速度也一样快。

Devshock component was cool... they released the source i guess at some point?

I believe i still have that.

but writing your own smpp lib is not that hard...

SMPP 3.4 spec is fairly straight forward.

You are basically doing 3 things:

  • managing socket connections - .net stack makes that very easy and
    efficient
  • sending properly formatted PDU
  • decoding received bytes into PDU

Ola, you can drop me a mail if you still need this.

Cheers.

EDIT
Some Provider, like the one i use (High Tech InfoSystems) also provide you a http gateway through which you may post your traffic

You may seek that as an alternative to SMPP.

One downside i have seen experienced with SMPP, is frequent disconnects is your Network connection is shaky.

The HTTP gateway options does not suffer from this and is just as fast too.

你是年少的欢喜 2024-09-01 09:03:06

下面是在 C# 中使用 smpp 协议的简单示例代码。

顺便说一句,ardan studio dll 在数据编码和解码方面存在一些问题。

TON 和 NP? 在 ardan studio dll 中是静态的,所以我们更改了它,然后使用了这段代码,否则它可以工作,但你不能使用不同的字符集。

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
}

Here is the simple example code using smpp protocol in C#.

By the way ardan studio dll has some issue about data encoding and decoding.

TON and NPİ is given static in ardan studio dll so we changed it then we used this code otherwise it works but you can't use different char set.

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
}
笔芯 2024-09-01 09:03:05

我使用 Kannel 进行 SMPP,将 kannel 连接到 smpp 服务器: 链接

这是我的 kannel.conf:

group = core
admin-port = 13000
smsbox-port = 13001
admin-password = bar
status-password = foo
log-file = "/var/log/kannel/bearerbox.log"
log-level = 0
box-deny-ip = "*.*.*.*"
box-allow-ip = "127.0.0.1"
access-log = "/var/log/kannel/smsaccess.log"

#SMSC CONNECTION
group=smsc
smsc=smpp
smsc-id=ID1
host=130.1.1.50
port=5016
transceiver-mode = 1
source-addr-ton = 1
source-addr-autodetect = 0
dest-addr-npi = 1
dest-addr-ton = 1
smsc-username = "user"
smsc-password= "pass"
system-type= "system"

#SMSBOX SETUP
group = smsbox
bearerbox-host = 127.0.0.1
bearerbox-port = 13001
sendsms-port = 13013
log-file = "/var/log/kannel/smsbox.log"
log-level = 0
access-log = "/var/log/kannel/smsaccess.log"

#SEND-SMS USERS
group = sendsms-user
username = user
password = pass

#SERVICES
group = sms-service
keyword = default
text = "Su mensaje ha sido procesado"
concatenation = true
catch-all = true
accept-x-kannel-headers = true
get-url = "http://localhost/kannel/receivesms.php?sender=%p&text=%b"

发送短信:

curl "http://localhost:13013/cgi-bin/sendsms?user=xxxxxx&pass=yyyyy&to=56976808016&text=tes"

I use a Kannel for SMPP, connect kannel to a smpp server: link.

This is my kannel.conf:

group = core
admin-port = 13000
smsbox-port = 13001
admin-password = bar
status-password = foo
log-file = "/var/log/kannel/bearerbox.log"
log-level = 0
box-deny-ip = "*.*.*.*"
box-allow-ip = "127.0.0.1"
access-log = "/var/log/kannel/smsaccess.log"

#SMSC CONNECTION
group=smsc
smsc=smpp
smsc-id=ID1
host=130.1.1.50
port=5016
transceiver-mode = 1
source-addr-ton = 1
source-addr-autodetect = 0
dest-addr-npi = 1
dest-addr-ton = 1
smsc-username = "user"
smsc-password= "pass"
system-type= "system"

#SMSBOX SETUP
group = smsbox
bearerbox-host = 127.0.0.1
bearerbox-port = 13001
sendsms-port = 13013
log-file = "/var/log/kannel/smsbox.log"
log-level = 0
access-log = "/var/log/kannel/smsaccess.log"

#SEND-SMS USERS
group = sendsms-user
username = user
password = pass

#SERVICES
group = sms-service
keyword = default
text = "Su mensaje ha sido procesado"
concatenation = true
catch-all = true
accept-x-kannel-headers = true
get-url = "http://localhost/kannel/receivesms.php?sender=%p&text=%b"

Send SMS:

curl "http://localhost:13013/cgi-bin/sendsms?user=xxxxxx&pass=yyyyy&to=56976808016&text=tes"
余罪 2024-09-01 09:03:05

如果您熟悉Perl,则可以使用Net::SMPPJasmin(内置于 Python)。这些都经过了相当多的测试和使用。

You can use Net::SMPP if you are familiar with Perl or Jasmin (built in Python). Those are pretty tested and used.

像你 2024-09-01 09:03:04

有一个用 Java 编写的 Logica SMPP 项目,可以帮助您了解这一问题。除此之外,SMPP 维基百科页面上有一个项目列表,可以达到类似的目的。

There's the Logica SMPP project, written in Java, that could educate you on the matter. Other than that, there's a list of projects on the SMPP Wikipedia page that could fill a similar purpose.

桃扇骨 2024-09-01 09:03:04

我已经使用 DevShock 的客户端库几年了,但该公司似乎已经从我的视野中消失了。

谷歌很快就找到了这个:

http://www.inetlab.ru /Products/ALT.SMS.SmppClient.aspx

看起来很简单,并且附带了 C# 和 VB.Net 示例以及一些不错的文档。

希望有帮助。

I've used a client library from DevShock for a few years, but the company seems to have disappeared from view.

A quick Google turned up this one though:

http://www.inetlab.ru/Products/ALT.SMS.SmppClient.aspx.

Seems straightforward enough, and comes with both C# and VB.Net examples as well as some decent documentation.

Hope that helps.

迟月 2024-09-01 09:03:04

我认为最好的选择是 jsmpp lib。它有很好的例子,许多低级的事情发生在幕后,你可以专注于你的业务逻辑。

jsmpp 主网站

I think that the best choise is jsmpp lib. It have good examples and many low level thing happen behind the scenes and you can focus on your business logic.

jsmpp home site

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文