将url按照ASCII码进行排序加密
from urllib import parse import hashlib,time # 毫秒字符串 stamp = time.time() timestamp = int(round(stamp*1000)) param = { "partner":"abc", "timestamp":timestamp, "mobile":"17343037825" } print(param) # 排序后的字符串为params params = sorted(param.items()) # 默认按照ascii码从小到大排序 params = dict(params) # 转换为字典 # 新的url路径为params_url params_url = parse.urlencode(params) # 转换为url的格式 print(params_url) # 加密字符串 = 字符串排序+加盐处理 params_temp = params_url + "&key=51A1A92D917EF5B0E4D665BE62903E2B" print(params_temp) params_sign = hashlib.md5((params_temp).encode("utf-8")).hexdigest() print(params_sign) # 将加密后的字符串变大写 sign = params_sign.upper() print(sign)