-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
60 lines (43 loc) · 1.14 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
# @Time : 2022/7/29 10:48
# @Author : yangyuexiong
# @Email : [email protected]
# @File : utils.py
# @Software: PyCharm
import time
import random
import string
import uuid
def gen_api_v3_key():
"""生成API V3 密钥"""
API_V3_KEY = "".join(str(uuid.uuid4()).split("-")).upper()
return API_V3_KEY
def gen_random_str(length=32):
"""
生成随机字符串
:param length:
:return: 32位随机字符串
"""
random_str = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(length))
return random_str
def gen_timestamp():
"""
时间戳
:return:
"""
return str(int(time.time()))
def gen_order_number(prefix="", suffix=""):
"""
生成订单号
"""
order_no = f"{prefix}{time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))}{int(time.time())}{suffix}"
return order_no
if __name__ == '__main__':
v3_key = gen_api_v3_key()
print(v3_key)
random_str = gen_random_str()
print(random_str)
timestamp = gen_timestamp()
print(timestamp)
order_number = gen_order_number()
print(order_number)