npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

think-wechat

v1.1.0

Published

wechat middleware for thinkjs 3.0

Downloads

21

Readme

Think-wechat

npm status build status dependency status coverage status

微信中间件,基于 node-webot/wechat,支持 thinkJS 3.0

Getting start

$ npm install think-wechat

配置 middleware

  • 编辑 config/middleware.js
const path = require('path');
const wechat = require('think-wechat')
const isDev = think.env === 'development';

module.exports = [
  [...]
  {
    handle: wechat,
    match: '/wechat',
    options: {
      token: <微信开发者token>,
      appid: <appID>,
      encodingAESKey: <消息对称加密串>,
      checkSignature: true // 可选,默认为true。由于微信公众平台接口调试工具在明文模式下不发送签名,所以如要使用该测试工具,请将其设置为false
    }
  },
  {
    handle: 'payload',
    options: {}
  },
  [...]
];

注意:think-wechat 必须要在 payload 中间件前面加载,它会代替 payload 处理微信发过来的 post 请求中的数据。

  • 根据 match 配置,增加对应的 controller 和 action

支持的 action 包括:textAction、imageAction、voiceAction、videoAction、shortvideoAction、locationAction、linkAction、eventAction、deviceTextAction、deviceEventAction。

const Base = require('./base.js');
const DEFULT_AUTO_REPLY = '功能正在开发中~';

export default class extends Base {
  /**
   * index action
   * @return {Promise} []
   */
  indexAction(){
    // 验证开发者服务器
    // 这里只是演示,所以没做签名校验,实际上应该要根据微信要求进行签名校验
    const echostr = this.get('echostr');
    return this.end(echostr);
  }
  // textAction(){
      // 发送文本消息
  //  const {Content} = this.post();    
  //  this.success('你发送给我的是:' + Content.trim());
  // }
  async textAction(){
  	const {Content} = this.post();
  	const music = await myService.search(Content.trim());
  	
  	if(music){
  		const {title, description, url} = music;
  		this.success({
  			type: 'music',
        	content: {
	        title,
	        description,
	        musicUrl: url,
	        hqMusicUrl: url,
	        thumbMediaId: "thisThumbMediaId"
	      }			
  		});
  	}else{
  		this.fail('你所找的歌曲不存在');
  	}
  }
  eventAction(){
    const message = this.post();
    
    this.success(JSON.stringify(message));
  }
  __call(){
    this.success(DEFULT_AUTO_REPLY);
  }
}
  • 登录你的微信服务号,将微信开发者的接口URL配置为:
http://your_hostname/wechat

this.success 支持返回所有 node-webot/wechat 支持的格式。

License

MIT