ynet-sdk-python 0.0.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.
- ynet_sdk/__init__.py +50 -0
- ynet_sdk/__main__.py +10 -0
- ynet_sdk/_version.py +11 -0
- ynet_sdk/cli.py +141 -0
- ynet_sdk/common/__init__.py +9 -0
- ynet_sdk/common/sign/__init__.py +40 -0
- ynet_sdk/common/sign/_algorithms.py +154 -0
- ynet_sdk/common/sign/_converter.py +305 -0
- ynet_sdk/common/sign/constants.py +84 -0
- ynet_sdk/common/sign/open_api_sign.py +330 -0
- ynet_sdk/exceptions.py +60 -0
- ynet_sdk/py.typed +1 -0
- ynet_sdk_python-0.0.2.dist-info/METADATA +375 -0
- ynet_sdk_python-0.0.2.dist-info/RECORD +17 -0
- ynet_sdk_python-0.0.2.dist-info/WHEEL +4 -0
- ynet_sdk_python-0.0.2.dist-info/entry_points.txt +2 -0
- ynet_sdk_python-0.0.2.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: ynet-sdk-python
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Ynet 数据中心开放平台 SDK —— 支持 MD5 / HMAC_SHA256 / RSA2 的请求签名与验签(与 Java 版逐字节一致)
|
|
5
|
+
Project-URL: Homepage, https://ynet-data-center-manager.belink.com/gitlab/root/ynet-sdk-python
|
|
6
|
+
Project-URL: Repository, https://ynet-data-center-manager.belink.com/gitlab/root/ynet-sdk-python
|
|
7
|
+
Project-URL: Issues, https://ynet-data-center-manager.belink.com/gitlab/root/ynet-sdk-python/-/issues
|
|
8
|
+
Project-URL: Changelog, https://ynet-data-center-manager.belink.com/gitlab/root/ynet-sdk-python/-/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Documentation, https://ynet-data-center-manager.belink.com/gitlab/root/ynet-sdk-python/-/blob/main/README.md
|
|
10
|
+
Project-URL: Java SDK, https://ynet-data-center-manager.belink.com/gitlab/root/ynet-sdk-java
|
|
11
|
+
Author-email: 张吉健 <zhangjj2@belink.com>
|
|
12
|
+
Maintainer-email: 数据中心架构组 <zhangjj2@belink.com>
|
|
13
|
+
License: Apache-2.0
|
|
14
|
+
Keywords: belink,hmac,md5,openapi,rsa2,sdk,sign,signature,ynet
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Security :: Cryptography
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.9
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
31
|
+
Requires-Dist: cryptography>=42.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
36
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
37
|
+
Provides-Extra: rsa
|
|
38
|
+
Requires-Dist: cryptography>=42.0; extra == 'rsa'
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
|
|
41
|
+
# Ynet Data Center OpenAPI SDK (Python)
|
|
42
|
+
|
|
43
|
+
专为 **Ynet 数据中心开放平台** 设计的官方 Python SDK,是
|
|
44
|
+
[Java 版 ynet-sdk-java](https://ynet-data-center-manager.belink.com/gitlab/root/ynet-sdk-java)
|
|
45
|
+
的等价实现。
|
|
46
|
+
|
|
47
|
+
本版本核心提供 API 请求的**签名与验签**能力,**Java 端与 Python 端签名结果逐字节一致**,
|
|
48
|
+
因此可以放心用于「Java 客户端 + Python 网关」或「Python 客户端 + Java 网关」的混合部署。
|
|
49
|
+
后续将持续扩展统一 HTTP 客户端、数据加解密、Webhook 回调处理等组件。
|
|
50
|
+
|
|
51
|
+

|
|
52
|
+

|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 🌟 核心特性
|
|
58
|
+
|
|
59
|
+
- **🛡️ 多算法安全支持**:原生支持 `MD5`、`HMAC_SHA256`、`RSA2`(SHA256withRSA)三种签名算法。
|
|
60
|
+
- **🧬 与 Java 版逐字节一致**:排序规则、值转换、空值过滤、异常文案全部对齐,
|
|
61
|
+
并由 `tests/test_java_parity.py` 用 Java 原始实现的输出做回归验证。
|
|
62
|
+
- **🧾 复杂参数自动 JSON 化**(0.0.2 新增):`dict` / `list` / dataclass 等复杂值
|
|
63
|
+
按 Java 版相同的 fastjson2 规则序列化为标准 JSON,嵌套业务数据也能两端签出同一个串。
|
|
64
|
+
- **🧠 智能参数处理**:按参数名 **UTF-16 字典序**(等同 Java `TreeMap<String>`)排序,
|
|
65
|
+
自动过滤 `null` 与空白值,拼接为 `key1=value1&key2=value2`。
|
|
66
|
+
- **🚫 防"自己签自己"**:内置默认排除列表(`msgSignature`、`sign`、`signature`、`signData`)。
|
|
67
|
+
- **⏱️ 强制防重放校验**:默认强制校验 `timestamp` 与 `nonce`,缺失立即抛异常。
|
|
68
|
+
- **📦 零运行时依赖**:基础安装只依赖标准库;`RSA2` 作为可选依赖按需安装。
|
|
69
|
+
- **🔒 恒定时间比较**:验签使用 `hmac.compare_digest`,可抵御时序侧信道攻击。
|
|
70
|
+
- **🧩 类型完备**:全量类型注解,自带 `py.typed`,支持 mypy / pyright。
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 🚀 安装
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# 基础能力(MD5 / HMAC_SHA256),零第三方依赖
|
|
78
|
+
pip install ynet-sdk-python
|
|
79
|
+
|
|
80
|
+
# 需要 RSA2 时安装可选依赖
|
|
81
|
+
pip install "ynet-sdk-python[rsa]"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
要求 Python 3.9 及以上。
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## ⚡ 快速开始
|
|
89
|
+
|
|
90
|
+
### 1. 客户端:生成签名
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from ynet_sdk import generate_sign
|
|
94
|
+
|
|
95
|
+
params = {
|
|
96
|
+
"appKey": "YNET_123456",
|
|
97
|
+
"timestamp": "1698765432100", # 毫秒级时间戳
|
|
98
|
+
"nonce": "a1b2c3d4e5f6", # 随机字符串
|
|
99
|
+
"userId": "1001", # 业务参数
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
app_secret = "your_app_secret_here"
|
|
103
|
+
sign = generate_sign(params, "HMAC_SHA256", app_secret)
|
|
104
|
+
|
|
105
|
+
params["msgSignature"] = sign # 签名只参与传输,不参与计算
|
|
106
|
+
print("生成的签名:", sign) # 64 位小写十六进制
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 2. 服务端(网关):验证签名
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from ynet_sdk import verify_sign
|
|
113
|
+
from ynet_sdk.exceptions import SignParameterError
|
|
114
|
+
|
|
115
|
+
# 假设这是从 HTTP 请求中收到的全部参数(含 msgSignature)
|
|
116
|
+
params = get_params_from_request()
|
|
117
|
+
client_sign = params.get("msgSignature")
|
|
118
|
+
|
|
119
|
+
app_secret = get_app_secret_from_cache(params["appKey"])
|
|
120
|
+
|
|
121
|
+
if not verify_sign(params, "HMAC_SHA256", app_secret, client_sign):
|
|
122
|
+
raise PermissionError("签名校验失败,拒绝访问!")
|
|
123
|
+
|
|
124
|
+
print("签名校验通过,允许执行业务逻辑")
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 3. RSA2(非对称)
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from ynet_sdk import generate_sign, verify_sign
|
|
131
|
+
|
|
132
|
+
sign = generate_sign(params, "RSA2", PRIVATE_KEY_PEM) # 私钥签名,输出 Base64
|
|
133
|
+
ok = verify_sign(params, "RSA2", PUBLIC_KEY_PEM, sign) # 公钥验签
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
> 密钥支持 PEM(带 `-----BEGIN ...-----` 头尾与换行)或裸 Base64 字符串,
|
|
137
|
+
> 也接受 DER 字节;PKCS#8 / PKCS#1 / X.509 均可。
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## ⚙️ 高级用法:自定义校验规则
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from ynet_sdk import build_sign_content, generate_sign
|
|
145
|
+
|
|
146
|
+
# 场景 1:跳过必传字段校验,且不排除任何字段(极简模式)
|
|
147
|
+
sign1 = generate_sign(params, "MD5", "secret", None, None)
|
|
148
|
+
|
|
149
|
+
# 场景 2:自定义必传字段(例如必须传 appKey 和 tenantId)
|
|
150
|
+
sign2 = generate_sign(params, "MD5", "secret", ["appKey", "tenantId"], None)
|
|
151
|
+
|
|
152
|
+
# 场景 3:自定义排除字段(例如业务自定义签名字段名为 mySign)
|
|
153
|
+
sign3 = generate_sign(params, "MD5", "secret", None, {"mySign", "callbackUrl"})
|
|
154
|
+
|
|
155
|
+
# 场景 4:只构建待签名字符串,便于排查两端不一致
|
|
156
|
+
content = build_sign_content(params)
|
|
157
|
+
print(content) # appKey=YNET_123456&nonce=...×tamp=...&userId=1001
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 复杂参数(嵌套结构)
|
|
161
|
+
|
|
162
|
+
嵌套的 `dict` / `list` / dataclass 会被序列化成标准 JSON 后参与签名,与 Java 版一致:
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from dataclasses import dataclass
|
|
166
|
+
from ynet_sdk import build_sign_content, generate_sign
|
|
167
|
+
|
|
168
|
+
params = {
|
|
169
|
+
"timestamp": "1698765432100",
|
|
170
|
+
"nonce": "a1b2c3d4",
|
|
171
|
+
"profile": {"city": "上海", "tags": ["vip", "new"], "level": 3},
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
build_sign_content(params)
|
|
175
|
+
# 'nonce=a1b2c3d4&profile={"city":"上海","tags":["vip","new"],"level":3}×tamp=1698765432100'
|
|
176
|
+
|
|
177
|
+
@dataclass
|
|
178
|
+
class Address:
|
|
179
|
+
city: str
|
|
180
|
+
zip_code: int
|
|
181
|
+
|
|
182
|
+
generate_sign({**params, "addr": Address("杭州", 310000)}, "HMAC_SHA256", "secret")
|
|
183
|
+
# addr={"city":"杭州","zip_code":310000}&...
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
> 注意:`dict` 里的 `None` 会被整条丢弃(fastjson2 默认不输出 null 字段),
|
|
187
|
+
> 而 `list` 里的 `None` 会保留为 `null`。
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## 📖 API 参考
|
|
192
|
+
|
|
193
|
+
| 函数 | 说明 |
|
|
194
|
+
| :--- | :--- |
|
|
195
|
+
| `generate_sign(params, sign_type, secret, required_fields=..., exclude_fields=...)` | 生成签名 |
|
|
196
|
+
| `verify_sign(params, sign_type, secret, client_sign, required_fields=..., exclude_fields=...)` | 验证签名,返回 `bool` |
|
|
197
|
+
| `build_sign_content(params, exclude_fields=...)` | 构建待签名字符串 |
|
|
198
|
+
| `check_required_fields(params, required_fields)` | 单独校验必传字段 |
|
|
199
|
+
|
|
200
|
+
| 参数 | 类型 | 说明 |
|
|
201
|
+
| :--- | :--- | :--- |
|
|
202
|
+
| `params` | `Mapping[str, Any]` | 参与签名的参数 |
|
|
203
|
+
| `sign_type` | `str` / `SignType` | `"MD5"` / `"HMAC_SHA256"` / `"RSA2"`,大小写不敏感 |
|
|
204
|
+
| `secret` | `str`(RSA2 可为 `bytes`) | AppSecret,或 Base64/DER 私钥/公钥 |
|
|
205
|
+
| `required_fields` | `Sequence[str] \| None` | 默认 `("timestamp", "nonce")`;`None` 表示不校验 |
|
|
206
|
+
| `exclude_fields` | `Set[str] \| None` | 默认排除 4 个签名字段;`None` 表示不排除 |
|
|
207
|
+
|
|
208
|
+
**异常体系**(均继承 `OpenApiSignError`):
|
|
209
|
+
|
|
210
|
+
| 异常 | 同时是 | 触发场景 |
|
|
211
|
+
| :--- | :--- | :--- |
|
|
212
|
+
| `SignParameterError` | `ValueError` | 参数为空、缺必传字段、算法不支持 |
|
|
213
|
+
| `SignKeyError` | `ValueError` | 密钥格式非法 |
|
|
214
|
+
| `SignDependencyError` | `ImportError` | 未安装 `cryptography` 却使用 RSA2 |
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## 🔄 与 Java 版对照
|
|
219
|
+
|
|
220
|
+
| Java (`com.belink.sdk.common.sign.OpenApiSignUtil`) | Python (`ynet_sdk`) |
|
|
221
|
+
| :--- | :--- |
|
|
222
|
+
| `generateSign(params, signType, secret)` | `generate_sign(params, sign_type, secret)` |
|
|
223
|
+
| `generateSign(p, t, s, required, exclude)` | `generate_sign(p, t, s, required, exclude)` |
|
|
224
|
+
| `verifySign(p, t, s, clientSign)` | `verify_sign(p, t, s, client_sign)` |
|
|
225
|
+
| `buildSignContent(params)` | `build_sign_content(params)` |
|
|
226
|
+
| `IllegalArgumentException` | `SignParameterError`(`ValueError` 子类) |
|
|
227
|
+
| `OpenApiSignUtil.MD5` 等常量 | `SignType.MD5` 等枚举 |
|
|
228
|
+
|
|
229
|
+
为降低迁移成本,还提供了 Java 风格的兼容门面:
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
from ynet_sdk import OpenApiSignUtil
|
|
233
|
+
OpenApiSignUtil.generate_sign(params, "HMAC_SHA256", secret) # 等价于模块级函数
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### 与 Java 版的差异(均为增强,不改变签名结果)
|
|
237
|
+
|
|
238
|
+
| 项目 | Java 版 | Python 版 |
|
|
239
|
+
| :--- | :--- | :--- |
|
|
240
|
+
| 验签比较 | `String.equals` | `hmac.compare_digest`(恒定时间) |
|
|
241
|
+
| Base64 填充 | 必须合法 | 自动补齐缺失的 `=` |
|
|
242
|
+
| 私钥格式 | 仅 PKCS#8 | PKCS#8 与 PKCS#1 均可 |
|
|
243
|
+
| 非字符串 `secret` | 编译期约束 | 显式抛 `SignParameterError` 并给出提示 |
|
|
244
|
+
| 浮点次正规数(如 `5e-324`) | `4.9E-324` | `5.0E-324`(Python 最短表示) |
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## 🌐 跨语言一致性说明
|
|
249
|
+
|
|
250
|
+
同一份参数在 Java 与 Python 端必须拼出**完全相同的待签名字符串**,SDK 已处理以下差异:
|
|
251
|
+
|
|
252
|
+
1. **排序**:Java 的 `TreeMap<String>` 按 UTF-16 code unit 排序。Python 默认按 Unicode 码位排序,
|
|
253
|
+
对 emoji 等 BMP 外字符顺序不同,SDK 已改用 UTF-16 排序键。
|
|
254
|
+
2. **布尔值**:输出 `true` / `false`(小写),而非 Python 的 `True` / `False`。
|
|
255
|
+
3. **浮点数**:按 Java `Double.toString` 格式化,如 `1.0`、`0.001`、`1.0E7`、`1.0E-4`。
|
|
256
|
+
4. **空白判定**:采用 Java `trim()` 语义,只剔除 `<= U+0020` 的字符(NBSP、全角空格不算空白)。
|
|
257
|
+
5. **复杂值**(0.0.2 起):`dict` / `list` / `tuple` / `set` / dataclass / 带 `model_dump()`
|
|
258
|
+
的对象按 fastjson2 规则序列化成 JSON——无空格、`Map` 中的 `null` 键被丢弃、
|
|
259
|
+
`List` 中的 `null` 保留为 `null`、中文与 emoji 不转义。例如:
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
build_sign_content({"p": {"city": "上海", "tags": ["a", "b"], "level": 3}})
|
|
263
|
+
# 'p={"city":"上海","tags":["a","b"],"level":3}'
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
6. **已知差异**:Java 的 `java.util.Date` 会被写成毫秒时间戳、枚举写成枚举名;
|
|
267
|
+
Python 侧 `datetime` 输出 ISO 字符串、`Enum` 取 `.value`。需要严格互通时请传字符串。
|
|
268
|
+
|
|
269
|
+
> **💡 最佳实践**:跨语言场景建议**所有参数值都以字符串传递**。
|
|
270
|
+
> 数字、布尔、时间等类型请自行格式化成两端都认可的文本(如 `"1698765432100"`、`"true"`、`"2026-10-25 22:48:00"`),
|
|
271
|
+
> 这样最稳妥,也不受各语言默认格式化规则影响。确实需要嵌套结构时,优先用
|
|
272
|
+
> `dict` / `list`(两端都会按同一套 JSON 规则处理),并保证 Java 侧使用 `LinkedHashMap`
|
|
273
|
+
> 等保序 Map,两端键顺序一致。
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## 🖥️ 命令行工具
|
|
278
|
+
|
|
279
|
+
安装后可直接用 `ynet-sign` 或 `python -m ynet_sdk` 联调排查:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
# 计算签名
|
|
283
|
+
ynet-sign sign --type HMAC_SHA256 --secret s3cr3t \
|
|
284
|
+
--param appKey=YNET_123456 --param timestamp=1698765432100 --param nonce=abc
|
|
285
|
+
|
|
286
|
+
# 校验签名(退出码 0=通过,1=不通过,2=参数错误)
|
|
287
|
+
ynet-sign verify --type HMAC_SHA256 --secret s3cr3t --sign <签名> --param appKey=YNET_123456
|
|
288
|
+
|
|
289
|
+
# 只看待签名字符串,用于和 Java 端逐字符比对
|
|
290
|
+
ynet-sign content --param b=2 --param a=1
|
|
291
|
+
|
|
292
|
+
# 用 JSON 传参保留类型,或从文件读取 RSA 私钥
|
|
293
|
+
ynet-sign sign --type RSA2 --secret-file ./private_key.pem --json '{"appKey": "K", "timestamp": "1", "nonce": "n"}'
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## 🧪 开发与验证
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
# 安装开发依赖
|
|
302
|
+
pip install -e ".[dev]"
|
|
303
|
+
|
|
304
|
+
# 运行测试(含跨语言一致性验证)
|
|
305
|
+
pytest
|
|
306
|
+
|
|
307
|
+
# 静态检查
|
|
308
|
+
ruff check src tests
|
|
309
|
+
mypy
|
|
310
|
+
|
|
311
|
+
# 构建分发包
|
|
312
|
+
python -m build
|
|
313
|
+
twine check dist/*
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### 跨语言一致性如何保证?
|
|
317
|
+
|
|
318
|
+
`tests/data/vectors.json` 不是手工编写的,而是由 `tools/java-parity/generate_vectors.py`
|
|
319
|
+
**编译并运行 Java 版原始实现**后导出的真实输出(待签名字符串、签名结果、验签结论、异常文案、
|
|
320
|
+
RSA2 签名)。因此测试通过即代表两端行为一致。Java 版算法调整后,重新生成向量即可:
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
python tools/java-parity/generate_vectors.py --java-sdk /path/to/ynet-sdk-java
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## 📦 发布到仓库
|
|
329
|
+
|
|
330
|
+
完整的发布流程(PyPI / 私有 Nexus / GitLab Package Registry、可信发布、版本号管理)
|
|
331
|
+
见 [docs/RELEASE.md](docs/RELEASE.md)。最简流程:
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
# 1. 修改版本号(src/ynet_sdk/_version.py)并更新 CHANGELOG
|
|
335
|
+
# 2. 构建 + 校验
|
|
336
|
+
python -m build && twine check dist/*
|
|
337
|
+
# 3. 上传
|
|
338
|
+
twine upload dist/* # PyPI
|
|
339
|
+
twine upload --repository-url <私有仓库地址> dist/* # 私有 PyPI 兼容仓库
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
仓库已内置 GitLab / GitHub CI:打 `v*` 标签即自动构建并发布(见 `.github/workflows/release.yml`
|
|
343
|
+
与 `.gitlab-ci.yml`)。
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## 🗺️ 未来规划(Roadmap)
|
|
348
|
+
|
|
349
|
+
- [x] **v0.0.1**:核心签名与验签模块(`generate_sign` / `verify_sign`)
|
|
350
|
+
- [x] **v0.0.2**:对齐 Java 0.0.2——复杂参数(`Map` / `List` / 实体)按 fastjson2 规则 JSON 化
|
|
351
|
+
- [ ] **v0.1.0**:统一 HTTP 请求客户端(`OpenApiClient`),内置重试、超时、自动签名注入
|
|
352
|
+
- [ ] **v0.2.0**:敏感数据加解密工具(`OpenApiCryptoUtil`),支持 AES/RSA
|
|
353
|
+
- [ ] **v0.3.0**:Webhook 回调事件接收与验签标准化处理
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## ⚠️ 最佳实践与注意事项
|
|
358
|
+
|
|
359
|
+
1. **防重放职责分离**:SDK 只校验 `timestamp` / `nonce` 是否存在并参与计算。
|
|
360
|
+
**时间戳误差校验**(如 5 分钟有效期)与 **Nonce 唯一性校验**(如 Redis `setnx`)
|
|
361
|
+
属于网关业务逻辑,请在中间件或装饰器中自行实现。
|
|
362
|
+
2. **空值规则一致**:SDK 会忽略值为 `None` 或空白的参数,请确保两端对"空值不参与签名"达成一致。
|
|
363
|
+
3. **敏感信息保护**:`secret`(AppSecret 或私钥)不应出现在网络请求中,
|
|
364
|
+
应保存在配置中心或密钥管理系统。
|
|
365
|
+
4. **RSA2 密钥长度**:建议至少 2048 位。
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## 📄 License
|
|
370
|
+
|
|
371
|
+
[Apache License 2.0](LICENSE)
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
*如有问题或建议,请联系数据中心架构组。*
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
ynet_sdk/__init__.py,sha256=94MND2iy3pGIUZqXMiyim7aMHRBg9zMDiM80JdgOQok,1244
|
|
2
|
+
ynet_sdk/__main__.py,sha256=ov-v7ze7l9qIpK-SYaebRRkEpQ-V7N7SXdIO0l4OXdw,159
|
|
3
|
+
ynet_sdk/_version.py,sha256=1ElfBrewkkXocbYLZrZ_3oyeI6n7EvOEcSnbee_QP9E,280
|
|
4
|
+
ynet_sdk/cli.py,sha256=4r3S9M1KZ-eSITlRMRChW5mMZ6nxMc0POhom4-ZVry8,5597
|
|
5
|
+
ynet_sdk/exceptions.py,sha256=UMlX77YZrCOgEt3skV9hXdVv_A7v1lK8f_B1TgfdUwY,2106
|
|
6
|
+
ynet_sdk/py.typed,sha256=oKNj2zNf4950lvzY8ayV8cfHh-8-IqBJFyJAcQK17mo,92
|
|
7
|
+
ynet_sdk/common/__init__.py,sha256=EqPboGrNpQxNULLkzZEfXuIStiB8kt-znCqQ8CquqFM,274
|
|
8
|
+
ynet_sdk/common/sign/__init__.py,sha256=v8rPBqpJdl76k1rb70Jpasa0_rKqSWpOscqQf3rKelg,825
|
|
9
|
+
ynet_sdk/common/sign/_algorithms.py,sha256=0rRAieb0rvOzA3S6fBOR3Xs5pT6eIdCNYYv5nCdBzOo,5819
|
|
10
|
+
ynet_sdk/common/sign/_converter.py,sha256=-Jf4xWjduHNgIs7HcxrgjP_6uzRKRbRhZktYDlSmX8k,13370
|
|
11
|
+
ynet_sdk/common/sign/constants.py,sha256=Ae-KrVuwZFwubrL6fkhoz-xOhL-1Hs-LXcGo8YcYZqU,2740
|
|
12
|
+
ynet_sdk/common/sign/open_api_sign.py,sha256=4mQK0AOXAtxcgY5sOvdHoGJ6OaGCrXYcVu-xyuzGmCs,12901
|
|
13
|
+
ynet_sdk_python-0.0.2.dist-info/METADATA,sha256=XyBqWK4I560Ca6WRfN1HL04wWQc60eGiNU0zsxQf47k,15329
|
|
14
|
+
ynet_sdk_python-0.0.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
15
|
+
ynet_sdk_python-0.0.2.dist-info/entry_points.txt,sha256=c7o2urngrocpKVUJu8rfnAjFujEx7ESrdfLdowt5HdE,48
|
|
16
|
+
ynet_sdk_python-0.0.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
17
|
+
ynet_sdk_python-0.0.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|