Bot-CQBOT/python-apiproject/__init__.py
2024-07-06 09:47:19 +08:00

70 lines
2.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: UTF-8 -*-
# 开发人员:萌狼蓝天
# 博客Https://mllt.cc
# 笔记Https://cnblogs.com/mllt
# 哔哩哔哩/微信公众号:萌狼蓝天
# 开发时间2022/5/6
# CodingUTF-8
import flask, json
from flask import request
import oemail
from flask_cors import CORS, cross_origin # 导入包
from functools import wraps
from flask import make_response
from flask import render_template
server = flask.Flask(__name__) # 将该py文件转为一个服务
from package_info import API_INFO
server.register_blueprint(API_INFO)
from dynamic_toekn import API_DyNamicToken
server.register_blueprint(API_DyNamicToken)
# from OpenCVTool import API_OpenCVTool
# server.register_blueprint(API_OpenCVTool)
CORS(server, supports_credentials=True) # 设置参数
def allow_cross_domain(fun):
@wraps(fun)
def wrapper_fun(*args, **kwargs):
rst = make_response(fun(*args, **kwargs))
rst.headers['Access-Control-Allow-Origin'] = '*'
rst.headers['Access-Control-Allow-Methods'] = 'PUT,GET,POST,DELETE,OPTIONS,*'
allow_headers = "Referer,Accept,Origin,User-Agent"
rst.headers['Access-Control-Allow-Headers'] = allow_headers
return rst
return wrapper_fun
@server.route('/', methods=["GET"])
def index():
return render_template('index.html')
@server.route('/doc', methods=["GET"])
def document():
return render_template('document.html')
@server.route('/docs/doc', methods=["GET"])
def documentReturn():
return render_template('document.html')
@server.route('/docs/qq', methods=["GET"])
def page_doc_info_qq():
return render_template('info/qq.html')
@server.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
@server.errorhandler(500)
def internal_server_error(e):
return render_template('500.html'), 500
@server.route('/email/code', methods=['post'])
@allow_cross_domain
def emailSendCode():
receiver = request.values.get('receiver')
name = request.values.get('name')
key = request.values.get('key')
# key="qq2686485465"
return oemail.send(receiver, name, key)
if __name__ == '__main__':
server.run(debug=False, port=2312, host='0.0.0.0') # 指定端口,host,0.0.0.0代表不管几个网卡任何ip都可访问