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 🙏

© 2026 – Pkg Stats / Ryan Hefner

wechat-promise

v1.0.7

Published

微信接口,promise方式调用

Readme

该版本是从我的正式项目迁移过来,在项目里已经可以运行,目前迁移后暂未测试,平时比较忙,如果有兴趣可以帮忙测试下,有问题发issue给我

#初始化

var wxp = require('wechat-promise');
var wx = new wxp.Wx(app_id, app_secret, encrypt_key);

##自定义并加入缓存 微信的access_token, js_ticket在正式生产环境中需要缓存起来,所以wechat-promise已内置自动缓存的调用,只需要自定义cache既可

cache的定义方法如下,以memcached为例


var memcached = new Memcahced(...),
    Promise = require('bluebird');
var Cache = (function() {
  function Cache(cache) {
    this.cache = cache;
    Promise.promisifyAll(this.cache);
  }

  Cache.prototype.get = function(key) {
    return this.cache.getAsync(key);
  };

  Cache.prototype.set = function(key, value, expire) {
    return this.cache.setAsync(key, val, expire).then(function() {
      return Promise.resolve(val);
    });
  };

  return Cache;

})();

var cache = new Cache(memcached);
var wx = new wxp.Wx(app_id, app_secret, encrypt_key, cache);

##启用支付功能 添加商户id和证书地址

商户id和证书均可在微信商户平台获取


var wx = new wxp.Wx(app_id, app_secret, encrypt_key, cache, mch_id, cert_path);

#接口操作 ##请边参考微信接口的文档边对照使用

###获取登录授权码链接 auth_url

微信浏览器跳转到该链接后会跳转回redirect_url,并在链接上加上授权码code,通过code可进行登录操作


var url = wx.auth_url(redirect_url, state, scope);

###登录 login

登录微信账号


wx.login(code).then(function(data){
  console.log(data.access_token);
  console.log(data.openid);
});

###获取用户信息 user_info

登录后获取用户信息,昵称头像等


wx.user_info(token, openid).then(function(data){
  console.log(data)
});

###获取access_token access_token

用于其他接口调用的token,此token不同于登陆的access_token,请勿混淆

该token支持缓存,实际应用中也必须缓存,程序中已内置,但缓存方法需要自定义,请参考‘自定义并加入缓存’


wx.access_token().then(function(token){
  console.log(token);
});

###自定义菜单 create_menu

用于自定义进入公众号时底部菜单,使用该功能必须开启服务器配置

该方法的json参数请参照微信文档


wx.create_menu(json).then(function(data){
  console.log(data);
});

###获取js接口签名 js_signature

用于调用微信jssdk


wx.js_signature(url).then(function(data){
    console.log(data);
});

###模板接口 temp_info

推送给指定用户信息


wx.temp_info(openid, tid, data, url).then(function(data){
  console.log(data);
});

###下载媒体资源 download

下载媒体资源,请注意媒体资源过期时间


wx.download(media_id).then(function(data){
  console.log(data);
});

待补充支付部分