理解smpp node.js上的auth

好的,我在这里挣扎了一下。 这是我想要实现的:创build并运行一个smpp服务器,用于侦听来自我们的短信服务平台的smpp发送请求。 只有我们的平台应该能够连接到这个服务器。

在接收绑定时,授权它我们的服务,并接收发送请求

只接受来自授权用户/密码的发送请求。

在收到发送请求后,将其发送给我们的消息传递提供者,其中registered_delivery = 1

等待deliver_sm响应让我们知道它已经到达

用消息传递状态更新我们的本地数据库。

我的问题 – 我的服务似乎让任何做未经授权的submit_sm。

这里有一些粗糙的,难看的testing代码,我已经放在一起了。 我是否构造错误? 请记住,我对smpp和node.js都很陌生,所以我可能会疯狂地偏离轨道。

var smpp = require('smpp'); // create listener for incoming connections from our server var server = smpp.createServer(function(session) { // create outbound connection to provider to pass messages on var outsession = smpp.connect('smpp.provider.net', 8101); outsession.bind_transceiver({ system_id: 'myaccount', password: 'abcdef' }, function (pdu){ console.log("outsession bind completed"); if (pdu.command_status == 0){ console.log("outsession bind completed ok, status 0"); } }); console.log("Srv: starting session.on event handlers"); session.on('bind_transceiver', function(pdu) { // we pause the session to prevent further incoming pdu events, // untill we authorize the session with some async operation. // auth incoming - can ONLY be our local system so far. //if (checkAsyncUserPass(id,pw)){ // credentials ok // how do I remember this for future send request ? //} else { // report fail //} console.log("Srv: received bind_transceiver"); session.send(pdu.response()); outsession.submit_sm({ destination_addr: '447957123456', registered_delivery: 1, short_message: 'Hello from provider, received a bind to server' }, function(pdu) { if (pdu.command_status == 0) { console.log('srv: sent ok to provider'); } }); session.send(pdu.response()); // listen for incoming delivery response messages for previous messages outsession.on('deliver_sm_resp', function(pdu){ console.log('srv: outsession received a deliver_sm_resp'); }); outsession.on('deliver_sm', function(pdu){ console.log('srv: outsession received a deliver_sm pdu'); }); }); session.on('unbind', function(pdu){ console.log("Srv: received unbind"); session.send(pdu.response()); }); session.on('submit_sm', function(pdu){ console.log("Srv: received submit_sm, pdu:"); session.send(pdu.response()); }); session.on('submit_sm_resp', function(pdu){ console.log("Srv: received submit_sm_resp"); session.send(pdu.response()); }); session.on('deliver_sm', function(pdu){ console.log("Srv: received deliver_sm pdu:"); session.send(pdu.response()); }); session.on('deliver_sm_resp', function(pdu){ console.log("Srv: session received deliver_sm_resp"); session.send(pdu.response()); }); session.on('enquire_link', function(pdu){ console.log("Srv: received enquire_link"); session.send(pdu.response()); }); session.on('enquire_link_sm', function(pdu){ console.log("Srv: received enquire_link_sm"); session.send(pdu.response()); }); }); function checkAsyncUserPass(id, pw, fn){ return true; } server.listen(8101); 

您必须调用授权用户凭证的asynchronous函数:

 session.on('bind_transceiver', function(pdu) { // pause the session to prevent further incoming pdu events // until we authorize the session with an async operation session.pause(); checkAsyncUserPass(pdu.system_id, pdu.password, function(client){ if(!client){ session.send(pdu.response({ command_status: smpp.ESME_RBINDFAIL //Here reject WRONG clients })); session.close(); return; } // receive SMS... session.resume(); session.on('submit_sm', function(pdu) { // do whatever you want to do with received SMS // eg respond with an uuid response or something: session.send(pdu.response({ message_id: msgid //uuid (you have to generate this) }); }); }); //End checkAsyncUserPass }); //End bind_transceiver