# wechat-message-handlers

> 为处理微信消息提供一种简便统一的方式

Latest version **0.1.0** (published 2016-05-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install wechat-message-handlers
pnpm add wechat-message-handlers
yarn add wechat-message-handlers
bun add wechat-message-handlers
```

## 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.1.0 |
| Published | 2016-05-05 |
| First published | 2016-05-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | na57 |
| Maintainers | na57 |
| Keywords | wechat |

## Links

- npm: https://www.npmjs.com/package/wechat-message-handlers
- Repository: https://github.com/nagucc/wechat-message-handlers
- Homepage: https://github.com/nagucc/wechat-message-handlers#readme
- Issues: https://github.com/nagucc/wechat-message-handlers/issues
- npm.io page: https://npm.io/package/wechat-message-handlers

## Dependencies (2)

- [uuid](https://npm.io/package/uuid.md) ^2.0.2
- [lodash.isfunction](https://npm.io/package/lodash.isfunction.md) ^3.0.8

## Recent versions

- 0.1.0 (latest) — 2016-05-05
- 0.0.2 — 2016-05-05
- 0.0.1 — 2016-05-05

## README

# wechat-message-handlers
为处理微信消息提供一种简便统一的方式

## Examples

### Wechat Enterprise

以下是在微信企业号中使用的示例，来自[wechat-enterprise-signup](https://github.com/nagucc/wechat-enterprise-signup)

```

import { Router } from 'express';
import wechat from 'wechat-enterprise';
import {handleEvent, handleText} from 'wechat-message-handlers';

const router = new Router();

let TextHandlers = {

  /*
处理用户输入的姓名
   */
  ready_for_name: (msg, req, res) => {
    req.wxsession.user_name = msg.Content;
    let str = `请输入您的手机号码：`;
    req.wxsession.mobile_signup = 'ready_for_mobile';
    res.reply(str);
  },
  ready_for_mobile: (msg, req, res) => {
    req.wxsession.user_mobile = msg.Content;
    let str = `${req.wxsession.user_name}, ${msg.Content}`;
    res.reply(str);
  },
  unhandled: (msg, req, res) => {
    res.reply('do nothing');
  }
}
let EventHandlers = {
  /*
    开始进入自主注册的程序
   */
  mobile_signup: (msg, req, res, next) => {
    let str = `欢迎注册，请输入您的姓名：`
    req.wxsession.mobile_signup = 'ready_for_name';
    res.reply(str);
  }
}

let getTextHandler = (msg, req) => {
  if(req.wxsession && req.wxsession.mobile_signup) {
    return TextHandlers[req.wxsession.mobile_signup];
  } else {
    return TextHandlers.unhandled;
  }
}
router.use('/', wechat(wxcfg, wechat.text(handleText(getTextHandler))
  .event(handleEvent(EventHandlers))));
export default router;

```

#### Notes

1. 上述例子中的`TextHandlers`对象中，`subscribe`和`unsubscribe`被保留，用作特定的订阅和取消订阅时间的处理函数。

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