Browse Source

update:添加get_sha258

dongzhaorui 2 years ago
parent
commit
3b47c9e6df
1 changed files with 21 additions and 1 deletions
  1. 21 1
      FworkSpider/feapder/utils/tools.py

+ 21 - 1
FworkSpider/feapder/utils/tools.py

@@ -7,7 +7,6 @@ Created on 2018-09-06 14:21
 @author: Boris
 @email: boris_liu@foxmail.com
 """
-
 import asyncio
 import calendar
 import codecs
@@ -43,6 +42,7 @@ import execjs  # pip install PyExecJS
 import redis
 import requests
 import six
+from Crypto.Hash.SHA256 import SHA256Hash
 from requests.cookies import RequestsCookieJar
 from w3lib.url import canonicalize_url as _canonicalize_url
 
@@ -1736,6 +1736,26 @@ def get_sha1(*args):
     return sha1.hexdigest()  # 40位
 
 
+def get_sha256(*args):
+    """
+    @summary: 获取唯一的64位值, 用于获取唯一的id
+    ---------
+    @param *args: 参与联合去重的值
+    ---------
+    @result: 5580c91ea29bf5bd963f4c08dfcacd983566e44ecea1735102bc380576fd6f30
+    """
+
+    # sha256 = hashlib.sha256()
+    # for arg in args:
+    #     sha256.update(str(arg).encode())
+    # return sha256.hexdigest()
+
+    sha256 = SHA256Hash()
+    for arg in args:
+        sha256.update(str(arg).encode('utf-8'))
+    return sha256.hexdigest()  # 64位
+
+
 def get_base64(secret, message):
     """
     @summary: 数字证书签名算法是:"HMAC-SHA256"