代码拉取完成,页面将自动刷新
# 公众号授权自动登录登录接口
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。