-
Notifications
You must be signed in to change notification settings - Fork 96
API v1.x
Welcome to the wechat-jssdk API wiki!
For v2.x, checkout the API-2.x
###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()
-
verifySignature, [query {object}], JSON object containing all the verification properties, including:timestamp,nonce, to generate the signature to which to compare withquery.signature. -
getAccessToken, callback {function}, thecallbackwill be called after getting the accessToken from wechat server. -
getWechatTicket, [accessToken {string}, callback {function}], pass theaccessTokento get thejsticket. -
updateAccessTokenOrTicketGlobally, [token {string}, ticket{string}, callback {function}], update global token and ticket, it will update every 2 hours, usually we don't need to update it manually. -
getNewTokenAndTicket, [callback {function}, force {boolean}], get new global token and ticket, passforce:trueto force getting the info, otherwise, it will only allow to get this at most 5 times within 2 hours. -
prepareNewSignature, [callback {function}], 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}, callback {function}],infoinclude all the signature information for the specific url. -
updateSignatureByUrl, [url {string}, info {object}, callback {function}], update the signature by existing url. -
getSignatureByURL, [url {string}, callback {function}], get the signature form cache or create a new one, usually this is the most used api. -
createNewSignature, [url {string}, callback {function}, force {boolean}], create a new signature now. -
getTokenFromCache, [url {string}], just get url signature from cache.
Usually
getSignatureByURLis the only two apis you need to call.
###OAuth APIs
Call api: wx.oauth.fun()
-
getUserBaseInfo, [code {string}, callback {function}], get wechat user base info,codeparam is included in the wechat redirect url. -
getUserInfo, [code {string}, callback {function}, 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 returned together -
getUserInfoByOptions, [options {object}], same as above, instead, put all the options inside one object:{ code: '', returnToken: false, force: false, callback: function(){} } -
getOAuthAccessToken, [code {string}, callback {function}], get OAuth access token. -
isAccessTokenValid, [callback {function}], check if the cached token is expired. -
getCachedTokenInfo, return cached access_token, refresh_token info, etc... -
refreshAccessToken, [callback {function}], refresh the access token manually
Usually
getUserBaseInfo,getUserInfo,getUserInfoByOptionsare the only apis you need