2023-03-13 16:24:58 +08:00
|
|
|
# 全局使用的服务放到这里初始化,作为项目配置输入的入口
|
2023-03-13 14:22:40 +08:00
|
|
|
from logging import getLogger
|
2023-03-14 10:49:27 +08:00
|
|
|
from sqlalchemy.orm import declarative_base
|
2023-03-23 15:31:16 +08:00
|
|
|
from ThirdPartyApi.Tianyancha.Apis import TianyanchaApi
|
2023-03-24 11:03:13 +08:00
|
|
|
from ThirdPartyApi.Yujingtong.Apis import YujingtongApi
|
2023-03-13 14:22:40 +08:00
|
|
|
from Utils.AuthUtils import AuthUtil, TokenDataModel
|
2023-03-17 14:31:32 +08:00
|
|
|
from Utils.MongoUtils import MongoConnect
|
2023-03-13 14:22:40 +08:00
|
|
|
from Utils.RedisUtils import RedisPool
|
|
|
|
from Utils.SqlAlchemyUtils import SqlalchemyConnect
|
|
|
|
from configparser import ConfigParser
|
2023-03-20 14:11:37 +08:00
|
|
|
from Utils.VerifyCodeUtils import EmailCodeVerify, ImageCaptchaVerify, PhoneVerifyCode
|
|
|
|
from Utils.PhoneMsgUtils import PhoneMsgSend
|
2023-03-29 16:32:04 +08:00
|
|
|
from Utils.ApiLimitUtils import ApiLimit
|
2023-03-13 14:22:40 +08:00
|
|
|
|
|
|
|
# 日志
|
|
|
|
uvicorn_log = getLogger('uvicorn')
|
|
|
|
|
|
|
|
# 配置数据
|
|
|
|
conf = ConfigParser()
|
|
|
|
conf.read("Config/common.ini", encoding='utf-8-sig')
|
|
|
|
|
|
|
|
# redis连接池
|
|
|
|
redis_pool = RedisPool(host=conf['redis']['host'], port=int(conf['redis']['port']))
|
|
|
|
redis_pool.connect()
|
|
|
|
|
|
|
|
# 共用mysql数据库
|
2023-03-14 10:49:27 +08:00
|
|
|
common_db_base = declarative_base()
|
2023-07-28 14:06:44 +08:00
|
|
|
# common_db = SqlalchemyConnect(common_db_base, host=conf['mysql']['host'],
|
|
|
|
# user=conf['mysql']['user'],
|
|
|
|
# password=conf['mysql']['password'],
|
|
|
|
# db=conf['mysql']['db'])
|
|
|
|
|
|
|
|
common_db = SqlalchemyConnect(common_db_base, host=conf['remote_mysql']['host'],
|
|
|
|
user=conf['remote_mysql']['user'],
|
|
|
|
password=conf['remote_mysql']['password'],
|
|
|
|
db=conf['remote_mysql']['db'])
|
2023-03-13 14:22:40 +08:00
|
|
|
|
2023-03-17 14:31:32 +08:00
|
|
|
# mongo db
|
2023-03-29 10:56:53 +08:00
|
|
|
mg_db = MongoConnect(conf["mongo"]["host"], int(conf["mongo"]["port"]),
|
|
|
|
conf["mongo"]["db"],
|
|
|
|
conf["mongo"].get('user'),
|
|
|
|
conf["mongo"].get("password"))
|
2023-03-17 14:31:32 +08:00
|
|
|
|
2023-03-13 14:22:40 +08:00
|
|
|
# 邮箱验证码工具类
|
|
|
|
email_code_verify = EmailCodeVerify(redis_pool, conf['email']['api'], conf['email']['sender'])
|
|
|
|
|
|
|
|
# 图片验证码工具类
|
|
|
|
image_captcha_verify = ImageCaptchaVerify(redis_pool)
|
|
|
|
|
|
|
|
# 权限验证工具类
|
|
|
|
auth_util = AuthUtil[TokenDataModel](secret_key=conf['auth']['jwt_key'], tokenDataModel=TokenDataModel)
|
2023-03-20 14:11:37 +08:00
|
|
|
|
|
|
|
phone_msg_send = PhoneMsgSend(conf['hw_msg']['url'],
|
|
|
|
conf['hw_msg']['app_key'],
|
|
|
|
conf['hw_msg']['app_secret'],
|
|
|
|
conf['hw_msg']['sender'],
|
|
|
|
conf['hw_msg']['template_id'],
|
|
|
|
conf['hw_msg']['signature']
|
|
|
|
)
|
|
|
|
|
|
|
|
phone_verify_code = PhoneVerifyCode(redis_pool, phone_msg_send)
|
2023-03-23 15:31:16 +08:00
|
|
|
|
|
|
|
# 天眼查接口
|
2023-03-29 11:30:23 +08:00
|
|
|
tianyancha_api = TianyanchaApi(conf['tianyancha']['token'], mongo_connect=mg_db)
|
2023-03-24 11:03:13 +08:00
|
|
|
# 预警通接口
|
2023-03-29 11:30:23 +08:00
|
|
|
yujingtong_api = YujingtongApi(conf['yujingtong']['token'], mongo_connect=mg_db)
|
2023-03-29 16:32:04 +08:00
|
|
|
|
|
|
|
# 接口使用统计与限制
|
|
|
|
api_limit = ApiLimit(redis_pool=redis_pool)
|
|
|
|
|