114 lines
2.6 KiB
Python
114 lines
2.6 KiB
Python
import sys
|
||
sys.path.append('./lib')
|
||
|
||
import os
|
||
from flask import Flask, escape, url_for, request, render_template, redirect, abort, send_from_directory
|
||
from allFunction import manageLogin, findQR, flash, delQR, manageNotify, createOrder, checkOrder, addQR
|
||
|
||
app = Flask(__name__)
|
||
|
||
if __name__ == '__main__':
|
||
app.run()
|
||
|
||
# 用户小程序登录
|
||
@app.route('/login',methods=['POST'])
|
||
def login():
|
||
res = manageLogin(request)
|
||
if(res):
|
||
return res
|
||
else:
|
||
abort(400)
|
||
|
||
# # 用户扫描二维码
|
||
# @app.route('/qr',methods=['GET'])
|
||
# def qr():
|
||
# res = findQR(request)
|
||
# if(res):
|
||
# return render_template('qrcode.html',data = res)
|
||
# else:
|
||
# abort(410)
|
||
|
||
# 小程序刷新用户信息
|
||
@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('/newOrder',methods=['POST'])
|
||
# def newOrder():
|
||
# res = createOrder(request)
|
||
# if(res):
|
||
# return res
|
||
# else:
|
||
# abort(400)
|
||
|
||
# 处理订单异步通知(暂时废弃)
|
||
# @app.route('/notify',methods=['POST'])
|
||
# def notify():
|
||
# manageNotify(request)
|
||
# return 'ok'
|
||
|
||
# 小程序查询订单状态(暂时废弃)
|
||
# @app.route('/checkOrder',methods=['POST'])
|
||
# def check():
|
||
# res = checkOrder(request)
|
||
# print(res)
|
||
# if res:
|
||
# return res
|
||
# else:
|
||
# abort(500)
|
||
|
||
# 控制小程序是否显示“最佳案例”
|
||
@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')
|
||
|
||
|
||
# 二维码查询失败重定向, 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
|
||
|
||
# 目前的安全模式依赖于限制post访问,非对称加密校验,对所有内容进行规则审查,
|
||
# 主要还是防止有人恶意访问,等到写密码本的时候尝试模拟ssl加密模式
|