# -*- coding: utf-8 -*- # 此接口为一卡通号转学号接口 from asyncio import events import traceback from auth import auth from database import SqlSet from handler import BaseHandler from log import LogBase from route import app logger = LogBase().get_logger("CardnoToStuidD") @app.route(r'/translate/cardnoToStuidD') @auth.admin class CardnoToStuidDHandler(BaseHandler): """ 一卡通号转学号 handler """ INFO = {"author": "zzccchen", "version": "2.0"} async def get(self, *args, **kwargs): cardno = self.get_argument_cardno() if not cardno: return self.finish() try: get_stu_stuid = await SqlSet.get_student_info( ["stuid"], "cardno", cardno) if not get_stu_stuid: return self.write_error_f(4041)
# coding=utf8 # 此接口为学生信息查询接口 from asyncio import events import traceback from auth import auth from database import SqlSet from handler import BaseHandler from log import LogBase from route import app logger = LogBase().get_logger("CourseTable") @app.route(r'/stu/stuInfo/courseTableAllL') @auth.admin class CourseTableAllLHandler(BaseHandler): """全部课表查询.""" INFO = {"author": "zzccchen", "version": "2.0"} async def get(self, *args, **kwargs): cardno = self.get_argument_cardno() if not cardno: return self.finish() try: stuid = await SqlSet.get_student_info(["stuid"], "cardno", cardno) if not stuid: return self.write_error_f(4041) get_course_table = await SqlSet.get_course_table_all(stuid["stuid"]
def __init__(self, name, psw): LogBase.__init__(self, name) self.web = SingleWeb() self.name = name self.psw = psw
# -*- coding: utf-8 -*- # 此接口为QQ转身份信息接口 from asyncio import events import traceback from auth import auth from database import SqlSet from handler import BaseHandler from log import LogBase from route import app logger = LogBase().get_logger("QqToInfoD") @app.route(r'/translate/qqToInfoD') @auth.admin class QqToInfoDHandler(BaseHandler): """ QQ转身份信息 handler """ INFO = {"author": "zzccchen", "version": "2.0"} async def get(self, *args, **kwargs): qq = self.get_argument_qq() if not qq: return self.finish() try: get_stu_info = await SqlSet.get_student_info(["*"], "qq", qq) if not get_stu_info: return self.write_error_f(4042) return self.write_json_f(get_stu_info)
# -*- coding: utf-8 -*- # redis模块 import configparser import redis from database.connect_database import Database from log import LogBase logger = LogBase().get_logger("RedisSession") class RedisSession(object): """Redis 相关类.""" __instance = None def __new__(cls, *args, **kwargs): """单例模式实现.""" if cls.__instance is None: cls.__instance = super(RedisSession, cls).__new__(cls) return cls.__instance def __init__(self): conf = configparser.ConfigParser() conf.read("./database/redis.cfg") self.host = conf["REDIS_INFO"]["host"] self.port = conf["REDIS_INFO"]["port"] self.db = conf["REDIS_INFO"]["db"] self.jsid = "jsid" def connect_redis(self): """连接到 Redis 数据库.
# -*- coding: utf-8 -*- # 此接口为QQ转一卡通接口 from asyncio import events import traceback from auth import auth from database import SqlSet from handler import BaseHandler from log import LogBase from route import app logger = LogBase().get_logger("QqToCardnoD") @app.route(r'/translate/qqToCardnoD') @auth.admin class QqToCardnoDHandler(BaseHandler): """ QQ转一卡通 handler.""" INFO = {"author": "zzccchen", "version": "2.0"} async def get(self, *args, **kwargs): qq = self.get_argument_qq() if not qq: return self.finish() try: get_stu_cardno = await SqlSet.get_student_info( ["cardno"], "qq", qq) if not get_stu_cardno: return self.write_error_f(4042) return self.write_json_f(get_stu_cardno) except Exception as e:
# 此接口为token发放接口 from asyncio import events import datetime import json import traceback import jwt import requests from .auth import auth from database import SqlSet from handler import BaseHandler from log import LogBase from route import app logger = LogBase().get_logger("XAuth") @app.route(r'/xAuth') class XAuthHandler(BaseHandler): """token发放模块.""" INFO = {"author": "zzccchen", "version": "2.0"} GET_OPEN_ID_URL = "https://graph.qq.com/oauth2.0/me" def get_openid(self, tk): access_token = str(tk)[3:] res = requests.get(self.GET_OPEN_ID_URL, params={"access_token": access_token}, timeout=60) res_json = json.loads(res.text[10:-3])
# coding=utf8 # 此接口为学生信息查询接口 from asyncio import events import traceback from auth import auth from database import SqlSet from handler import BaseHandler from log import LogBase from route import app logger = LogBase().get_logger("Paocao") @app.route(r'/stu/stuInfo/paocaoD') @auth.admin class PaocaoDHandler(BaseHandler): """获取最后一次打卡的次数和打卡时间.""" INFO = {"author": "zzccchen", "version": "2.0"} async def get(self, *args, **kwargs): cardno = self.get_argument_cardno() if not cardno: return self.finish() try: use, get_paocao, rank = await SqlSet.get_paocao(cardno) if not get_paocao: return self.write_error_f(4041) data = { "count": get_paocao["count_paocao"],
# -*- coding: utf-8 -*- # 此接口为词库相关接口 from asyncio import events import traceback from auth import auth from database import SqlSet from handler import BaseHandler from log import LogBase from route import app logger = LogBase().get_logger("LexiconD") @app.route(r'/basicTool/lexiconD') @auth.admin class LexiconDHandler(BaseHandler): """词库模块.""" INFO = {"author": "zzccchen", "version": "2.0"} async def get(self, *args, **kwargs): """查询词库中对应的回复.""" key = self.get_argument('key', None) try: reply = await SqlSet.get_dictionary(key) # 不开放secret标识为非0的key查询 if not reply or reply.get("secret", 1) != 0: return self.write_error_f(4047) else: del reply["secret"] return self.write_json_f(reply)
# -*- coding: utf-8 -*- # 此接口为用户信息相关接口 from route import app import traceback import pymysql from tornado import gen import tornado.web from auth import auth from database import db_pool from handler import BaseHandler from log import LogBase logger = LogBase().get_logger("UserInfo") @app.route(r'/user/userInfo/nicknameD') @auth.admin class NicknameDHandler(BaseHandler): """查询用户昵称.""" INFO = {"author": "zzccchen", "version": "2.0"} SELECT_SQL = """ SELECT `nickName` AS `nickname` FROM testsmallwei.signin_user WHERE `personQQ` = %s;"""
# -*- coding: utf-8 -*- # 此接口为名字转身份信息接口 from asyncio import events import traceback from auth import auth from database import SqlSet from handler import BaseHandler from log import LogBase from route import app logger = LogBase().get_logger("NameToInfoL") @app.route(r'/translate/nameToInfoL') @auth.admin class NameToInfoLHandler(BaseHandler): """名字转身份信息 handler.""" INFO = {"author": "zzccchen", "version": "2.0"} async def get(self, *args, **kwargs): name = self.get_argument('name', None) page = self.get_argument_page() pagesize = self.get_argument_pagesize() if not page or not pagesize: return self.finish() if not name: return self.write_error_f(40010) try:
import hashlib import json import traceback import zlib from asyncio import events from Crypto.Cipher import AES from Crypto.Util.Padding import unpad from auth import auth from database import SqlSet, redis_session from handler import BaseHandler from log import LogBase from route import app logger = LogBase().get_logger("PaocaoSpider") MD5_SET = "MD5_SET" MD5_COUNT = "count" @app.route(r'/basicTool/paocaoSpider') @auth.common class PaocaoSpiderHandler(BaseHandler): INFO = {"author": "zzccchen", "version": "2.0"} def decrypt(self, raw_data): key = b'1234123412ABCDEF' iv = b'ABCDEF1234123412' cipher = AES.new(key, AES.MODE_CBC, iv) return base64.b64decode(
#!/usr/bin/python3 # -*- coding: utf-8 -*- # import os from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop from handler import BaseHandler from log import LogBase from route import app logger = LogBase().get_logger("Main") @app.route(r'/') class HelloHandler(BaseHandler): """hello world模块.""" INFO = {"author": "zzccchen", "version": "2.0"} def get(self, *args, **kwargs): return self.write_json_f({"greet": "Hello Smallwei"}) def main(): try: logger.info("Xapi start") # http_server = tornado.httpserver.HTTPServer(app, ssl_options={ # "certfile": os.path.join(os.path.abspath("."), "server.crt"), # "keyfile": os.path.join(os.path.abspath("."), "server.key"), # }, xheaders=True)
# -*- coding: utf-8 -*- # 此接口为学号转一卡通接口 from asyncio import events import traceback from auth import auth from database import SqlSet from handler import BaseHandler from log import LogBase from route import app logger = LogBase().get_logger("StuidToCardnoD") @app.route(r'/translate/stuidToCardnoD') @auth.admin class StuidToCardnoDHandler(BaseHandler): """ 学号转一卡通 handler """ INFO = {"author": "zzccchen", "version": "2.0"} SELECT_SQL = """ SELECT `cardNo` AS `cardno` FROM testsmallwei.student_info WHERE `stuNo` = %s;""" async def get(self, *args, **kwargs):
# -*- coding: utf-8 -*- # 此接口为一卡通号转QQ接口 from asyncio import events import traceback from auth import auth from database import SqlSet from handler import BaseHandler from log import LogBase from route import app logger = LogBase().get_logger("CardnoToQqD") @app.route(r'/translate/cardnoToQqD') @auth.admin class CardnoToQqDHandler(BaseHandler): """一卡通号转QQ handler.""" INFO = {"author": "zzccchen", "version": "2.0"} async def get(self, *args, **kwargs): cardno = self.get_argument_cardno() if not cardno: return self.finish() try: get_stu_qq = await SqlSet.get_student_info(["qq"], "cardno", cardno) if not get_stu_qq: return self.write_error_f(4041) if get_stu_qq.get("qq") == None: return self.write_error_f(4045)
# -*- coding: utf-8 -*- # 创建数据库连接 import configparser import tormysql from log import LogBase logger = LogBase().get_logger("Database") class Database(object): """数据库类.""" __instance = None def __new__(cls, *args, **kwargs): """单例模式实现.""" if cls.__instance is None: cls.__instance = super(Database, cls).__new__(cls) return cls.__instance def __init__(self): """数据库配置.""" conf = configparser.ConfigParser() conf.read("./database/database.cfg") self.host = conf["DATABASE_INFO"]["host"] self.port = int(conf["DATABASE_INFO"]["port"]) self.user = conf["DATABASE_INFO"]["user"] self.passwd = conf["DATABASE_INFO"]["passwd"] self.db = conf["DATABASE_INFO"]["db"]
from route import app import datetime import requests import time import traceback import json import pymysql from tornado import gen import tornado.web from auth import auth from database import db_pool from handler import BaseHandler from log import LogBase logger = LogBase().get_logger("Signin") @app.route(r'/user/signin/signinD') @auth.admin class SigninHandler(BaseHandler): """签到模块. 使用日出日落时间 """ INFO = {"author": "zzccchen&Polydick", "version": "2.0"} SCORE_BASE = 10 # 签到基础分 SCORE_SUN_DOWN = 1 # 日落后补签加分 CTN_SCORE_SCALER = 0.1 # 连续签到加成放大因子