Просмотр исходного кода

Functions 增加str_to_md5方法

罗俊辉 7 месяцев назад
Родитель
Сommit
4501af9b0e
1 измененных файлов с 18 добавлено и 1 удалено
  1. 18 1
      applications/functions.py

+ 18 - 1
applications/functions.py

@@ -209,4 +209,21 @@ class Functions(object):
         :return:
         """
         job_thread = threading.Thread(target=job_func)
-        job_thread.start()
+        job_thread.start()
+
+    @classmethod
+    def str_to_md5(cls, strings):
+        """
+        字符串转化为 md5 值
+        :param strings:
+        :return:
+        """
+        # 将字符串转换为字节
+        original_bytes = strings.encode('utf-8')
+        # 创建一个md5 hash对象
+        md5_hash = hashlib.md5()
+        # 更新hash对象,传入原始字节
+        md5_hash.update(original_bytes)
+        # 获取16进制形式的MD5哈希值
+        md5_value = md5_hash.hexdigest()
+        return md5_value