-
Notifications
You must be signed in to change notification settings - Fork 96
API
jason edited this page Dec 23, 2016
·
16 revisions
Welcome to the wechat-jssdk API wiki for V3!
//get your wechat info from wechat dashboard const wechatInfo = { "wechatRedirectUrl": "http://yourdomain.com/wechat/oauth-callback", "wechatToken": "aaa", // used to pass the verification when save wechat config on wechat dashboard "appId": "bbb", //required for jssdk and oauth usage "appSecret": "ccc" //required } const WeChat = require('wechat-jssdk'); const wx = new WeChat(wechatInfo);
Default Api usage: wx.jssdk.fun(params...).then(resolveFn, rejectFn), the wx.jssdk is a reference to new JSSDK(options) instance internally,
Instantiate your own JSSDK instance:
const JSSDK = WeChat.JSSDK; const jssdk = new JSSDK(wechatInfo); jssdk.fun(params...).then(resolveFn, rejectFn);
- @constructor
Wechat.JSSDK, usenew JSSDK(options)to instantiate JSSDK instance, which is automatically called when you donew WeChat(options)above. -
verifySignature, [query {object}], JSON object containing all the verification properties, including:timestamp,nonce, to generate the signature to compare withquery.signature, you need to call this api when you first input the wechat config in wechat dashboard. -
getSignature, [url {string}, forceNewSignature {boolean}], get the signature from cache or create a new one, usually this is the most used api. IfforceNewSignatureis true, generate a new signature instead of getting it from cache. -
jssdk.store, the Store instance for the current jssdk instance.
Other apis are used internally, usually you don't need to call them directly...
Default Api usage: wx.oauth.fun(params...).then(resolveFn, rejectFn), the wx.oauth is a reference to new OAuth(options) instance internally,
Instantiate your own OAuth instance:
const OAuth = WeChat.OAuth; const oauth = new OAuth(wechatInfo); oauth.fun(params...).then(resolveFn, rejectFn);
- @constructor
Wechat.OAuth, usenew OAuth(options)to instantiate OAuth instance, which is automatically called when you donew WeChat(options)above. -
generateOAuthUrl, [redirectUrl {string}, scope {string}, state {string}], customize your own callback url, pass your customscopeandstate(defaultuserAuth) option to original wechat api. The defaultwx.oauth.snsUserInfoUrl(scope:snsapi_userinfo) andwx.oauth.snsUserBaseUrl(scope:snsapi_base) is generated with thewechatRedirectUrlwhen you pass tonew Wechat(options). -
getUserInfo, [code {string}, key {string}, returnToken {boolean}], get wechat user info, including nickname, openid, avatar, etc..., ifcodeis a false value('', null, etc...), it will get the access token from cache based on thekeyparameter, thekey(default use theopenidfrom the userinfo result) is used as a unique key for access token info to be stored in Stores, which can be retrieved next time directly from cache instead of getting thecodeagain, ifreturnTokenis true, the result of the token api will be merged with the user profile, and be returned together. -
getUserBaseInfo, [code {string}, key {string}], get wechat user base info,codeparam is included in the wechat redirect url. -
oauth.store, the Store instance for the current oauth instance.