如何使用节点smpp发送长消息? [英] how to send long message using node smpp?

查看:135
本文介绍了如何使用节点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);
        }
    });
};

如果messege的字符数少于160个,则表示是好的.将发送消息,但如果messege的字符数超过160个字符,则如果sms messege的时间太长,它将在buffer.js中抛出新的TypeError值参数. .非常感谢您的帮助

If the messege is below 160 character it is okey .Messege will be sent but if messege is above 160 character then it will throw new TypeError value argument is out of bounds in buffer.js if sms messege is too long.Please Help .will really appreciate any help

推荐答案

通过此..希望有一天能对某人有所帮助

solved this problem by this ..hope it helps someone someday

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发送长消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆