28 lines
520 B
Python
28 lines
520 B
Python
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 |