92 lines
2.2 KiB
Python
92 lines
2.2 KiB
Python
# 将lib里边的文件加到路由中
|
|
import sys
|
|
sys.path.append('./lib')
|
|
import os
|
|
from flask import Flask, escape, url_for, request, render_template, redirect, abort, send_from_directory, Response
|
|
from allFunction import flash, delQR, addQR, genQR, manageLogin
|
|
|
|
app = Flask(__name__)
|
|
|
|
# 引入跨域访问处理模块
|
|
from flask_cors import CORS
|
|
# 取消跨域访问限制,方便本地测试 注册CORS, "/*" 允许访问所有api
|
|
CORS(app, resources=r'/*')
|
|
|
|
# 用户小程序登录
|
|
@app.route('/login',methods=['POST'])
|
|
def login():
|
|
res = manageLogin(request, 1)
|
|
if(res):
|
|
return res
|
|
else:
|
|
abort(400)
|
|
|
|
# 小程序刷新用户信息
|
|
@app.route('/reflash',methods=['POST'])
|
|
def reflash():
|
|
res = flash(request)
|
|
if(res):
|
|
return res
|
|
else:
|
|
abort(400)
|
|
|
|
# 用户删除二维码
|
|
@app.route('/del',methods=['POST'])
|
|
def delQRCode():
|
|
res = delQR(request)
|
|
if(res):
|
|
return res
|
|
else:
|
|
abort(400)
|
|
|
|
# 用户添加二维码
|
|
@app.route('/add',methods=['POST'])
|
|
def addQRCode():
|
|
res = addQR(request)
|
|
if(res):
|
|
return res
|
|
else:
|
|
abort(400)
|
|
|
|
# 生成二维码
|
|
@app.route('/generate',methods=['GET'])
|
|
def generate():
|
|
res = genQR(request.args.get("text"))
|
|
if(res):
|
|
return Response(res, mimetype='image/png')
|
|
else:
|
|
abort(400)
|
|
|
|
# 控制小程序是否显示“最佳案例”
|
|
@app.route('/config', methods=['post'])
|
|
def config():
|
|
return {'errcode': 200, 'showBest': 'true'}
|
|
|
|
# 图标
|
|
@app.route('/favicon.ico')
|
|
def favicon():
|
|
return send_from_directory(os.path.join(app.root_path, 'static'),'favicon.ico', mimetype='image/vnd.microsoft.icon')
|
|
|
|
@app.route('/<path>')
|
|
def notDefind():
|
|
abort(404)
|
|
|
|
# 二维码查询失败重定向, 404
|
|
@app.errorhandler(404)
|
|
def page_not_found(e):
|
|
return render_template('404.html'), 404
|
|
|
|
@app.errorhandler(400)
|
|
def page_not_found(e):
|
|
return render_template('400.html'), 400
|
|
|
|
@app.errorhandler(500)
|
|
def page_not_found(e):
|
|
return render_template('500.html'), 500
|
|
|
|
@app.errorhandler(410)
|
|
def page_not_found(e):
|
|
return render_template('410.html'), 500
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host="0.0.0.0", debug=True, port="80") |