1. 根据uid和日期生成统一id。
# 12345678_20211112
def hash(uid_date):
seed = 131
hash = 0
for i in uid_date:
hash = hash * seed + ord(i)
hash = hash & 0x7FFFFFFF
return (hash % 5000)
2. 使用sha256进行hash
from datetime import datetime
from hashlib import sha256, sha512
import hmac
def hash(data, key="1547836219980"):
# data = "testappSecret"
cts = datetime.now().__str__()
data = data + cts
data = data.encode('utf-8')
key = key.encode('utf-8')
result = hmac.new(key, data, digestmod=sha256).hexdigest().upper()
return result