Skip to content

yourenyouyu/node-wechat-oauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-wechat-oauth

Wechat Official Document Repository Address

Install Module

 npm install node-wechat-oauth --save

Usage

instantiation object.

const  oauth = require('node-wechat-oauth');
const  client = oauth({
   openid:'',
   secret:''
});

Get Authorization Url

SNSAPI_BASE

client.getAuthUrl(redirect, 'snsapi_base');

SNSAPI_USERIFO

client.getAuthUrl(redirect, 'snsapi_userinfo');
please make http request redirect to the authorization url ;

SNSAPI_LOGIN

client.getQRCodeAuthUrl(redirect);

Get AccessToken

getAccessToken(code, function(error, result){
    console.log(error || result);
});

The result of access token request.

result:
{ 
     "access_token":"ACCESS_TOKEN",    
     "expires_in":7200,    
     "refresh_token":"REFRESH_TOKEN",    
     "openid":"OPENID",    
     "scope":"SCOPE" 
 } 

Get User Information

client.getUserInfo({
  access_token: 'ACCESS_TOKEN',
  openid: 'OPENID'
},function(error, result){
    console.log(error || result);
});

User information details

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

Refresh AccessToken

client.refreshToken(access_token, function(error, result){
    console.log(error, result);
});

Verify AccessToken

client.verifyToken(access_token,openid,function(error, result){
    console.log(error || result);
});

result of verify

valid
{ 
    "errcode":0,
    "errmsg":"ok"
}
invalid
{
    "errcode":40003,
    "errmsg":"invalid openid"
}

About

微信授权登陆模块

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published