寫短信接口時,未加密不太安全,使用了md5加密
前端傳過來 telephone timestamp sign
先後端約定 salt爲XXX
驗證前端傳來的sign 是否爲 hashlib.md5((timestamp+telephone+self.salt).encode('utf-8')).hexdigest()防止別人隨便調用短信驗證接口
# md5函數必需要傳一個bytes類型的字符串進去
#hexdigest() 轉化爲字符串
import hashlib
sign2 = hashlib.md5((timestamp+telephone+salt).encode('utf-8')).hexdigest()
加密常見的問題:前端
1:Unicode-objects must be encoded before hashing 後端
解決方案:安全
import hashlib 函數
m2 = hashlib.md5() 加密
m2.update(src.encode('utf-8')) code
print m2.hexdigest()接口