cherry_be/lib/public/utils.py
2021-02-08 21:09:02 +08:00

39 lines
702 B
Python
Raw 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.

from urllib.request import quote, unquote
import base64
import json
from hashlib import md5
def btoa(content):
"""
JSON转base64
"""
return base64.b64encode(quote(content).encode())
def atob(content):
"""
base64转JSON
"""
return unquote(base64.b64decode(content).decode())
def signCode(code):
"""
给str签名用于加密密码
"""
d = str(code)
d = d.replace(' ', '')
md = md5()
md.update(d.encode('utf-8'))
r = md.hexdigest().upper()
return r
def checkData(data):
"""
MD5校验数据
"""
d = data.copy()
try:
d.pop('sign')
except KeyError:
pass
return data['sign'] == signCode(d)