1
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 值参数超出 buffer.js 的范围。请帮助。真的感谢任何帮助

4

2 回答 2

4

通过这个解决了这个问题..希望有一天它可以帮助某人

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));
于 2018-01-09T10:34:00.697 回答
1

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

message_payload定义:

包含扩展的短信用户数据。最多可以传输 64K 八位字节。

官方文件说:

需要发送超过 254 个八位字节的消息的应用程序应使用 message_payload 参数。在这种情况下,sm_length 字段应设置为零。

短消息数据应插入到 short_message 或 message_payload 字段中。两个字段不得同时使用。

我用node-smpp做了一个测试,它可以工作。无需串联。

于 2021-01-05T15:48:28.097 回答