`

Nodejs 微信开发,wechat on nodejs

阅读更多
// app.js
var express = require('express')
  , http = require('http')
  , path = require('path')
  , swig = require('swig')
  , router = require('./node-app/router/router')
  , config = require('./node-app/config/config')

function initApp() {
  router.initRouter(express, app);
}

config.init(app, initApp);

 

// router.js
function appRouter(express, app) {
  var mainRouter = express.Router();
  mainRouter.use('/wechat', routes.wechat);
}

exports.initRouter = function (express, app) {
  app.use(appRouter(express, app));
}

 

// wechat.js
var map = require('../router-config').getMapping()
  , wechat = require('wechat');

function wechatRouter(express) {
  var router = express.Router();
  router.use('/', wechat('wechatToken').text(function (message, req, res, next) {
    // TODO
    res.reply('微信文本消息~~~~~~~');
  }).image(function (message, req, res, next) {
    // TODO
    res.reply('微信图片消息~~~~~~~');
  }).voice(function (message, req, res, next) {
    // TODO
    res.reply('微信语音消息~~~~~~~');
  }).video(function (message, req, res, next) {
    // TODO
    res.reply('微信视频消息~~~~~~~');
  }).location(function (message, req, res, next) {
    // TODO
    res.reply('微信地址消息~~~~~~~');
  }).link(function (message, req, res, next) {
    // TODO
    res.reply('微信链接消息~~~~~~~');
  }).event(function (message, req, res, next) {
    // TODO
    res.reply('微信事件消息~~~~~~~');
  }).middlewarify());
  return router;
}

module.exports = wechatRouter;

 

公众平台配置:

url:htttp://demo.com/wechat

token:wechatToken

 

微信截屏:

 

  • 大小: 134.1 KB
分享到:
评论
1 楼 wangwanttt 2016-06-01  
源码可以贴一下吗

相关推荐

Global site tag (gtag.js) - Google Analytics