如何在NodeJS中使用udh连接从smpp客户端发送的消息

问题描述

我正在开发一个 sms 网关,我在其中开发了一个 smpp 服务器。我的一位客户想要使用 3rd 方工具发送消息。一切正常。除了一个。如果客户端发送超过 254 个八位字节的长消息,则 short_message 参数包含 udh 属性。我发现消息是按顺序传来的。我还注意到缓冲区具有该序列的值。 现在我需要将这些多部分消息合并为一个。我卡在这里

这是我的 smpp 服务器代码

import { SUBMIT_SM } from './app/constants/smpp.constants';
import * as smpp from 'smpp';
import { BIND_TRANSCEIVER } from './app/constants';

export class SMPPTestServer {
  constructor() {
    this.init();
  }

  public async init() {
    const server = smpp.createServer((session: any) => {
      session.on(BIND_TRANSCEIVER,async (pdu: any) => {
        session.pause();

        const buffers = [];

        session.on(SUBMIT_SM,async (pdu: any) => {
          const udh = pdu.short_message.udh[0];

          session.send(
            pdu.response({
              sequence_number: pdu.sequence_number,}),);
        });

        session.send(pdu.response());
        session.resume();
      });
    });

    server.listen(2775);
    console.log('SMPP Test Server Listening On 2775');
  }
}

这是我正在测试的客户端代码

var smpp = require('smpp');

function sleep(milliseconds) {
  return new Promise((resolve) => setTimeout(resolve,milliseconds));
}

var session = smpp.connect({
  url: 'smpp://localhost:2775',// url: 'smpp://157.230.248.140:2775',auto_enquire_link_period: 10000,});

session.bind_transceiver(
  {
    system_id: 'reshop',password: 'reshop202',},async function (pdu) {
    const messages = ['dddd','hello world','from message analytica'];
    const concatRef = Math.floor(Math.random() * 255);

    for (let i = 0; i < messages.length; i++) {
      const smsPart = messages[i];
      const udh = new Buffer(6);

      udh.write(String.fromCharCode(0x5),0); /* Length of UDH */
      udh.write(
        String.fromCharCode(0x0),1
      ); /* Indicator for concatenated message */
      udh.write(String.fromCharCode(0x3),2); /* Subheader Length (3 bytes) */
      udh.write(
        String.fromCharCode(concatRef),3
      ); /* Same reference for all concatenated messages */
      udh.write(
        String.fromCharCode(messages.length),4
      ); /* Number of total messages in the split */
      udh.write(
        String.fromCharCode(i + 1),5
      ); /* Sequence number (used by the mobile to concatenate the split messages) */

      if (pdu.command_status == 0) {
        session.submit_sm(
          {
            destination_addr: '01636476123',short_message: { udh: udh,message: smsPart },source_addr: '8809612440278',// sequence_number: 99,// {
          //   destination_addr: '01636476123',//   message_payload:
          //     "(CNN)Sme of the most damaging testimony against the police officer on trial over the death of George Floyd is coming from fellow cops. The second week of evidence against Derek Chauvin,who is charged with murdering Floyd,has moved on from wrenching eyewitness accounts of the Minnesota man's death,which sparked a worldwide racial reckoning. Prosecutors are now narrowing in on Chauvin's conduct in subduing Floyd,making a case that he acted outside reasonable police procedure.",//   source_addr: '8809612440278',//   sequence_number: 99,// },function (pdu) {
            console.log('[CLIENT => SUBMIT_SM]',pdu);
            console.log(i);

            if (pdu.command_status == 0) {
              // Message successfully sent
              console.log(pdu.message_id);
            }
          }
        );

        session.on('deliver_sm',async (pdu) => {
          if (pdu && pdu.receipted_message_id) {
            // console.log('[ON_DELIVER_SM]',pdu);
            session.send(
              pdu.response({
                sequence_number: pdu.sequence_number,message_id: pdu.receipted_message_id,})
            );
          }
        });

        console.log('Taking Nap');
        await sleep(10);

        // session.on('deliver_sm',function (pdu) {
        //   console.log('[CLIENT => DELIVER_SM]',pdu);
        // });
      }
    }
  }
);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...