1 Star 1 Fork 0

ManiacRaTT/HospitalFrontDesk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
view_api.py 2.53 KB
一键复制 编辑 原始数据 按行查看 历史
ManiacRaTT 提交于 2023-01-11 12:03 . Initial commit
# 公众号授权自动登录登录接口
import json
import uuid
from datetime import datetime
import requests
import ctrl_base
from ctrl_api import ReturnCode
from util import utils
from util.base_config import g_version
from util.define import g_bs_capacity_info, app_id, WXsecret
from database.xMySQL_1 import objects
def get_user_info(js_code):
req_params = {
"appid": app_id, # 小程序的 ID
"secret": WXsecret, # 小程序的 secret
"js_code": js_code,
"grant_type": 'authorization_code'
}
req_result = requests.get('https://api.weixin.qq.com/sns/jscode2session',
params=req_params, timeout=3, verify=False)
class WXlogin(ctrl_base.BaseHandler):
async def post(self):
# req_data = json.loads(self.request.body)
#
# js_code = req_data.get('js_code')
#
# # 这里是换取用户的信息
# user_info = get_user_info(js_code=js_code)
# TEST
desc=''
id = '25255252'
role = None
name = self.get_json_argument("name")
openid = self.get_json_argument("openid")
session_key = self.get_json_argument("session_key")
userid = self.get_json_argument("userid")
# openid = user_info['openid']
# session_key = user_info['session_key']
# desc = user_info['desc']
# name = user_info['name']
# id = ''
# role = ''
# user_uuid = uuid.uuid4()
# # 用来维护用户的登录态
# User.save_user_session(
# openid=openid,
# session_key=session_key,
# user_uuid=user_uuid
# )
self.set_secure_cookie('username',name)
self.set_secure_cookie('openid',openid)
self.set_secure_cookie('session_key',session_key)
self.set_secure_cookie('userid',userid)
# 存储用户信息
# await self.application.objects.get_or_create(VeteransUser,
# name=name,
# id=id,
# desc=desc,
# role=role,
# openid=openid)
await self.finish(ReturnCode(200, flag=True))
return
class WXlogout(ctrl_base.BaseHandler):
# @is_login
async def get(self):
self.clear_cookie("openid","session_key","username","userid")
await self.finish(ReturnCode(200,flag=True,data='log out Successfully'))
return
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/maniacratt/HospitalFrontDesk.git
git@gitee.com:maniacratt/HospitalFrontDesk.git
maniacratt
HospitalFrontDesk
HospitalFrontDesk
master

搜索帮助