如何使用节点 smpp 发送长消息?

how to send long message using node smpp?

exports.sendSMS = function (session, to, text, sourceAddress, jsonMessageHistoryIds, callback) {

     console.log('messege',text);

    session.submit_multi({
        source_addr: sourceAddress,
        dest_address: to,
        short_message: text

    }, function (pdu) {
        console.log('submit_multi: ', pdu.command_status);
        console.log("PDU", pdu);
        if (pdu.command_status == 0) {
            // insert into sms smpp logs
            var values = {
                type: 'bulk',
                message: text,
                numbers: JSON.stringify(to)
            };

        console.log(pdu.message_id);
            callback(null, pdu.message_id);
        }
    });
};

如果消息低于 160 个字符,则没关系。消息将被发送,但如果消息超过 160 个字符,那么它将抛出新的 TypeError value argument is out of bounds in buffer.js if sms messege is too long.Please 帮助。非常感谢任何帮助

通过这个解决了这个问题..希望有一天它能帮助别人

npm install gsm
The above module also splits the message into parts:

//We need to split the message and send it in many parts
var gsm = require('gsm');

var info = gsm("Your message string here");

//This is a unique id present in each message part
var concat_ref = this.concat_ref++; 

var part_id = 0;
info.parts.forEach(function(part) {
    part_id++;
    var udh = new Buffer(6);
    udh.write(String.fromCharCode(0x5), 0); //Length of UDF
    udh.write(String.fromCharCode(0x0), 1); //Indicator for concatenated message
    udh.write(String.fromCharCode(0x3), 2); //  Subheader Length ( 3 bytes)
    udh.write(String.fromCharCode(concat_ref), 3); //Same reference for all concatenated messages
    udh.write(String.fromCharCode(info.sms_count), 4); //Number of total messages in the concatenation
    udh.write(String.fromCharCode(part_id), 5); //Sequence number ( used by the mobile to concatenate the split messages)

    var submit_pdu = {
        source_addr:msg.from,
        destination_addr: msg.to,
        short_message: { udh:udh, message:part },
        registered_delivery:1 //If you want a delivery report
    };

    this.getSession().submit_sm(submit_pdu, function(pdu) {
        if (pdu.command_status == 0) {
            console.log("SMPP Gateway[" + this.getOptions().address + "] - SUMBIT[" + submit_pdu.source_addr + ">>>" + submit_pdu.destination_addr + "] - " + pdu.message_id);
        }
        if(callback) {
            callback(pdu);
        }
    }.bind(this));
}.bind(this));

您可以使用官方 SMPP specification 中所述的 message_payload 参数(字段名称)来发送长度超过 254 个八位字节的消息。

message_payload定义:

Contains the extended short message user data. Up to 64K octets can be transmitted.

官方文档说:

Applications which need to send messages longer than 254 octets should use the message_payload parameter. In this case the sm_length field should be set to zero.

The short message data should be inserted in either the short_message or message_payload fields. Both fields must not be used simultaneously.

我用 node-smpp 进行了测试,它有效。无需连接。