UNPKG

@shencom/api

Version:
88 lines (75 loc) 2.95 kB
import { getInitializedApiConfig } from '../config'; import { unToken } from '../utils/utils'; import type { ResIlhOauthLogin } from './uaa'; interface ResYzyGetAuthUrl { code?: string; /** 授权后重定向地址 */ redirectUri: string; accessToken?: string; refreshToken?: string; } export interface ResYzyToken { accessToken: string; refreshToken: string; expiresIn: number; } /** * 粤政易-获取粤政易授权链接 * @param {ResYzyGetAuthUrl} 授权配置 * @return {string} 授权重定向 uri */ export const ApiYzyGetAuthUrl = (body: ResYzyGetAuthUrl, headers?: Record<string, any>) => { const { url, http } = getInitializedApiConfig(); const api = `${url}/service-uaa/yzy/auth/url`; return http.post<string>(api, body, unToken(headers)); }; /** * 粤政易-通过授权 code 获取 access_token * @param {string} 粤政易重定向拼接的 code 参数 * @return {ResYzyToken} 粤政易用户 access_token */ export const ApiYzyCodeAuth = (code: string, headers?: Record<string, any>) => { const { url, http } = getInitializedApiConfig(); const api = `${url}/service-uaa/yzy/auth/gettoken`; return http.post<ResYzyToken>(api, { code }, unToken(headers)); }; /** * 粤政易-根据access_token验证登陆状态是否有效 * @param {string} 粤政易 accessToken * @return {boolean} 有效-true,无效-errcode(5000) */ export const ApiYzyAuthVerify = (accessToken: string, headers?: Record<string, any>) => { const { url, http } = getInitializedApiConfig(); const api = `${url}/service-uaa/yzy/auth/verify`; return http.post<boolean>(api, { accessToken }, unToken(headers)); }; /** * 粤政易-通过refresh_token置换新的access_toke * @param {string} 粤政易授权一起返回的 refresh_token * @return {ResYzyToken} 粤政易用户 access_token */ export const ApiYzyRefreshToken = (refreshToken: string, headers?: Record<string, any>) => { const { url, http } = getInitializedApiConfig(); const api = `${url}/service-uaa/yzy/auth/exchange`; return http.post<Omit<ResYzyToken, 'refreshToken'>>(api, { refreshToken }, unToken(headers)); }; /** * 粤政易-通过access_token获取用户信息 * @param {string} 粤政易 accessToken * @return {ResIlhOauthLogin} Oauth 授权的用户信息 */ export const ApiYzyLogin = (accessToken: string, headers?: Record<string, any>) => { const { url, http } = getInitializedApiConfig(); const api = `${url}/service-uaa/yzy/auth/login`; return http.post<ResIlhOauthLogin>(api, { accessToken }, unToken(headers)); }; /** * 粤政易-退出登录 * @param {string} 粤政易 accessToken * @return {string} 粤政易退出登录的重定向 uri */ export const ApiYzyLogout = (accessToken: string, headers?: Record<string, any>) => { const { url, http } = getInitializedApiConfig(); const api = `${url}/service-uaa/yzy/auth/logout`; return http.post<string>(api, { accessToken }, { headers }); };