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

wxe-auth-express

v0.5.0

Published

用于微信企业号登录的express中间件

Readme

wxe-auth-express

express middleware, 用它可以实现微信企业号的登录

API

signin

此中间件用的功能包括:

  1. 发起登录认证请求,详见微信企业号文档
  2. 接收返回的code,并用code获取UserId

参数

wxapi

必须的。 由 wxent-api-redis生成的微信企业号接口API,将被调用的接口包括:

  • getAuthorizeURL 用于构造认证请求URL
  • getUserIdByCode 用于用code获取UserId
cookieNameForUserId

登录后需要将(加密的)UserId存储到cookie中,此处用于指定cookie的名字,默认为userId

callbackUrl

认证服务器返回code时使用的回调url,默认可以由系统自己构造一个当前url

getme

用户读取当前用户的登录信息

参数

cookieNameForUserId

登录后需要将(加密的)UserId存储到cookie中,此处用于指定cookie的名字,默认为userId

getUserId

获取当前用户的id。 成功获取时,将结果存放在req.user.userid,失败时,返回响应:{ ret:-1 }

getUser

在使用此API时,必须先调用getUserId,或设置好req.user.userid的值。 获取当前用户在微信企业号的详细信息。 成功获取时,将结果存放在req.user中,数据结构见微信企业号文档; 失败时,返回响应:{ ret: -1 }

参数

wxapi

必须的。 由 wxent-api-redis生成的微信企业号接口API,将被调用的接口包括:

  • getUser 用于获取用户数据

Build

使用npm run build

示例

Express处理程序

import { Router } from 'express';
import API from 'wxent-api-redis';
import { signin, getme } from 'wxe-auth-express';

const wxapi = API(corpId, secret, agentId, redishost, redisport);
const router = new Router();

const host = 'wx.example.com';

router.get('/signin', signin({
  wxapi: wxapi,
  cookieNameForUserId: 'userId',
  callbackUrl: `http://${host}/signin`
}));

// 获取当前登录用户信息
router.get('/me', getme('userId'));

客户端

let getMe = async() => {
  // fetch的时候必须带上cookie
  let meRes = await fetch(`/me`, {
    credentials: 'same-origin'
  });
  let result = await meRes.json();

  // 获取到用户信息,用户已经登录
  if(result.ret === 0){
    return Promise.resolve(result.data);
  }
    // 不能获取到用户信息,用户未登录
    else {
    return Promise.reject(await result.msg);
  }
}

// 检查用户是否已经登录
getMe().then(userId => {
  // 用户已经登录
  // ...
}).catch(e => {
  // 用户还未登录,转到登录页面
  // 此时必须带上redirect_uri参数,这样才知道认证之后要返回哪个页面
  window.location = `/api/signup/signin?redirect_uri=${window.location.href}`;
})

在本地进行调试

在本地进行调试需要注意的问题:

  1. 在本地进行调试需要使用微信Web开发者工具
  2. 需要修改本地hosts文件,将可信域名绑定到