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

weixin-node

v1.0.0

Published

微信(wechat)签名等后端接口封装(nodejs)

Downloads

3

Readme

weixin-node

微信(wechat)签名等后端接口封装(nodejs)

USAGE

  • getToken

通过 appidsecret 获取 access_token

+ **appid**
+ **secret**
+ expires_in 强制指定缓存时间(默认缓存 7200 秒)
+ update 是否强制服务端更新缓存

return

{ access_token: 'yqtqCpfmJOnbJM6i2_JeWK_-r28jvIgO0Pzk66IXpFXRKVqrrDoqCXrOE4G1wgGiSERMKQ2qTH7l9xwDD1O--bxxLh8ahXbgrhx67o4qUZ0',
  expires_in: 7200 }
  • getTicket

通过 access_token 获取 ticket

+ **access_token**
+ expires_in 强制指定缓存时间(默认缓存 7200 秒)
+ update 是否强制服务端更新缓存

return

{ errcode: 0,
  errmsg: 'ok',
  ticket: 'sM4AOVdWfPE4DxkXGEs8VDsWI7B-faDW7RPMNI7CBMYBwrOO_HqeX3cazP-FRv1zclArJLDw2_0WQA604Sc-GA',
  expires_in: 7200 }
  • sign

微信官方签名算法

+ **ticket**
+ **url**

return

{ jsapi_ticket: 'sM4AOVdWfPE4DxkXGEs8VDsWI7B-faDW7RPMNI7CBMYBwrOO_HqeX3cazP-FRv1zclArJLDw2_0WQA604Sc-GA',
  nonceStr: '564m6gkt2dbwqao',
  timestamp: '1426509920',
  url: 'http://weixin.com',
  signature: 'fd0079efb712acfdcc0a398b85c74102f1cd1ef1' }

example

simple

var weixin = require('.')
var co = require('co')

co(function *(){
  var token = yield weixin.getToken('wx0e9ccf43c71f8bab', 'd97eb68dc872c9c940d96a1e55c2d7a3')
  console.log('token:', token)

  var ticket = yield weixin.getTicket(token.access_token)
  console.log('ticket:', ticket)

  var sign = yield weixin.sign(ticket.ticket, 'http://weixin.com')
  console.log('sign:', sign)
})

sign a url, just need appid + secret

function *() {
  var query = this.query
  var token = yield weixin.getToken(query.appid, query.secret, query.expires_in, query.update)

  if(token.errcode) return this.body = token

  var ticket = yield weixin.getTicket(token.access_token)

  if(ticket.errcode !== 0) return this.body = ticket

  var result = weixin.sign(ticket, query.url)
  result.appId = query.appid
  this.body = result
}