• 大小: 7KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-06-17
  • 语言: Python
  • 标签:

资源简介

weixin_login 微信网页授权实现扫码登录

资源截图

代码片段和文件信息

from flask import Flask request session send_file
import redis random string

app = Flask(__name__)
app.config.update(dict(
DEBUG=False
SECRET_KEY=‘DFWL0G69HUHdeJN‘
))
app.config[‘POOL‘] = redis.ConnectionPool(host=‘127.0.0.1‘ port=6379)


@app.route(‘/‘)
def index():
    return send_file(‘page.html‘)

@app.route(‘/state‘ methods=[‘GET‘])
def getState():
r = redis.Redis(connection_pool=app.config[‘POOL‘])
if session.get(‘state‘) and r.get(session[‘state‘]):
return session[‘state‘]
state = ‘‘.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8))
r.set(state ‘none‘ ex=2*60)
session[‘state‘] = state
return state

@app.route(‘/result‘ methods=[‘GET‘])
def getResult():
r = redis.Redis(connection_pool=app.config[‘POOL‘])
if session.get(‘state‘) and r.get(session[‘state‘]) == ‘success‘:
return ‘success‘
return ‘failed‘

@app.route(‘/success‘ methods=[‘GET‘])
def sendCode():
state = request.args.get(‘state‘)
code = request.args.get(‘code‘)
r = redis.Redis(connection_pool=app.config[‘POOL‘])
if r.get(state):
r.set(state ‘success‘)
return code
return ‘failed‘


if __name__ == ‘__main__‘:
app.run()



 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-05-31 13:50  weixin_login-master\
     文件         917  2017-05-31 13:50  weixin_login-master\README.md
     文件         874  2017-05-31 13:50  weixin_login-master\page.html
     文件        1169  2017-05-31 13:50  weixin_login-master\server.py
     目录           0  2017-05-31 13:50  weixin_login-master\static\
     文件       13995  2017-05-31 13:50  weixin_login-master\static\jquery.qrcode.min.js

评论

共有 条评论