-
Notifications
You must be signed in to change notification settings - Fork 93
API v2.x
Welcome to the wechat-jssdk API wiki!
###Initialize
//get your wechat info from wechat dashboard
var wechatInfo = {
"wechatRedirectUrl": "http://yourdomain.com/wechat/oauth-callback",
"wechatToken": "aaa",
"appId": "bbb",
"appSecret": "ccc"
}
var wx = require('wechat-jssdk');
wx.initialize(wechatInfo);
###JS-SDK APIs
Call api: wx.jssdk.fun(params...).then(resolveFn, rejectFn)
-
getSignatureByURL
, [url {string}, forceNewSignature {boolean}], get the signature form cache or create a new one, usually this is the most used api. -
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. -
getAccessToken
, get access token before getting ticket. -
getWechatTicket
, [accessToken {string}], pass theaccessToken
to get thejsticket
. -
updateAccessTokenOrTicketGlobally
, [token {string}, ticket{string}], update global token and ticket, it will update every 2 hours, usually we don't need to update it manually. -
getNewTokenAndTicket
, [force {boolean}], get new global token and ticket, passforce:true
to force getting the info, otherwise, it will only allow to get this at most 5 times within 2 hours. -
prepareNewSignature
, get or generate global token info for signature generating process. -
genSignature
, [ticket {string}, url {string}, token {string}], generate the url signature with the provided info. -
saveNewSignature
, [info {object}],info
include all the signature information for the specific url. -
updateSignatureByUrl
, [url {string}, info {object}], update the signature for existing url. -
createNewSignature
, [url {string}], create a new signature now. -
getTokenFromCache
, [url {string}], just get url signature from cache. -
getCachedGlobalToken
, get global token/ticket info from cache -
getCachedUrlSignature
, get all cached urls signature info
Usually
getSignatureByURL
is the only api you need to call.
###OAuth APIs
Call api: wx.oauth.fun(params...).then(resolveFn, rejectFn)
-
generateOauthUrl
, [customUrl {string}, isBaseUrl {boolean}], customize your own callback url,isBaseUrl
to indicate thescope
option in original wechat api. -
generateOauthUrlByScope
, [customUrl {string}, scope {string}], customize your own callback url, pass your customscope
option to original wechat api. -
getUserBaseInfo
, [code {string}], get wechat user base info,code
param is included in the wechat redirect url. -
getUserInfo
, [code {string}, forceTokenUpdate {boolean}, returnToken {boolean}], get wechat user info, including nickname, openid, avatar, etc..., if forceTokenUpdate is true, it will get the token from wechat server first, if return Token is true, the result of the token api will be merged with the user profile, and be returned together -
getUserInfoByOptions
, [options {object}], same as above, instead, put all the options inside one object:{ code: '', returnToken: false, force: false }
-
getOAuthAccessToken
, [code {string}], get OAuth access token. -
isAccessTokenValid
, check if the cached token is expired. -
refreshAccessToken
, refresh the access token manually
Usually
generateOauthUrl
,getUserBaseInfo
,getUserInfo
, are the only apis you need