Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nodejs-wechat

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodejs-wechat

wechat api

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Nodejs Wechat

NPM version Build Status

Nodejs wrapper of wechat api

Usage

var Wechat = require('nodejs-wechat');
var opt = {
  token: token,
  url: '/weixin'
};
var wechatInstance = new Wechat(opt);

var express = require('express');
var middlewares = require('express-middlewares-js');
var app = express();

app.use('/weixin', Wechat.bodyParser());
// alternative method
// app.use('/weixin', middlewares.xmlBodyParser());

app.get('/weixin', wechatInstance.verifyRequest.bind(wechatInstance));
app.post('/weixin', wechatInstance.handleRequest.bind(wechatInstance));

// you can work with other restful logics
app.use('/api', middlewares.bodyParser());

wechat.on('text', function(session) {
  session.replyTextMsg('Hello World');
});
wechat.on('image', function(session) {
  session.replyNewsMsg([{
    Title: '新鲜事',
    Description: '点击查看今天的新鲜事',
    PicUrl: 'http://..',
    Url: 'http://..'
  }]);
});
wechat.on('voice', function(session) {
  session.replyMsg({
    Title: 'This is Music',
    MsgType: 'music',
    Description: 'Listen to this music and guess ths singer',
    MusicUrl: 'http://..',
    HQMusicUrl: 'http://..',
    ThumbMediaId: '..'
  });
});

Api

Wechat
  • #verifyRequest(req, res)

    This is a express/connect middleware, which verify the signature of request from weixin server

  • #handleRequest(req, res)

    This is a express/connect middleware, which handle the request post from weixin server

  • #on(msgType, handler)

    Wechat is an inheritance from event.EventEmitter. Wechat will emit an event in incoming message's MsgType, with a Session as parameter. Valid events:

    text, image, voice, video, location, link, event.subscribe, event.unsubscribe, event.SCAN, event.LOCATION, event.CLICK, event.VIEW.

    References: 接收普通消息, 接收事件推送

Session
  • req

    This is the request from weixin server

  • res

    This is the response to weixin server

  • #replyMsg(msgObject)

    Reply a message via this.res

  • #replyTextMessage(content)

    Reply a text message

  • #replyNewsMessage(articles)

    Reply a news messages.

TODO

  • Advanced interfaces

Keywords

FAQs

Package last updated on 18 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc