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

wxchat

v0.0.8

Published

微信公共平台接口封装

Downloads

20

Readme

wxchat

可以使用微信菜单按钮只有2种情况: 服务者账号(公司) 订阅者账号,需要交300RMB,可以提高权限

安装

npm install wxchat

使用

调用及其验证Token,Token申请地址

var wxchat = require('wxchat')(token);

调用时处理

wxchat.middlewarify(req, res);
  • 验证token
  • 处理微信返回xml

text

wxchat.text(function(data){
	var message = {}
	// 发送文本信息后,需要给返回的内容
	wxchat.send(message);
});

image

wxchat.image(function(data){
	var message = {}
	// 发送信息后,需要给返回的内容
	wxchat.send(message);
});

voice

wxchat.voice(function(data){
	var message = {}
	// 发送信息后,需要给返回的内容
	wxchat.send(message);
});

location

wxchat.location(function(data){
	var message = {}
	// 发送信息后,需要给返回的内容
	wxchat.send(message);
});

link

wxchat.link(function(data){
	var message = {}
	// 发送信息后,需要给返回的内容
	wxchat.send(message);
});

subscribe

wxchat.subscribe(function(data){
	var message = {}
	// 关注时,返回的内容
	wxchat.send(message);
});

unsubscribe

wxchat.voice(function(data){
	var message = {}
	// 取消关注时,返回的内容
	wxchat.send(message);
});

click

这个比较特殊,需要有菜单时,才可以执行

wxchat.click(function(data){
	var message = {}
	// 点击菜单按钮时,返回的内容
	wxchat.send(message);
});

all

监听上面所有的事件

回复信息

必须是JSON

wxchat.send(message);

返回数据类型解释

{
	createTime: data.createTime,
	fromUsername: data.fromUsername,
	toUsername: data.toUsername,
	content: '前端分享,欢迎你~'
}

createTime/fromUsername/toUsername,是返回的数据中存在的,你也可以手动配置

content有如下几种类型:

  • 文本
{
	title: "标题",
	description: "描述",
	text: 'xxx'
}
  • 数组,需要遵守如下的格式
{
	title: "标题",
	description: "描述",
	pic: 'http://xxx',
	url: "http://xxx"
}
  • music
{
	title: "标题",
	description: "描述",
	// 普通质量的音乐
	url: 'http://xxx',
	// 质量比较高的链接(wifi环境优先使用)
	hqUrl: "http://xxx"
}
  • voice/image
{
	title: "标题",
	description: "描述",
	// 媒体文件的 id
    mediaId: xx
}
  • video
{
	title: "标题",
	description: "描述",
	// 媒体文件的 id
    mediaId: xx,
    // 视频消息缩略图的id
    thumbMediaId: xx
}

默认返回的数据

可以通过下面的代码来获取:

data.default.xxx

注意

data.default.FromUsernamedata.default.ToUsername 在回复时,请这样填写

{
	createTime: data.createTime,
	// 注意下面2项是反的,才是对的
	fromUsername: data.default.ToUsername,
	toUsername: data.default.FromUsername,
	content: '前端分享,欢迎你~'
}

示例

var http = require('http');
var wxchat = require('wxchat')(yourToken);

http.createServer(function (req, res) {
	wxchat.middlewarify(req, res);
	// 关注后,推送欢迎信息
	wxchat.subscribe(function(data){
		var msg = {
			createTime: data.createTime,
			fromUsername: data.fromUsername,
			toUsername: data.toUsername,
			content: '前端分享,欢迎你~'
		}
		wxchat.send(msg);
	});
	// 发来文本信息后,推送一条新闻
	wxchat.text(function(data){
		var msg = {
			msgType: 'news',
			createTime: data.createTime,
			fromUsername : data.fromUsername,
			toUsername : data.toUsername,
			content : [
				{
					title: "sublime自定义",
					description: "多年来,我已经用了很多的代码编辑器,从Windows上的“记事本”到Mac上的Espresso ,TextMate和Sublime Text。最终,一直使用Sublime Text 2,因为它是如此的简单易用,可定制的。",
					url: "http://liuqing.pw/2013/09/12/sublime-customizing-your-workflow.html"
				}
			]
		}
		wxchat.send(msg);
	});

}).listen(process.env.VCAP_APP_PORT || 3000);