|
@@ -15,6 +15,8 @@ from common import security
|
|
from datetime import timedelta
|
|
from datetime import timedelta
|
|
from common.security import valid_access_token
|
|
from common.security import valid_access_token
|
|
from common.auth_user import *
|
|
from common.auth_user import *
|
|
|
|
+from common import YzyApi
|
|
|
|
+from models import *
|
|
|
|
|
|
router = APIRouter()
|
|
router = APIRouter()
|
|
|
|
|
|
@@ -204,4 +206,68 @@ async def logout(
|
|
return {
|
|
return {
|
|
"code": 200,
|
|
"code": 200,
|
|
"msg": "退出成功"
|
|
"msg": "退出成功"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+@router.post('/yzy/callback')
|
|
|
|
+async def yzy(
|
|
|
|
+ request: Request,
|
|
|
|
+ db: Session = Depends(get_db),
|
|
|
|
+ data: dict = Depends(remove_xss_json)
|
|
|
|
+):
|
|
|
|
+ code = data['code']
|
|
|
|
+ state = data['state']
|
|
|
|
+ state_str = base64.b64decode(state).decode('utf-8')
|
|
|
|
+ state_json = json.loads(state_str)
|
|
|
|
+ print(code, state_json)
|
|
|
|
+
|
|
|
|
+ if code != 'xxxxx':
|
|
|
|
+ resp = YzyApi.get_user_info(code)
|
|
|
|
+ if resp['errcode'] != 0:
|
|
|
|
+ return {
|
|
|
|
+ "code": 500,
|
|
|
|
+ "msg": "Code异常"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ user_id = resp['UserId']
|
|
|
|
+ else:
|
|
|
|
+ user_id = "eb4kehgy6wj4qn0jhx1dk6"
|
|
|
|
+
|
|
|
|
+ row = db.query(YzyOrgUserEntity).filter(YzyOrgUserEntity.userid == user_id).first()
|
|
|
|
+ if row is None:
|
|
|
|
+ return {
|
|
|
|
+ "code": 500,
|
|
|
|
+ "msg": "user_id异常"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ yzy_account = row.account
|
|
|
|
+ row = db.query(SysUser).filter(SysUser.yzy_account == yzy_account).first()
|
|
|
|
+ if row is None:
|
|
|
|
+ return {
|
|
|
|
+ "code": 500,
|
|
|
|
+ "msg": "用户不是本系统用户"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ user_id = str(row.user_id)
|
|
|
|
+
|
|
|
|
+ access_token_expires = timedelta(seconds = 7200)
|
|
|
|
+ access_token = security.create_access_token(
|
|
|
|
+ data={"sub": user_id}, expires_delta = access_token_expires
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ refresh_token_expires = timedelta(seconds = 7200)
|
|
|
|
+ refresh_token = security.create_access_token(
|
|
|
|
+ data={"sub": user_id}, expires_delta = refresh_token_expires
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ "code": 200,
|
|
|
|
+ "msg": "粤政易登录成功",
|
|
|
|
+ "data": {
|
|
|
|
+ "access_token": access_token,
|
|
|
|
+ "refresh_token": refresh_token,
|
|
|
|
+ "expire_in": 7200,
|
|
|
|
+ "refresh_expire_in": 7200,
|
|
|
|
+ "scope": "",
|
|
|
|
+ "redirect_url": state_json['redirect_url']
|
|
|
|
+ }
|
|
}
|
|
}
|