from apiflask import APIBlueprint from app import rpc from app.api.v1.exception.auth import WechatLoginError, AuthError from app.api.v1.schema.auth import WechatLoginIn, WechatLoginOut, RefreshTokenIn, RefreshTokenOut auth = APIBlueprint('auth', __name__) @auth.post('/wechat_login') @auth.input(WechatLoginIn) @auth.output(WechatLoginOut) @auth.doc(summary='微信登录', description='微信登录') def wechat_login(json_data): try: result = rpc.admin.wechat_login(json_data['code']) except Exception as e: raise WechatLoginError(extra_data={'error_docs': str(e)}) return result @auth.get('/refresh_token') @auth.input(RefreshTokenIn, location='query') @auth.output(RefreshTokenOut) @auth.doc(summary='刷新 Token', description='刷新 Token') def refresh_token(query_data): try: result = rpc.admin.refresh_token(query_data['refresh_token']) except Exception as e: raise AuthError(extra_data={'error_docs': str(e)}) return result