# node-smgp

> a tool for chinatelecom smgp

Latest version **0.0.11** (published 2021-05-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-smgp
pnpm add node-smgp
yarn add node-smgp
bun add node-smgp
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2021-05-26 |
| First published | 2021-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 5 |
| Unpacked size | 122.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | juju |
| Maintainers | tong3jie |
| Keywords | smgp |

## Links

- npm: https://www.npmjs.com/package/node-smgp
- Repository: https://github.com/tong3jie/node-smgp
- Homepage: https://github.com/tong3jie/node-smgp#readme
- Issues: https://github.com/tong3jie/node-smgp/issues
- npm.io page: https://npm.io/package/node-smgp

## Dependencies (5)

- [dayjs](https://npm.io/package/dayjs.md) ^1.10.4
- [debug](https://npm.io/package/debug.md) ^4.3.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [iconv-lite](https://npm.io/package/iconv-lite.md) ^0.6.2
- [sleep-promise](https://npm.io/package/sleep-promise.md) ^9.1.0

## Recent versions

- 0.0.11 (latest) — 2021-05-26
- 0.0.10 — 2021-05-08
- 0.0.9 — 2021-04-25
- 0.0.8 — 2021-04-25
- 0.0.7 — 2021-04-25
- 0.0.6 — 2021-04-25
- 0.0.3 — 2021-03-10
- 0.0.2 — 2021-03-09
- 0.0.1 — 2021-03-09

## README

a tool for chinatelecom smgp.

Supports Node.js >= 14.

# Quick Start

## Install

```shell
$ npm install node-smgp
```

# Client Example
## Connnect Config

```javascript
const config = {
  host: string;
  port: number;
  clientID: string;
  secret: string;
  spId: string;
  serviceId: string;
  srcId: string;
}
```

## Create Connection

```javascript
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

```javascript

SMGPSocket.on('exit', exitMsg => {
  console.log(exitMsg);
});

```

## TimeOut

***send 3 times***

```javascript

SMGPSocket.on('timeout', (phone, content) => {
  console.log(phone, content);
});

````

## Deliver

```javascript

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

```javascript

SMGPSocket.sendSms('13301171412', '【京东】您的验证码为：123456');

```

---
# Server Example

##  Create server
```javascript
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 
```javascript
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](https://github.com/tong3jie/node-smgp/issues).

---
_Source: https://npm.io/package/node-smgp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
