import * as util from 'util' ; import * as urlencode from 'urlencode' ; import { ApiConfigKit , AccessToken , OpenComponentAccessTokenApi } from '@tnwx/accesstoken' ; import { HttpKit } from '@tnwx/kits' ; import { ScopeEnum , Lang } from '@tnwx/commons' ; author Javen
 *  copyright description export class OpenMpSnsAccessTokenApi { private static authorizeUrl : string = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&component_appid=%s' ; private static accessTokenUrl : string = 'https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=%s&code=%s&grant_type=authorization_code&component_appid=%s&component_access_token=%s' ; private static refreshTokenUrl : string = 'https://api.weixin.qq.com/sns/oauth2/component/refresh_token?appid=%s&grant_type=refresh_token&component_appid=%s&component_access_token=%s&refresh_token=%s' ; private static userInfoUrl : string = 'https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=%s' ; param appId param redirectUri param scope param state public static getAuthorizeUrl ( appId , redirectUri , scope , state ? ) { let url = util . format ( this . authorizeUrl , appId , urlencode ( redirectUri ) , scope , ApiConfigKit . getApiConfig . getAppId ) ; if ( state ) { url = url + '&state=' + state ; } return url + '#wechat_redirect' ; } param code public static async getSnsAccessToken ( code , appId ) { let accessToken = await OpenComponentAccessTokenApi . getAccessToken ( ) ; let url = util . format ( this . accessTokenUrl , appId , code , ApiConfigKit . getApiConfig . getAppId , accessToken . getAccessToken ) ; return HttpKit . getHttpDelegate . httpGet ( url ) ; } param refreshToken public static async refreshAccessToken ( appId , refreshToken ) { let accessToken = await OpenComponentAccessTokenApi . getAccessToken ( ) ; let url = util . format ( this . refreshTokenUrl , appId , ApiConfigKit . getApiConfig . getAppId , accessToken . getAccessToken , refreshToken ) ; return HttpKit . getHttpDelegate . httpGet ( url ) ; } param accessToken param openId param lang public static async getUserInfo ( accessToken , openId , lang ) { let url = util . format ( this . userInfoUrl , accessToken , openId , lang ) ; return HttpKit . getHttpDelegate . httpGet ( url ) ; } }