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

egg-wxauth

v1.0.1

Published

an egg.js plugin for `weixin` Auth2.

Downloads

9

Readme

egg-wxauth

this is an plugin for weixin Auth2.

Documention

1.install

in your command line, type npm install egg-wxauth -S

  npm install egg-wxauth -S

2.update config

in egg project, find your config directory, then do like below

config/plugin.js

// make `wxauth` plugin enabled
exports.wxauth = {
  enabled: true,
  package: 'egg-wxauth',
}

config/config.default.js

config.wxauth = {
  appid: 'appid', // your appid
  appsecret: 'appsecret', // your appsecret
  // scope: 'snsapi_base', 'snsapi_base' default
}

3. Use as serveice

after 1 && 2 steps, it is auto injected into egg context already.then you can use this.ctx.service.wxauth to get methods what you want.

your service or controller.js

'use strict'

const Controller = require('egg').Controller

class HomeController extends Controller {
  * index() {
    // use egg-session(you can do this depend on your project)
    if (this.ctx.session.user) {
      // if user logged, then redirect to  your `loggin url`(http://egg.inrice.top/main)
      // `http://egg.inrice.top/main` exposed to user.
      this.ctx.redirect('http://egg.inrice.top/main')
    } else {
      // redirect url(use for getting the callback by weixin)
      this.ctx.service.wxauth.getCode('http://egg.inrice.top/auth?')
    }
  }
  // if weixin return a request, it will be enter `auth` methods that you defined.
  * auth() {
    const userData = yield this.ctx.service.wxauth.getUserInfo()
    if (!this.ctx.session.user) {
      this.ctx.session.user = userData
    }
    this.ctx.redirect('http://egg.inrice.top/main')
  }
  * main() {
    this.ctx.body = 'loggin success, this is your loggin url'
  }
}

module.exports = HomeController

4.API

  • getCode (redirectUrl)

This is a method for sending authorization requests to WeChat... After waiting for user action (if the scope is silent authorization to jump to redirectUrl), WeChat sends a get request to our redirectUrl.

  • getAccessToken()

This is a method for getting access_token and openid etc.like below

see detail

{
 "access_token":"ACCESS_TOKEN",
 "expires_in":7200,
 "refresh_token":"REFRESH_TOKEN",
 "openid":"OPENID",
 "scope":"SCOPE"
}
  • getUserInfo(),

This i a method for getting UseInfo when scope is snsapi_userinfo(otherwise, you don't need to use this method), see detail

when scope is snsapi_userinfo

{
 "openid":" OPENID",
 " nickname": "Mr.Right",
 "sex":"1",
 "province":"PROVINCE",
 "city": "CITY",
 "country":"COUNTRY",
 "headimgurl":"http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/46",
"privilege":[ "PRIVILEGE1" "PRIVILEGE2"],
 "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"
}