xtn-tools-pro 1.0.0.7.0__py3-none-any.whl → 1.0.0.7.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xtn_tools_pro/utils/crypto.py +31 -0
- xtn_tools_pro/utils/helpers.py +19 -0
- {xtn_tools_pro-1.0.0.7.0.dist-info → xtn_tools_pro-1.0.0.7.2.dist-info}/METADATA +2 -1
- {xtn_tools_pro-1.0.0.7.0.dist-info → xtn_tools_pro-1.0.0.7.2.dist-info}/RECORD +7 -7
- {xtn_tools_pro-1.0.0.7.0.dist-info → xtn_tools_pro-1.0.0.7.2.dist-info}/LICENSE +0 -0
- {xtn_tools_pro-1.0.0.7.0.dist-info → xtn_tools_pro-1.0.0.7.2.dist-info}/WHEEL +0 -0
- {xtn_tools_pro-1.0.0.7.0.dist-info → xtn_tools_pro-1.0.0.7.2.dist-info}/top_level.txt +0 -0
xtn_tools_pro/utils/crypto.py
CHANGED
@@ -8,8 +8,11 @@
|
|
8
8
|
# --------------------------------------------------------------------------------------------------
|
9
9
|
# 2024/5/13 xiatn V00.01.000 新建
|
10
10
|
# --------------------------------------------------------------------------------------------------
|
11
|
+
import jwt
|
11
12
|
import base64
|
12
13
|
import hashlib
|
14
|
+
import secrets
|
15
|
+
import datetime
|
13
16
|
|
14
17
|
|
15
18
|
def get_md5_32(s: str, is_upper=False):
|
@@ -117,5 +120,33 @@ def get_base64_encode(s: str):
|
|
117
120
|
return encoded_string
|
118
121
|
|
119
122
|
|
123
|
+
def generate_bearer_token(secret_key, expiration=0, algorithm='HS256', **kwargs):
|
124
|
+
"""
|
125
|
+
生成 Bearer Token
|
126
|
+
:param secret_key: 用于加密的密钥
|
127
|
+
:param expiration: 过期时间戳,0则表示不过期
|
128
|
+
:param algorithm: 使用的加密算法(默认是 HS256)HS256、HS384、HS512
|
129
|
+
:param kwargs: 其他自定义的 Token 数据
|
130
|
+
:return: 生成的 Bearer Token
|
131
|
+
"""
|
132
|
+
payload = {
|
133
|
+
**kwargs # 将其他参数添加到 payload
|
134
|
+
}
|
135
|
+
if expiration:
|
136
|
+
payload['exp'] = expiration
|
137
|
+
|
138
|
+
token = jwt.encode(payload, secret_key, algorithm=algorithm)
|
139
|
+
return token
|
140
|
+
|
141
|
+
|
142
|
+
def generate_secret_key(length=32):
|
143
|
+
"""
|
144
|
+
生成一个随机的 secret key
|
145
|
+
:param length: key 的长度,默认为 32
|
146
|
+
:return: 生成的 secret key
|
147
|
+
"""
|
148
|
+
return secrets.token_hex(length)
|
149
|
+
|
150
|
+
|
120
151
|
if __name__ == '__main__':
|
121
152
|
print(get_base64_encode(''))
|
xtn_tools_pro/utils/helpers.py
CHANGED
@@ -12,8 +12,10 @@ import re
|
|
12
12
|
import uuid
|
13
13
|
import math
|
14
14
|
import json
|
15
|
+
import random
|
15
16
|
from uuid import UUID
|
16
17
|
from pprint import pformat
|
18
|
+
from datetime import datetime
|
17
19
|
from urllib.parse import urlencode
|
18
20
|
|
19
21
|
|
@@ -111,6 +113,7 @@ def get_calculate_total_page(total, limit):
|
|
111
113
|
total_pages = math.ceil(total / limit)
|
112
114
|
return total_pages
|
113
115
|
|
116
|
+
|
114
117
|
def get_build_url_with_params(url, params):
|
115
118
|
"""
|
116
119
|
传入url和params拼接完整的url ->效果 https://wwww.xxxx.com/?xxx1=1&xxx2=2
|
@@ -123,8 +126,24 @@ def get_build_url_with_params(url, params):
|
|
123
126
|
return full_url
|
124
127
|
|
125
128
|
|
129
|
+
def get_orderId_random(prefix="", suffix=""):
|
130
|
+
"""
|
131
|
+
随机生成20位订单号,前部分由年月日时分秒组成
|
132
|
+
:param prefix: 自定义前缀
|
133
|
+
:param suffix: 自定义后缀
|
134
|
+
:return:
|
135
|
+
"""
|
136
|
+
current_time = datetime.now()
|
137
|
+
date_time_str = current_time.strftime("%y%m%d%H%M%S")
|
138
|
+
# 生成随机部分
|
139
|
+
random_number = ''.join(random.choices('0123456789', k=8))
|
140
|
+
# 组合成完整的数字
|
141
|
+
combined_number = int(date_time_str + random_number)
|
142
|
+
return f"{prefix}{combined_number}{suffix}"
|
143
|
+
|
126
144
|
|
127
145
|
if __name__ == '__main__':
|
128
146
|
# print(get_uuid(4))
|
129
147
|
from faker import Faker
|
130
148
|
|
149
|
+
print(get_orderId_random())
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: xtn-tools-pro
|
3
|
-
Version: 1.0.0.7.
|
3
|
+
Version: 1.0.0.7.2
|
4
4
|
Summary: xtn 开发工具
|
5
5
|
Author: xtn
|
6
6
|
Author-email: czw011122@gmail.com
|
@@ -15,5 +15,6 @@ Requires-Dist: dbutils
|
|
15
15
|
Requires-Dist: colorlog
|
16
16
|
Requires-Dist: requests
|
17
17
|
Requires-Dist: Faker
|
18
|
+
Requires-Dist: PyJWT
|
18
19
|
|
19
20
|
xtnkk-tools
|
@@ -14,15 +14,15 @@ xtn_tools_pro/task_pro/go_fun.py,sha256=hWEt2uJ9FCvJH7PhVZttS-11A7J6zbRKwX7c5YLY
|
|
14
14
|
xtn_tools_pro/task_pro/go_fun_v2.py,sha256=SgcXgtEBGSVL1V2LyqO0z8Md2H8JZxucYrLLIwqtiLM,18489
|
15
15
|
xtn_tools_pro/task_pro/go_fun_v3.py,sha256=wPd7LFQlDhLH-5SIlq_1k8og5oW6KWeY6g3QvmZSFSU,16013
|
16
16
|
xtn_tools_pro/utils/__init__.py,sha256=I1_n_NP23F2lBqlF4EOlnOdLYxM8M4pbn63UhJN1hRE,418
|
17
|
-
xtn_tools_pro/utils/crypto.py,sha256=
|
17
|
+
xtn_tools_pro/utils/crypto.py,sha256=oyzFqWum_oimUtzhfVCELQhdMjxDbLu-nOWfcNmazcc,4087
|
18
18
|
xtn_tools_pro/utils/file_utils.py,sha256=VfdIxog4s1UW5NpKkCvQsUs9qHjLoNCnstZbnftkT4w,2046
|
19
|
-
xtn_tools_pro/utils/helpers.py,sha256=
|
19
|
+
xtn_tools_pro/utils/helpers.py,sha256=H-a3gnahIah3kJqyKzzKlPWtVQYcFlJncz2rAfBqIiw,4444
|
20
20
|
xtn_tools_pro/utils/log.py,sha256=m0WtTWkkwtrki1ftP8vCDR8bMfK2gcfUGx5J2x2IlLQ,10138
|
21
21
|
xtn_tools_pro/utils/retry.py,sha256=0wjHsR5DBBKpv4naMfxiky8kprrZes4WURIfFQ4H708,1657
|
22
22
|
xtn_tools_pro/utils/sql.py,sha256=EAKzbkZP7Q09j15Gm6o0_uq0qgQmcCQT6EAawbpp4v0,6263
|
23
23
|
xtn_tools_pro/utils/time_utils.py,sha256=TUtzG61PeVYXhaQd6pBrXAdlz7tBispNIRQRcGhE2No,4859
|
24
|
-
xtn_tools_pro-1.0.0.7.
|
25
|
-
xtn_tools_pro-1.0.0.7.
|
26
|
-
xtn_tools_pro-1.0.0.7.
|
27
|
-
xtn_tools_pro-1.0.0.7.
|
28
|
-
xtn_tools_pro-1.0.0.7.
|
24
|
+
xtn_tools_pro-1.0.0.7.2.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
25
|
+
xtn_tools_pro-1.0.0.7.2.dist-info/METADATA,sha256=3yoxlnRP7RmdnMWzkHg8OpenKAmOWzzHAZAkLXbKKsk,477
|
26
|
+
xtn_tools_pro-1.0.0.7.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
27
|
+
xtn_tools_pro-1.0.0.7.2.dist-info/top_level.txt,sha256=jyB3FLDEr8zE1U7wHczTgIbvUpALhR-ULF7RVEO7O2U,14
|
28
|
+
xtn_tools_pro-1.0.0.7.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|