(Non-official) Wechat mini program (a.k.a. 微信小程序) auth helper for Node.js.
yarn add wxapp-auth
import WxappAuth from 'wxapp-auth';
(async function main() {
const wechatAuth = new WxappAuth('<APP_ID>', '<APP_SECRET>');
const userInfo = await wechatAuth.getUserInfo({
code: '<LOGIN_CODE>'
rawData: '<RAW_DATA>',
signature: '<SIGNATURE>',
});
}());
new WxappAuth(appId, appSecret);
Create a WxappAuth
instance.
appId
<String>: Wechat app id, requiredappSecret
<String>: Wechat app secret, required
wxappAuth.getUserInfo(params);
- Params <Object>
code
<String>:code
from wechat mini programwx.login()
sessionKey
<String>: Session key from getSession(params)rawData
<String>:rawData
from wechat mini programwx.getUserInfo()
signature
<String>:signature
from wechat mini programwx.getUserInfo()
encryptedData
<String>:encryptedData
from wechat mini programwx.getUserInfo()
iv
<String>:iv
from wechat mini programwx.getUserInfo()
- One of
code
orsessionKey
is required - One of
rawData
andsignature
, orencryptedData
andiv
are required
Promise of UserInfo object
wxappAuth.getSession(params);
- Params <Object>
code
<String>:code
from wechat mini programwx.login()
, required
Promise of object containing sessionKey
, openid
, and optional unionid
MIT