GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tong3jie/node-smgp: a tool for chinatelecom smgp.

BranchesTags
Open more actions menu

Latest commit

 

History

18 Commits
18 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
__pycache__
__pycache__
 
 
src
src
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
index.ts
index.ts
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

a tool for chinatelecom smgp.

Supports Node.js >= 14.

Quick Start

Install

$ npm install node-smgp

Client Example

Connnect Config

const config = {
  host: string;
  port: number;
  clientID: string;
  secret: string;
  spId: string;
  serviceId: string;
  srcId: string;
}

Create Connection

import Socket from 'node-smgp';

const SMGPSocket = new Socket({
  host: '127.0.0.1',
  port: 7789,
  clientID: 'abcdef',
  secret: 'abcdefg',
  spId: '10691234',
  serviceId: 'smgpservice',
  srcId: '10691234',
});

Exit

SMGPSocket.on('exit', exitMsg => {
  console.log(exitMsg);
});

TimeOut

send 3 times

SMGPSocket.on('timeout', (phone, content) => {
  console.log(phone, content);
});

Deliver

SMGPSocket.on('deliver', (Msg, callback) => {
  if (callback) callback();
  const { header, body } = Msg;
  const { SequenceID } = header;
  const { MsgID, IsReport, MsgFormat, SrcTermID, DestTermID, MsgLength, MsgContent } = body;
  switch (IsReport) {
    //状态报告
    case 1:
      db.inserte({ SequenceID, MsgID, MsgFormat, SrcTermID, DestTermID, MsgLength, MsgContent });
    //上行消息
    default:
      console.log(MsgContent);
  }
});

Send SMS

SMGPSocket.sendSms('13301171412', '【京东】您的验证码为:123456');

Server Example

Create server

import Socket from 'node-smgp';

const server = new Server({
  host: '127.0.0.1',
  port: 9000,
  // process login
  Login: (loginMsg: { header: IHeader; body: ILogin }): ILogin_Resp => {
    console.log(loginMsg);
    return { Status: 0, AuthenticatorServer: '1', ServerVersion: 0x03 };
  },
  // process submit
  Submit: (submitMsg: { header: IHeader; body: ISubmit }): ISubmit_Resp => {
    // console.log(submitMsg);

    return { Status: 0, MsgID: Date.now().toString() };
  },

  // process deliver
  Deliver: (deliverMsg: { header: IHeader; body: IDeliver_Resp }) => {
    console.log(deliverMsg);
  },
});

server.start();
server.on('error', error => {
  console.log(error);
});

deliver

server.deliver({ 
  MsgID: '123', 
  IsReport: 1, 
  MsgFormat: 8, 
  RecvTime: Date.now().toString(), 
  SrcTermID: '10691234', 
  DestTermID: '13301112222', 
  MsgLength: 12, 
  MsgContent: '123', 
  Reserve: '' 
})

Questions & Suggestions

Please open an issue here.

About

a tool for chinatelecom smgp.

Topics

smgp

Resources

Readme
Activity

Stars

3 stars

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.