import * as util from 'util' ; import * as urlencode from 'urlencode' ; import { HttpKit } from '@tnwx/kits' ; import { AccessToken , QyAccessTokenApi , OpenCpAccessTokenApi , AccessTokenType } from '@tnwx/accesstoken' ; author Javen
 *  copyright description export class OpenCpOauthApi { private static authorizeUrl : string = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect' ; private static qrConnectUrl : string = 'https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect?appid=%s&redirect_uri=%s&state=%s&usertype=%s' ; param suiteId param redirectUri param scope param state public static getAuthorizeUrl ( suiteId , redirectUri , scope , state ? ) { return util . format ( this . authorizeUrl , suiteId , urlencode . encode ( redirectUri ) , scope , state ) ; } param corpId param redirectUri param state param userType public static getQrConnect ( corpId , redirectUri , state ? , userType ? ) { return util . format ( this . qrConnectUrl , corpId , urlencode . encode ( redirectUri ) , state , userType ) ; } private static getUserInfoUrl : string = 'https://qyapi.weixin.qq.com/cgi-bin/service/getuserinfo3rd?suite_access_token=%s&code=%s' ; param code public static async getUserInfo ( code ) { let accessToken = await OpenCpAccessTokenApi . getAccessToken ( AccessTokenType . SUITE_TOKEN ) ; let url = util . format ( this . getUserInfoUrl , accessToken . getAccessToken , code ) ; return HttpKit . getHttpDelegate . httpGet ( url ) ; } private static getUserDetailUrl : string = 'https://qyapi.weixin.qq.com/cgi-bin/service/getuserdetail3rd?suite_access_token=%s' ; param userTicket public static async getUserDetail ( userTicket ) { let accessToken = await OpenCpAccessTokenApi . getAccessToken ( AccessTokenType . SUITE_TOKEN ) ; let url = util . format ( this . getUserDetailUrl , accessToken . getAccessToken ) ; return HttpKit . getHttpDelegate . httpPost ( url , JSON . stringify ( { user_ticket : userTicket } ) ) ; } private static getLoginInfoUrl : string = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_login_info?access_token=%s' ; param authCode public static async getLoginInfo ( authCode ) { let accessToken = await OpenCpAccessTokenApi . getAccessToken ( AccessTokenType . PROVIDER_TOKEN ) ; let url = util . format ( this . getLoginInfoUrl , accessToken . getAccessToken ) ; return HttpKit . getHttpDelegate . httpPost ( url , JSON . stringify ( { auth_code : authCode } ) ) ; } }