py-lmobile-toolkit 1.0.0__tar.gz
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.
- py_lmobile_toolkit-1.0.0/LICENSE +21 -0
- py_lmobile_toolkit-1.0.0/PKG-INFO +326 -0
- py_lmobile_toolkit-1.0.0/README.md +273 -0
- py_lmobile_toolkit-1.0.0/pyproject.toml +45 -0
- py_lmobile_toolkit-1.0.0/setup.cfg +4 -0
- py_lmobile_toolkit-1.0.0/src/py_lmobile_toolkit/__init__.py +24 -0
- py_lmobile_toolkit-1.0.0/src/py_lmobile_toolkit/sms/__init__.py +238 -0
- py_lmobile_toolkit-1.0.0/src/py_lmobile_toolkit/sms/responses.py +68 -0
- py_lmobile_toolkit-1.0.0/src/py_lmobile_toolkit/sms/utils.py +273 -0
- py_lmobile_toolkit-1.0.0/src/py_lmobile_toolkit.egg-info/PKG-INFO +326 -0
- py_lmobile_toolkit-1.0.0/src/py_lmobile_toolkit.egg-info/SOURCES.txt +12 -0
- py_lmobile_toolkit-1.0.0/src/py_lmobile_toolkit.egg-info/dependency_links.txt +1 -0
- py_lmobile_toolkit-1.0.0/src/py_lmobile_toolkit.egg-info/requires.txt +5 -0
- py_lmobile_toolkit-1.0.0/src/py_lmobile_toolkit.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 郭磊
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py-lmobile-toolkit
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: 微网通联(51welink)短信服务 Python SDK,提供同步和异步两种发送方式,支持请求签名认证
|
|
5
|
+
Author-email: Guolei <174000902@qq.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 郭磊
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://gitee.com/guolei19850528/py_lmobile_toolkit
|
|
29
|
+
Project-URL: Repository, https://gitee.com/guolei19850528/py_lmobile_toolkit.git
|
|
30
|
+
Project-URL: Documentation, https://www.lmobile.cn/ApiPages/index.html
|
|
31
|
+
Keywords: lmobile,python,client,api,微网通联,短信,sms,51welink
|
|
32
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
33
|
+
Classifier: Development Status :: 4 - Beta
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
40
|
+
Classifier: Operating System :: OS Independent
|
|
41
|
+
Classifier: Topic :: Communications
|
|
42
|
+
Classifier: Topic :: Communications :: Telephony
|
|
43
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
44
|
+
Requires-Python: >=3.10
|
|
45
|
+
Description-Content-Type: text/markdown
|
|
46
|
+
License-File: LICENSE
|
|
47
|
+
Requires-Dist: httpx>=0.27.0
|
|
48
|
+
Requires-Dist: pydantic>=2.0
|
|
49
|
+
Requires-Dist: jsonpath-ng>=1.5.3
|
|
50
|
+
Requires-Dist: jsonschema>=4.21.0
|
|
51
|
+
Requires-Dist: py-httpx-toolkit>=1.0.1
|
|
52
|
+
Dynamic: license-file
|
|
53
|
+
|
|
54
|
+
# py-lmobile-toolkit
|
|
55
|
+
|
|
56
|
+
微网通联(51welink)短信服务 Python SDK,提供同步和异步两种发送方式,支持请求签名认证机制。
|
|
57
|
+
|
|
58
|
+
## 作者
|
|
59
|
+
|
|
60
|
+
**Guolei**
|
|
61
|
+
|
|
62
|
+
- 邮箱:174000902@qq.com
|
|
63
|
+
|
|
64
|
+
## 项目主页
|
|
65
|
+
|
|
66
|
+
- **Gitee**: https://gitee.com/guolei19850528/py_lmobile_toolkit
|
|
67
|
+
- **官方 API 文档**: https://www.lmobile.cn/ApiPages/index.html
|
|
68
|
+
|
|
69
|
+
## 功能特性
|
|
70
|
+
|
|
71
|
+
- ✅ 同步短信发送接口
|
|
72
|
+
- ✅ 异步短信发送接口
|
|
73
|
+
- ✅ 请求签名认证机制(SHA256)
|
|
74
|
+
- ✅ 响应数据模型验证(Pydantic)
|
|
75
|
+
- ✅ 完整的工具函数支持
|
|
76
|
+
|
|
77
|
+
## 安装
|
|
78
|
+
|
|
79
|
+
使用 `uv` 安装:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
uv add py-lmobile-toolkit
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
或从pip安装:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install py-lmobile-toolkit
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 依赖包
|
|
92
|
+
|
|
93
|
+
| 依赖 | 版本要求 | 说明 |
|
|
94
|
+
|------|----------|------|
|
|
95
|
+
| httpx | >=0.27.0 | HTTP 客户端 |
|
|
96
|
+
| pydantic | >=2.0 | 数据验证 |
|
|
97
|
+
| jsonpath-ng | >=1.5.3 | JSONPath 查询 |
|
|
98
|
+
| jsonschema | >=4.21.0 | JSON Schema 校验 |
|
|
99
|
+
| py-httpx-toolkit | >=1.0.1 | HTTP 工具封装 |
|
|
100
|
+
|
|
101
|
+
## API 接口
|
|
102
|
+
|
|
103
|
+
### Sms 类
|
|
104
|
+
|
|
105
|
+
短信客户端核心类,提供同步和异步发送接口。
|
|
106
|
+
|
|
107
|
+
#### 初始化
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from py_lmobile_toolkit.sms import Sms
|
|
111
|
+
|
|
112
|
+
sms = Sms(
|
|
113
|
+
account_id="your_account",
|
|
114
|
+
password="your_password",
|
|
115
|
+
product_id="your_product"
|
|
116
|
+
)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**参数说明**:
|
|
120
|
+
|
|
121
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
122
|
+
|------|------|--------|------|
|
|
123
|
+
| base_url | str | https://api.51welink.com/ | API 服务器地址 |
|
|
124
|
+
| account_id | str | None | 账号 ID |
|
|
125
|
+
| password | str | None | 账号密码 |
|
|
126
|
+
| product_id | str/int | None | 产品 ID |
|
|
127
|
+
| smms_encrypt_key | str | SMmsEncryptKey | 加密密钥 |
|
|
128
|
+
| client_kwargs | dict | None | httpx.Client 配置 |
|
|
129
|
+
|
|
130
|
+
#### 同步发送
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
response = sms.send(
|
|
134
|
+
phone_nos="13800138000",
|
|
135
|
+
content="您的验证码是:123456"
|
|
136
|
+
)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### 异步发送
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
response = await sms.async_send(
|
|
143
|
+
phone_nos=["13800138000", "13900139000"],
|
|
144
|
+
content="测试短信"
|
|
145
|
+
)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**参数说明**:
|
|
149
|
+
|
|
150
|
+
| 参数 | 类型 | 说明 |
|
|
151
|
+
|------|------|------|
|
|
152
|
+
| phone_nos | str/list/tuple | 手机号码,支持单个或多个 |
|
|
153
|
+
| content | str | 短信内容 |
|
|
154
|
+
| client | httpx.Client/AsyncClient | 可选的客户端实例 |
|
|
155
|
+
| client_kwargs | dict | 客户端配置 |
|
|
156
|
+
|
|
157
|
+
## Utils 工具函数
|
|
158
|
+
|
|
159
|
+
### 时间戳生成
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from py_lmobile_toolkit.sms.utils import timestamp
|
|
163
|
+
|
|
164
|
+
ts = timestamp() # 返回毫秒级时间戳
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### 随机数生成
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from py_lmobile_toolkit.sms.utils import random_digits
|
|
171
|
+
|
|
172
|
+
digits = random_digits(length=10) # 生成10位随机数
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### SHA256 签名生成
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from py_lmobile_toolkit.sms.utils import sha256_signature
|
|
179
|
+
|
|
180
|
+
signature = sha256_signature(
|
|
181
|
+
account_id="dljtwy00",
|
|
182
|
+
password="g07KjuLN1",
|
|
183
|
+
phone_nos="13800138000",
|
|
184
|
+
random_digits="1234567890",
|
|
185
|
+
timestamp="1630000000000",
|
|
186
|
+
smms_encrypt_key="SMmsEncryptKey"
|
|
187
|
+
)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### JSONPath 查询
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
from py_lmobile_toolkit.sms.utils import json_find_first
|
|
194
|
+
|
|
195
|
+
data = {"store": {"books": [{"title": "Python"}, {"title": "Java"}]}}
|
|
196
|
+
title = json_find_first("$.store.books[0].title", data) # 返回 "Python"
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### JSON Schema 校验
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from py_lmobile_toolkit.sms.utils import json_is_valid
|
|
203
|
+
|
|
204
|
+
schema = {"type": "object", "properties": {"name": {"type": "string"}}}
|
|
205
|
+
valid = json_is_valid(schema, {"name": "test"}) # 返回 True
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### 响应模型转换
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
from py_lmobile_toolkit.sms.utils import build_success_instance
|
|
212
|
+
|
|
213
|
+
result = build_success_instance(response) # 转换为 Success 模型
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## 响应模型
|
|
217
|
+
|
|
218
|
+
### Base
|
|
219
|
+
|
|
220
|
+
所有响应的基类:
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
from py_lmobile_toolkit.sms.responses import Base
|
|
224
|
+
|
|
225
|
+
class Base(BaseModel):
|
|
226
|
+
Result: str # 错误码,succ 表示成功
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Success
|
|
230
|
+
|
|
231
|
+
成功响应模型:
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
from py_lmobile_toolkit.sms.responses import Success
|
|
235
|
+
|
|
236
|
+
result = Success(Result="succ")
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## 使用示例
|
|
240
|
+
|
|
241
|
+
### 同步发送示例
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
from py_lmobile_toolkit.sms import Sms
|
|
245
|
+
|
|
246
|
+
# 初始化客户端
|
|
247
|
+
sms = Sms(
|
|
248
|
+
account_id="your_account",
|
|
249
|
+
password="your_password",
|
|
250
|
+
product_id="your_product"
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
# 发送单条短信
|
|
254
|
+
response = sms.send(
|
|
255
|
+
phone_nos="13800138000",
|
|
256
|
+
content="您的验证码是:123456"
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
# 解析响应
|
|
260
|
+
data = response.json()
|
|
261
|
+
print(f"发送结果: {data.get('Result')}")
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### 异步发送示例
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
import asyncio
|
|
268
|
+
from py_lmobile_toolkit.sms import Sms
|
|
269
|
+
|
|
270
|
+
async def main():
|
|
271
|
+
# 初始化客户端
|
|
272
|
+
sms = Sms(
|
|
273
|
+
account_id="your_account",
|
|
274
|
+
password="your_password",
|
|
275
|
+
product_id="your_product"
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
# 批量发送短信
|
|
279
|
+
response = await sms.async_send(
|
|
280
|
+
phone_nos=["13800138000", "13900139000", "13700137000"],
|
|
281
|
+
content="【通知】您的订单已发货"
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
# 解析响应
|
|
285
|
+
data = response.json()
|
|
286
|
+
print(f"发送结果: {data.get('Result')}")
|
|
287
|
+
|
|
288
|
+
asyncio.run(main())
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### 签名验证示例
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
from py_lmobile_toolkit.sms.utils import sha256_signature, timestamp, random_digits
|
|
295
|
+
|
|
296
|
+
# 生成签名所需参数
|
|
297
|
+
ts = timestamp()
|
|
298
|
+
digits = random_digits()
|
|
299
|
+
|
|
300
|
+
# 生成签名
|
|
301
|
+
signature = sha256_signature(
|
|
302
|
+
account_id="your_account",
|
|
303
|
+
password="your_password",
|
|
304
|
+
phone_nos="13800138000",
|
|
305
|
+
random_digits=digits,
|
|
306
|
+
timestamp=ts,
|
|
307
|
+
smms_encrypt_key="SMmsEncryptKey"
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
print(f"生成的签名: {signature}")
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## 签名生成算法
|
|
314
|
+
|
|
315
|
+
签名生成遵循以下步骤:
|
|
316
|
+
|
|
317
|
+
1. **密码 MD5 加密**:`MD5(password + smms_encrypt_key)`,结果转大写
|
|
318
|
+
2. **参数拼接**(按顺序):
|
|
319
|
+
```
|
|
320
|
+
AccountId={account_id}&PhoneNos={first_phone}&Password={md5_password}&Random={random}&Timestamp={timestamp}
|
|
321
|
+
```
|
|
322
|
+
3. **SHA256 加密**:对拼接后的字符串进行 SHA256 哈希
|
|
323
|
+
|
|
324
|
+
## 许可证
|
|
325
|
+
|
|
326
|
+
MIT License
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
# py-lmobile-toolkit
|
|
2
|
+
|
|
3
|
+
微网通联(51welink)短信服务 Python SDK,提供同步和异步两种发送方式,支持请求签名认证机制。
|
|
4
|
+
|
|
5
|
+
## 作者
|
|
6
|
+
|
|
7
|
+
**Guolei**
|
|
8
|
+
|
|
9
|
+
- 邮箱:174000902@qq.com
|
|
10
|
+
|
|
11
|
+
## 项目主页
|
|
12
|
+
|
|
13
|
+
- **Gitee**: https://gitee.com/guolei19850528/py_lmobile_toolkit
|
|
14
|
+
- **官方 API 文档**: https://www.lmobile.cn/ApiPages/index.html
|
|
15
|
+
|
|
16
|
+
## 功能特性
|
|
17
|
+
|
|
18
|
+
- ✅ 同步短信发送接口
|
|
19
|
+
- ✅ 异步短信发送接口
|
|
20
|
+
- ✅ 请求签名认证机制(SHA256)
|
|
21
|
+
- ✅ 响应数据模型验证(Pydantic)
|
|
22
|
+
- ✅ 完整的工具函数支持
|
|
23
|
+
|
|
24
|
+
## 安装
|
|
25
|
+
|
|
26
|
+
使用 `uv` 安装:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
uv add py-lmobile-toolkit
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
或从pip安装:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install py-lmobile-toolkit
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 依赖包
|
|
39
|
+
|
|
40
|
+
| 依赖 | 版本要求 | 说明 |
|
|
41
|
+
|------|----------|------|
|
|
42
|
+
| httpx | >=0.27.0 | HTTP 客户端 |
|
|
43
|
+
| pydantic | >=2.0 | 数据验证 |
|
|
44
|
+
| jsonpath-ng | >=1.5.3 | JSONPath 查询 |
|
|
45
|
+
| jsonschema | >=4.21.0 | JSON Schema 校验 |
|
|
46
|
+
| py-httpx-toolkit | >=1.0.1 | HTTP 工具封装 |
|
|
47
|
+
|
|
48
|
+
## API 接口
|
|
49
|
+
|
|
50
|
+
### Sms 类
|
|
51
|
+
|
|
52
|
+
短信客户端核心类,提供同步和异步发送接口。
|
|
53
|
+
|
|
54
|
+
#### 初始化
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from py_lmobile_toolkit.sms import Sms
|
|
58
|
+
|
|
59
|
+
sms = Sms(
|
|
60
|
+
account_id="your_account",
|
|
61
|
+
password="your_password",
|
|
62
|
+
product_id="your_product"
|
|
63
|
+
)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**参数说明**:
|
|
67
|
+
|
|
68
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
69
|
+
|------|------|--------|------|
|
|
70
|
+
| base_url | str | https://api.51welink.com/ | API 服务器地址 |
|
|
71
|
+
| account_id | str | None | 账号 ID |
|
|
72
|
+
| password | str | None | 账号密码 |
|
|
73
|
+
| product_id | str/int | None | 产品 ID |
|
|
74
|
+
| smms_encrypt_key | str | SMmsEncryptKey | 加密密钥 |
|
|
75
|
+
| client_kwargs | dict | None | httpx.Client 配置 |
|
|
76
|
+
|
|
77
|
+
#### 同步发送
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
response = sms.send(
|
|
81
|
+
phone_nos="13800138000",
|
|
82
|
+
content="您的验证码是:123456"
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### 异步发送
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
response = await sms.async_send(
|
|
90
|
+
phone_nos=["13800138000", "13900139000"],
|
|
91
|
+
content="测试短信"
|
|
92
|
+
)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**参数说明**:
|
|
96
|
+
|
|
97
|
+
| 参数 | 类型 | 说明 |
|
|
98
|
+
|------|------|------|
|
|
99
|
+
| phone_nos | str/list/tuple | 手机号码,支持单个或多个 |
|
|
100
|
+
| content | str | 短信内容 |
|
|
101
|
+
| client | httpx.Client/AsyncClient | 可选的客户端实例 |
|
|
102
|
+
| client_kwargs | dict | 客户端配置 |
|
|
103
|
+
|
|
104
|
+
## Utils 工具函数
|
|
105
|
+
|
|
106
|
+
### 时间戳生成
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from py_lmobile_toolkit.sms.utils import timestamp
|
|
110
|
+
|
|
111
|
+
ts = timestamp() # 返回毫秒级时间戳
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 随机数生成
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from py_lmobile_toolkit.sms.utils import random_digits
|
|
118
|
+
|
|
119
|
+
digits = random_digits(length=10) # 生成10位随机数
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### SHA256 签名生成
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from py_lmobile_toolkit.sms.utils import sha256_signature
|
|
126
|
+
|
|
127
|
+
signature = sha256_signature(
|
|
128
|
+
account_id="dljtwy00",
|
|
129
|
+
password="g07KjuLN1",
|
|
130
|
+
phone_nos="13800138000",
|
|
131
|
+
random_digits="1234567890",
|
|
132
|
+
timestamp="1630000000000",
|
|
133
|
+
smms_encrypt_key="SMmsEncryptKey"
|
|
134
|
+
)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### JSONPath 查询
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from py_lmobile_toolkit.sms.utils import json_find_first
|
|
141
|
+
|
|
142
|
+
data = {"store": {"books": [{"title": "Python"}, {"title": "Java"}]}}
|
|
143
|
+
title = json_find_first("$.store.books[0].title", data) # 返回 "Python"
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### JSON Schema 校验
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from py_lmobile_toolkit.sms.utils import json_is_valid
|
|
150
|
+
|
|
151
|
+
schema = {"type": "object", "properties": {"name": {"type": "string"}}}
|
|
152
|
+
valid = json_is_valid(schema, {"name": "test"}) # 返回 True
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 响应模型转换
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
from py_lmobile_toolkit.sms.utils import build_success_instance
|
|
159
|
+
|
|
160
|
+
result = build_success_instance(response) # 转换为 Success 模型
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## 响应模型
|
|
164
|
+
|
|
165
|
+
### Base
|
|
166
|
+
|
|
167
|
+
所有响应的基类:
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from py_lmobile_toolkit.sms.responses import Base
|
|
171
|
+
|
|
172
|
+
class Base(BaseModel):
|
|
173
|
+
Result: str # 错误码,succ 表示成功
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Success
|
|
177
|
+
|
|
178
|
+
成功响应模型:
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from py_lmobile_toolkit.sms.responses import Success
|
|
182
|
+
|
|
183
|
+
result = Success(Result="succ")
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## 使用示例
|
|
187
|
+
|
|
188
|
+
### 同步发送示例
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
from py_lmobile_toolkit.sms import Sms
|
|
192
|
+
|
|
193
|
+
# 初始化客户端
|
|
194
|
+
sms = Sms(
|
|
195
|
+
account_id="your_account",
|
|
196
|
+
password="your_password",
|
|
197
|
+
product_id="your_product"
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
# 发送单条短信
|
|
201
|
+
response = sms.send(
|
|
202
|
+
phone_nos="13800138000",
|
|
203
|
+
content="您的验证码是:123456"
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
# 解析响应
|
|
207
|
+
data = response.json()
|
|
208
|
+
print(f"发送结果: {data.get('Result')}")
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### 异步发送示例
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
import asyncio
|
|
215
|
+
from py_lmobile_toolkit.sms import Sms
|
|
216
|
+
|
|
217
|
+
async def main():
|
|
218
|
+
# 初始化客户端
|
|
219
|
+
sms = Sms(
|
|
220
|
+
account_id="your_account",
|
|
221
|
+
password="your_password",
|
|
222
|
+
product_id="your_product"
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
# 批量发送短信
|
|
226
|
+
response = await sms.async_send(
|
|
227
|
+
phone_nos=["13800138000", "13900139000", "13700137000"],
|
|
228
|
+
content="【通知】您的订单已发货"
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
# 解析响应
|
|
232
|
+
data = response.json()
|
|
233
|
+
print(f"发送结果: {data.get('Result')}")
|
|
234
|
+
|
|
235
|
+
asyncio.run(main())
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### 签名验证示例
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
from py_lmobile_toolkit.sms.utils import sha256_signature, timestamp, random_digits
|
|
242
|
+
|
|
243
|
+
# 生成签名所需参数
|
|
244
|
+
ts = timestamp()
|
|
245
|
+
digits = random_digits()
|
|
246
|
+
|
|
247
|
+
# 生成签名
|
|
248
|
+
signature = sha256_signature(
|
|
249
|
+
account_id="your_account",
|
|
250
|
+
password="your_password",
|
|
251
|
+
phone_nos="13800138000",
|
|
252
|
+
random_digits=digits,
|
|
253
|
+
timestamp=ts,
|
|
254
|
+
smms_encrypt_key="SMmsEncryptKey"
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
print(f"生成的签名: {signature}")
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## 签名生成算法
|
|
261
|
+
|
|
262
|
+
签名生成遵循以下步骤:
|
|
263
|
+
|
|
264
|
+
1. **密码 MD5 加密**:`MD5(password + smms_encrypt_key)`,结果转大写
|
|
265
|
+
2. **参数拼接**(按顺序):
|
|
266
|
+
```
|
|
267
|
+
AccountId={account_id}&PhoneNos={first_phone}&Password={md5_password}&Random={random}&Timestamp={timestamp}
|
|
268
|
+
```
|
|
269
|
+
3. **SHA256 加密**:对拼接后的字符串进行 SHA256 哈希
|
|
270
|
+
|
|
271
|
+
## 许可证
|
|
272
|
+
|
|
273
|
+
MIT License
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "py-lmobile-toolkit"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
requires-python = ">=3.10"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Guolei", email = "174000902@qq.com" }
|
|
11
|
+
]
|
|
12
|
+
description = "微网通联(51welink)短信服务 Python SDK,提供同步和异步两种发送方式,支持请求签名认证"
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
license = { file = "LICENSE" }
|
|
15
|
+
keywords = ["lmobile", "python", "client", "api", "微网通联", "短信", "sms", "51welink"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Operating System :: OS Independent",
|
|
26
|
+
"Topic :: Communications",
|
|
27
|
+
"Topic :: Communications :: Telephony",
|
|
28
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
29
|
+
]
|
|
30
|
+
dependencies = [
|
|
31
|
+
"httpx>=0.27.0",
|
|
32
|
+
"pydantic>=2.0",
|
|
33
|
+
"jsonpath-ng>=1.5.3",
|
|
34
|
+
"jsonschema>=4.21.0",
|
|
35
|
+
"py-httpx-toolkit>=1.0.1",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
"Homepage" = "https://gitee.com/guolei19850528/py_lmobile_toolkit"
|
|
41
|
+
"Repository" = "https://gitee.com/guolei19850528/py_lmobile_toolkit.git"
|
|
42
|
+
"Documentation" = "https://www.lmobile.cn/ApiPages/index.html"
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.packages.find]
|
|
45
|
+
where = ["src"]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
py_lmobile - 微网通联短信服务 Python SDK
|
|
5
|
+
|
|
6
|
+
本模块提供接入微网通联(51welink)短信服务的完整功能,包括:
|
|
7
|
+
- 同步和异步短信发送能力
|
|
8
|
+
- 请求签名认证机制
|
|
9
|
+
- 响应数据模型
|
|
10
|
+
- 工具函数支持
|
|
11
|
+
|
|
12
|
+
主要组件:
|
|
13
|
+
- Sms: 短信客户端核心类,提供同步和异步发送接口
|
|
14
|
+
- utils: 工具函数模块,包含签名生成、时间戳等功能
|
|
15
|
+
- responses: 响应数据模型,用于标准化API响应
|
|
16
|
+
|
|
17
|
+
官方 API 文档:https://www.lmobile.cn/ApiPages/index.html
|
|
18
|
+
|
|
19
|
+
使用示例:
|
|
20
|
+
from py_lmobile.sms import Sms
|
|
21
|
+
|
|
22
|
+
sms = Sms(account_id="your_account", password="your_password", product_id="your_product")
|
|
23
|
+
response = sms.send(phone_nos="13800138000", content="您的验证码是:123456")
|
|
24
|
+
"""
|