1 import base64 2 import hmac 3 import urllib 4 from hashlib import sha1 5 expires = b"1501739982" # 过期时间戳 6 uuid = 'a2fafbbf-8877-4f73-8527-4707bf4df0b0'.encode(encoding="utf-8") # 授权id 7 key ='abcdefg123abcdefg123abcdefg123' # 渠道key 8 h = hmac.new(key.encode(encoding="utf-8"), 'GET\n%s\n%s'.encode(encoding="utf8") % (expires, uuid), sha1) 9 h.update(msg=b"ssss") # 其中如果消息过长的话可以使用update方法进行再次更新10 signature = base64.urlsafe_b64encode(h.digest())11 print(signature)
import base64import hmacimport urllibfrom hashlib import sha1import jsonrow_data = { "project_name": "授权项目", "project_desc": "项目描述", "project_where_to_put": "项目投放渠道"}key = b"abcdefg123abcdefg123abcdefg123"payload = base64.urlsafe_b64encode(json.dumps(row_data).encode(encoding="utf8"))h = hmac.new(key, payload, sha1)signature = base64.urlsafe_b64encode(h.digest())print(signature)