CloudApiRequest 1.0.0__py3-none-any.whl → 1.1.0__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.
Potentially problematic release.
This version of CloudApiRequest might be problematic. Click here for more details.
- cloud/CloudAPIRequest.py +509 -425
- cloud/CloudApiConfig.py +437 -311
- cloud/CloudSignUtil.py +48 -13
- cloud/CloudYamlUtil.py +34 -7
- {cloudapirequest-1.0.0.dist-info → cloudapirequest-1.1.0.dist-info}/METADATA +1 -1
- cloudapirequest-1.1.0.dist-info/RECORD +13 -0
- cloudapirequest-1.0.0.dist-info/RECORD +0 -13
- {cloudapirequest-1.0.0.dist-info → cloudapirequest-1.1.0.dist-info}/LICENSE +0 -0
- {cloudapirequest-1.0.0.dist-info → cloudapirequest-1.1.0.dist-info}/WHEEL +0 -0
- {cloudapirequest-1.0.0.dist-info → cloudapirequest-1.1.0.dist-info}/top_level.txt +0 -0
cloud/CloudSignUtil.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import hashlib
|
|
2
|
-
import json
|
|
3
2
|
import time
|
|
4
|
-
from urllib.parse import urlparse
|
|
5
3
|
|
|
6
4
|
from cloud.CloudLogUtil import log
|
|
7
5
|
|
|
@@ -12,10 +10,19 @@ class CloudSignUtil:
|
|
|
12
10
|
鉴权方式:MD5({enterpriseId}+{timestamp}+{token})
|
|
13
11
|
"""
|
|
14
12
|
|
|
13
|
+
@staticmethod
|
|
14
|
+
def _generate_md5_hash(sign_string):
|
|
15
|
+
"""
|
|
16
|
+
生成MD5签名的内部方法
|
|
17
|
+
:param sign_string: 签名字符串
|
|
18
|
+
:return: 32位小写MD5签名
|
|
19
|
+
"""
|
|
20
|
+
return hashlib.md5(sign_string.encode('utf-8')).hexdigest()
|
|
21
|
+
|
|
15
22
|
@staticmethod
|
|
16
23
|
def generate_md5_signature(enterprise_id, timestamp, token):
|
|
17
24
|
"""
|
|
18
|
-
生成MD5
|
|
25
|
+
生成MD5签名(按企业编号)
|
|
19
26
|
:param enterprise_id: 企业ID
|
|
20
27
|
:param timestamp: 时间戳
|
|
21
28
|
:param token: 访问token
|
|
@@ -23,11 +30,28 @@ class CloudSignUtil:
|
|
|
23
30
|
"""
|
|
24
31
|
# 构建签名字符串:{enterpriseId}+{timestamp}+{token}
|
|
25
32
|
sign_string = f"{enterprise_id}{timestamp}{token}"
|
|
26
|
-
|
|
33
|
+
return CloudSignUtil._generate_md5_hash(sign_string)
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def generate_md5_signature_by_validate_type(validate_type, enterprise_id, department_id, timestamp, token):
|
|
37
|
+
"""
|
|
38
|
+
根据验证类型生成MD5签名
|
|
39
|
+
:param validate_type: 验证类型 (1=部门编号, 2=企业编号)
|
|
40
|
+
:param enterprise_id: 企业ID
|
|
41
|
+
:param department_id: 部门编号
|
|
42
|
+
:param timestamp: 时间戳
|
|
43
|
+
:param token: 访问token
|
|
44
|
+
:return: 32位小写MD5签名
|
|
45
|
+
"""
|
|
46
|
+
if validate_type == 1:
|
|
47
|
+
# validateType=1时,sign=MD5({departmentId}+{timestamp}+{部门token值})
|
|
48
|
+
sign_string = f"{department_id}{timestamp}{token}"
|
|
49
|
+
else:
|
|
50
|
+
# validateType=2时,sign=MD5({enterpriseId}+{timestamp}+{企业token值})
|
|
51
|
+
sign_string = f"{enterprise_id}{timestamp}{token}"
|
|
27
52
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
log.info(f"生成的MD5签名: {signature}")
|
|
53
|
+
signature = CloudSignUtil._generate_md5_hash(sign_string)
|
|
54
|
+
log.info(f"签名计算: validateType={validate_type}, sign_string={sign_string}, signature={signature}")
|
|
31
55
|
|
|
32
56
|
return signature
|
|
33
57
|
|
|
@@ -60,8 +84,6 @@ class CloudSignUtil:
|
|
|
60
84
|
# 添加企业ID到请求头(如果需要)
|
|
61
85
|
headers['X-Enterprise-Id'] = str(enterprise_id)
|
|
62
86
|
|
|
63
|
-
log.info(f"生成的请求头: {headers}")
|
|
64
|
-
|
|
65
87
|
return headers
|
|
66
88
|
|
|
67
89
|
@staticmethod
|
|
@@ -76,8 +98,23 @@ class CloudSignUtil:
|
|
|
76
98
|
# 获取当前时间戳(秒级)
|
|
77
99
|
timestamp = int(time.time())
|
|
78
100
|
|
|
79
|
-
#
|
|
80
|
-
|
|
101
|
+
# 检查验证类型
|
|
102
|
+
validate_type = 2 # 默认按企业编号验证
|
|
103
|
+
department_id = None
|
|
104
|
+
|
|
105
|
+
if additional_params:
|
|
106
|
+
validate_type = int(additional_params.get('validateType', 2))
|
|
107
|
+
department_id = additional_params.get('departmentId')
|
|
108
|
+
|
|
109
|
+
# 根据验证类型生成签名
|
|
110
|
+
if validate_type == 1 and department_id:
|
|
111
|
+
# 按部门编号验证
|
|
112
|
+
signature = CloudSignUtil.generate_md5_signature_by_validate_type(
|
|
113
|
+
validate_type, enterprise_id, department_id, timestamp, token
|
|
114
|
+
)
|
|
115
|
+
else:
|
|
116
|
+
# 按企业编号验证
|
|
117
|
+
signature = CloudSignUtil.generate_md5_signature(enterprise_id, timestamp, token)
|
|
81
118
|
|
|
82
119
|
# 构建基础参数
|
|
83
120
|
params = {
|
|
@@ -90,8 +127,6 @@ class CloudSignUtil:
|
|
|
90
127
|
if additional_params:
|
|
91
128
|
params.update(additional_params)
|
|
92
129
|
|
|
93
|
-
log.info(f"生成的请求参数: {params}")
|
|
94
|
-
|
|
95
130
|
return params
|
|
96
131
|
|
|
97
132
|
@staticmethod
|
cloud/CloudYamlUtil.py
CHANGED
|
@@ -144,14 +144,41 @@ class CloudPlaceholderYaml:
|
|
|
144
144
|
return self
|
|
145
145
|
|
|
146
146
|
def jsonLoad(self):
|
|
147
|
-
#
|
|
148
|
-
|
|
147
|
+
# 先将单引号替换为双引号,None替换为null
|
|
148
|
+
temp_str = self.replaced_str.replace("'", "\"").replace('None', 'null')
|
|
149
|
+
|
|
150
|
+
# 在解析之前,检测并保护JSON字符串参数
|
|
151
|
+
# 查找模式:"key": "{...}" 或 "key": "[...]"
|
|
152
|
+
# 将内部的引号转义,使其成为合法的JSON字符串
|
|
153
|
+
def escape_json_string_values(match):
|
|
154
|
+
key = match.group(1)
|
|
155
|
+
json_str = match.group(2)
|
|
156
|
+
# 转义内部的双引号
|
|
157
|
+
escaped_json_str = json_str.replace('"', '\\"')
|
|
158
|
+
return f'"{key}": "{escaped_json_str}"'
|
|
159
|
+
|
|
160
|
+
# 匹配 "key": "{...}" 或 "key": "[...]" 的模式
|
|
161
|
+
# 使用非贪婪匹配,并且只匹配value部分被双引号包裹的情况
|
|
162
|
+
# .*? 可以匹配包含双引号的内容
|
|
163
|
+
pattern = r'"(\w+)"\s*:\s*"(\{.*?\}|\[.*?\])"'
|
|
164
|
+
temp_str = re.sub(pattern, escape_json_string_values, temp_str)
|
|
165
|
+
log.info(f"转义后的字符串: {temp_str[:300]}")
|
|
166
|
+
|
|
149
167
|
try:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
168
|
+
# 尝试直接解析
|
|
169
|
+
parsed_result = json.loads(temp_str)
|
|
170
|
+
log.info("替换后jsonLoad的str内容为:{}".format(parsed_result))
|
|
171
|
+
return parsed_result
|
|
172
|
+
except json.JSONDecodeError as e:
|
|
173
|
+
# 如果直接解析失败,尝试旧的替换逻辑(兼容旧用例)
|
|
174
|
+
log.warning(f"JSON解析失败: {e}, 尝试旧的替换逻辑")
|
|
175
|
+
try:
|
|
176
|
+
replaced_str = self.replaced_str.replace('"[', '[').replace(']"', ']').replace('"{', '{').replace('}"', '}').replace("'", "\"").replace('None','null')
|
|
177
|
+
replaced_str = json.loads(replaced_str)
|
|
178
|
+
log.info("替换后jsonLoad的str内容为:{}".format(replaced_str))
|
|
179
|
+
return replaced_str
|
|
180
|
+
except:
|
|
181
|
+
log.info(f'*************替换失败-YAML,请检查格式{replaced_str}******************')
|
|
155
182
|
|
|
156
183
|
def textLoad(self):
|
|
157
184
|
return json.loads(self.replaced_str)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
cloud/CloudAPIRequest.py,sha256=tacJg_mSrRr7ZkGxWivcGBeAJ4QwHtrOEmySg2xBwTM,24152
|
|
2
|
+
cloud/CloudApiConfig.py,sha256=s4VjgJT8cwCU2IZdZm5u5pgRxs8gp9ia5kW6P9txUWI,13027
|
|
3
|
+
cloud/CloudLogUtil.py,sha256=EXnU6QXFxl_npCcJgQvhtlG8uR57NmbOovFjVMHPOpQ,935
|
|
4
|
+
cloud/CloudRequestUtil.py,sha256=bsbI74p1iu4weXbDKqwhXvH1KwezvxYXdrXBMc9L3sE,4827
|
|
5
|
+
cloud/CloudSignUtil.py,sha256=dyUESxWYgcvTt-nOnI3mEboVispEF0cl_vX-1d3kUOU,5493
|
|
6
|
+
cloud/CloudYamlUtil.py,sha256=-WoOBSVsTQG9nbeEPocwh4eFV0Iilj1IcqXGYw5DYxs,9787
|
|
7
|
+
cloud/__init__.py,sha256=RgNAN_vKhCHnwcBy0hc1ttrr5x58bO_u6TNICZDSfFw,306
|
|
8
|
+
cloud/cli.py,sha256=VId1s29djJu7QrkXJc2je4fRV030vqD3nwuI23AN8Ig,1986
|
|
9
|
+
cloudapirequest-1.1.0.dist-info/LICENSE,sha256=hMjjUYpALQY0E8hzysmZszKwYy2mt8tUvAFQfIIbwV4,1099
|
|
10
|
+
cloudapirequest-1.1.0.dist-info/METADATA,sha256=PvbPs39nNOGRbmvDT7pLOX4gYp2MqxrXFI27D2pRGOA,608
|
|
11
|
+
cloudapirequest-1.1.0.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
|
12
|
+
cloudapirequest-1.1.0.dist-info/top_level.txt,sha256=lBiHHi76sKOBY-DmE0iDypxZxv-TTCnvHeiFleC_PuA,6
|
|
13
|
+
cloudapirequest-1.1.0.dist-info/RECORD,,
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
cloud/CloudAPIRequest.py,sha256=bji5WJJ4UQPO7EhQ2IsFMAOcG1aHtxjRU-0zwzNek2U,19441
|
|
2
|
-
cloud/CloudApiConfig.py,sha256=6mF-guPi92UyjE0o7pXVd5cZKZAJHmohv16CvziVkGs,9138
|
|
3
|
-
cloud/CloudLogUtil.py,sha256=EXnU6QXFxl_npCcJgQvhtlG8uR57NmbOovFjVMHPOpQ,935
|
|
4
|
-
cloud/CloudRequestUtil.py,sha256=bsbI74p1iu4weXbDKqwhXvH1KwezvxYXdrXBMc9L3sE,4827
|
|
5
|
-
cloud/CloudSignUtil.py,sha256=3D2etwvk1LYRE3GzoU6qXfTIM4FhEFjmT-i458Q2uCA,3849
|
|
6
|
-
cloud/CloudYamlUtil.py,sha256=_WmtzLOBznwYNY02JOQxOB3B8WvgJONk-PV7grw2C_U,8392
|
|
7
|
-
cloud/__init__.py,sha256=RgNAN_vKhCHnwcBy0hc1ttrr5x58bO_u6TNICZDSfFw,306
|
|
8
|
-
cloud/cli.py,sha256=VId1s29djJu7QrkXJc2je4fRV030vqD3nwuI23AN8Ig,1986
|
|
9
|
-
cloudapirequest-1.0.0.dist-info/LICENSE,sha256=hMjjUYpALQY0E8hzysmZszKwYy2mt8tUvAFQfIIbwV4,1099
|
|
10
|
-
cloudapirequest-1.0.0.dist-info/METADATA,sha256=3uFgDtx9S2odQlKmBxEKJULLQKq-rxcix41RpnET33I,608
|
|
11
|
-
cloudapirequest-1.0.0.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
|
12
|
-
cloudapirequest-1.0.0.dist-info/top_level.txt,sha256=lBiHHi76sKOBY-DmE0iDypxZxv-TTCnvHeiFleC_PuA,6
|
|
13
|
-
cloudapirequest-1.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|