Sms 通过SMPP发送短信

Sms 通过SMPP发送短信,sms,smpp,Sms,Smpp,如何通过SMPP直接发送短信?我的提供商提供了一个SMPP接口来发送SMS,我如何将其连接到它?是否有任何库或示例可以教我如何使用SMPP发送?也许使用PHP?或者C#?有一个用Java编写的,可以在这个问题上教育你。除此之外,网站上还有一个项目列表,可以满足类似的目的。我使用DevShock的一个客户端库已有几年了,但该公司似乎已经从人们的视野中消失了 不过,谷歌很快就发现了这一点: 看起来很简单,并附带了C#和VB.Net示例以及一些像样的文档 希望这能有所帮助。我建议您使用SMPP,但有

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

有一个用Java编写的,可以在这个问题上教育你。除此之外,网站上还有一个项目列表,可以满足类似的目的。

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

不过,谷歌很快就发现了这一点:

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

希望这能有所帮助。

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

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


我知道SMPP和HTTP都有多种SDK语言,我认为最好的选择是jsmpp库。它有很好的例子,很多低级的事情发生在幕后,你可以专注于你的业务逻辑


Devshock组件很酷。。。他们在某个时候公布了消息来源

我相信我还有这个

但是编写自己的smpp库并不是那么难

SMPP 3.4规范相当直截了当

你基本上做了三件事:

  • 管理套接字连接-.net堆栈使之非常简单和方便 有效的
  • 发送格式正确的PDU
  • 将接收到的字节解码为PDU
奥拉,如果你还需要这个,你可以给我寄封信

干杯

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

您可以将其作为SMPP的替代方案

我在SMPP中看到的一个缺点是频繁断开连接,即网络连接不稳定


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

我为SMPP使用Kannel,将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"

您可以使用SMPPCli,它是一个命令行SMPP SMS发送器。
您可以从下载它,如果您熟悉Perl或(内置Python),可以使用它。这些都经过了很好的测试和使用。

下面是在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
}
使用ArdanStudios.Common.SmppClient;
使用ArdanStudios.Common.SmppClient.App;
公共类SMPPClient服务
{
公共静态只读对象计数器锁=新对象();
私有静态bool isConnected=false;
专用ESMANAGER SMPPConnect客户端()
{
var smppServerPort=Library.GetAppSetting(SMPP_Server_Port).Split(“;”);
字符串server=“xxx.xx.xx.xxx”;
短端口=6101;
字符串shortLongCode=“MESSAGETİTLE”;
字符串systemId=“用户名”;
字符串password=“password”;
数据编码数据编码=数据编码.1;
ESMANAGER connectionManager=新的ESMANAGER(“EricssonTest”,shortLongCode,新的ESMANAGER.CONNECTION\u事件处理程序(ConnectionEventHandler),null,null,null,null,新的ESMANAGER.LOG\u事件处理程序(LogEventHandler),null);
connectionManager.AddConnections(1,ConnectionModes.Transmitter,服务器,端口,systemId,密码,“Transmitter”,数据编码);
返回连接管理器;
}
私有静态void LogEventHandler(LogEventNotificationTypes logEventNotificationType、字符串logKey、字符串shortLongCode、字符串消息)
{                    
}
私有静态void ConnectionEventHandler(字符串日志键、ConnectionEventTypes connectionEventType、字符串消息)
{
if(connectionEventType.Connected==connectionEventType)
{
锁(计数器锁)
{
断开连接=正确;
}
}
}
专用字符串Msisdn(字符串接收器)
{
var tmp=receiver.Replace(“/”,“”)
.替换(“,”)
.替换(“-”,”);
如果(tmp.Length==10)
返回90+接收器;
如果(tmp.Length==11&&tmp[0]==0')
返回9+tmp;
返回tmp;
}
public int SMPPSendMessage(字符串messageText,字符串phoneNumber)
{
var结果=0;
var pql=新的PSmsSendLogs();
尝试
{
使用(var connectionManager=SMPPConnectClient())
{
phoneNumber=Msisdn(phoneNumber);
数据编码提交数据编码=数据编码.1;
DataCodings encodeDataCoding=DataCodings.1;
List submitSm=null;
List submitSmResp=null;
while(true)
{
睡眠(1000);
如果(未连接)
{
*//将代码放在这里,等待连接建立。İt异步工作,因此在调用send方法时无法连接*
打破
}
}
结果=connectionManager.SendMessageLarge(电话号码、空、吨字母数字、Npi.Unknown、SubmitDataCodeding、EncodedDataCodeding、messageText、out submitSm、out submitSmResp);
}
}
捕获(例外情况除外)
{
结果=0;
}
返回结果;
}
#端区
}