# Path: src/utils/tool.py
# class DO(dict):
#     def __getattr__(self, name):
# def ip_check(ip):
# def email_check(email):
# def ParseMySQL(mysql, callback="dict"):
# def UploadImage2Upyun(FilePath, FileData, kwargs=PLUGINS['UpYunStorage']):
# def UploadRealFile2Upyun(file, imgurl, kwargs=PLUGINS['UpYunStorage']):
# def BaiduActivePush(pushUrl, original=True, callUrl=PLUGINS['BaiduActivePush']['callUrl']):
# def ChoiceColor():
# def TagRandomColor():
# def getIpArea(ip):
# def getIpArea2(ip):
# def get_current_timestamp():
# def timestamp_after_timestamp(timestamp=None, seconds=0, minutes=0, hours=0, days=0):
# def timestamp_to_timestring(timestamp, format='%Y-%m-%d %H:%M:%S'):
# def url_check(addr):
# def sql_safestring_check(string):
# def formatSize(bytes):
# def make_zipfile(zip_filename, zip_path, exclude=[]):
# def str_count(str):
#         M = kb / 1024
#             G = M / 1024


from config import SYSTEM
from .tool import logger, md5, get_current_timestamp
from functools import wraps
from flask import request, jsonify



class Signature(object):
    """ 接口签名认证 """

    def __init__(self):
        self._version = SYSTEM["Sign"]["version"]
        self._accessKeys = [
            {"accesskey_id": SYSTEM["Sign"]["accesskey_id"], "accesskey_secret": SYSTEM["Sign"]["accesskey_secret"]}
        ]
        # 时间戳有效时长，单位秒
        self._timestamp_expiration = 30

    def get_signer_name(self):
        """获取签名算法"""
        return "MD5"

    def get_singer_version(self):
        """获取签名版本"""
        return self._version

    def _check_req_timestamp(self, req_timestamp):
        """ 校验时间戳
        @pram req_timestamp str,int: 请求参数中的时间戳(10位)
        """
        if len(str(req_timestamp)) == 10:
            return True
            req_timestamp = int(req_timestamp)
            now_timestamp = get_current_timestamp()

# Path: src/utils/tool.py
# class DO(dict):
#     def __getattr__(self, name):
# def ip_check(ip):
# def email_check(email):
# def ParseMySQL(mysql, callback="dict"):
# def UploadImage2Upyun(FilePath, FileData, kwargs=PLUGINS['UpYunStorage']):
# def UploadRealFile2Upyun(file, imgurl, kwargs=PLUGINS['UpYunStorage']):
# def BaiduActivePush(pushUrl, original=True, callUrl=PLUGINS['BaiduActivePush']['callUrl']):
# def ChoiceColor():
# def TagRandomColor():
# def getIpArea(ip):
# def getIpArea2(ip):
# def get_current_timestamp():
# def timestamp_after_timestamp(timestamp=None, seconds=0, minutes=0, hours=0, days=0):
# def timestamp_to_timestring(timestamp, format='%Y-%m-%d %H:%M:%S'):
# def url_check(addr):
# def sql_safestring_check(string):
# def formatSize(bytes):
# def make_zipfile(zip_filename, zip_path, exclude=[]):
# def str_count(str):
#         M = kb / 1024
#             G = M / 1024


# Path: src/utils/Signature.py
from config import SYSTEM
from .tool import logger, md5, get_current_timestamp
from functools import wraps
from flask import request, jsonify




class Signature(object):
    """ 接口签名认证 """

    def __init__(self):
        self._version = SYSTEM["Sign"]["version"]
        self._accessKeys = [
            {"accesskey_id": SYSTEM["Sign"]["accesskey_id"], "accesskey_secret": SYSTEM["Sign"]["accesskey_secret"]}
        ]
        # 时间戳有效时长，单位秒
        self._timestamp_expiration = 30

    def get_signer_name(self):
        """获取签名算法"""
        return "MD5"

    def get_singer_version(self):
        """获取签名版本"""
        return self._version

    def _check_req_timestamp(self, req_timestamp):
        """ 校验时间戳
        @pram req_timestamp str,int: 请求参数中的时间戳(10位)
        """
        if len(str(req_timestamp)) == 10:
            return True
            req_timestamp = int(req_timestamp)
            now_timestamp = get_current_timestamp()

            logger.sys.info("req_timestamp: {}, now_timestamp: {}, req_timestamp <= now_timestamp: {}, 30s: {}".format(req_timestamp, now_timestamp, req_timestamp <= now_timestamp, req_timestamp + self._timestamp_expiration >= now_timestamp))