py_easy_wwtl
微网通联短信发送 Python SDK,提供简单易用的微网通联短信平台 API 交互功能,支持短信发送、签名生成等操作。
功能特性
- 短信发送:支持同步和异步发送短信
- 签名生成:按照微网通联 API 要求生成 SHA256 签名
- 灵活配置:支持通过参数自定义客户端行为
- 响应处理:提供 JSON 数据验证功能
- 同步/异步支持:同时支持同步和异步操作
- 类型提示:完整的类型注解,提供良好的 IDE 支持
安装
使用 pip 安装
pip install py_easy_wwtl
从源码安装
git clone https://gitee.com/guolei19850528/py_easy_wwtl.git
cd py_easy_wwtl
pip install -e .
依赖
- httpx
- py_easy_httpx
快速开始
同步发送短信
from py_easy_wwtl.sms import Sms
# 初始化短信客户端
sms_client = Sms(
account_id="YOUR_ACCOUNT_ID",
password="YOUR_PASSWORD",
product_id="YOUR_PRODUCT_ID"
)
# 发送短信
response = sms_client.send(
phone_nos="13800138000",
content="【测试】这是一条测试短信"
)
print(f"发送结果: {response}")
异步发送短信
import asyncio
from py_easy_wwtl.sms import Sms
async def main():
# 初始化短信客户端
sms_client = Sms(
account_id="YOUR_ACCOUNT_ID",
password="YOUR_PASSWORD",
product_id="YOUR_PRODUCT_ID"
)
# 异步发送短信
response = await sms_client.async_send(
phone_nos="13800138000",
content="【测试】这是一条测试短信"
)
print(f"发送结果: {response}")
asyncio.run(main())
API 文档
函数
sha256_signature(account_id, password, phone_nos, random_digits, timestamp, smms_encrypt_key)
生成 SHA256 签名
- 参数:
account_id: 账号 IDpassword: 密码phone_nos: 手机号,多个手机号用逗号分隔random_digits: 随机数字timestamp: 时间戳smms_encrypt_key: 加密密钥
- 返回:
str: SHA256 签名结果
Sms 类
初始化参数
base_url: API 基础 URL,默认为 "https://api.51welink.com/"account_id: 微网通联账号 IDpassword: 微网通联账号密码product_id: 产品 IDsmms_encrypt_key: 加密密钥,默认为 "SMmsEncryptKey"client_kwargs: 传递给 httpx.Client 的额外参数
方法
send(client=None, phone_nos="", content="", **kwargs): 同步发送短信async_send(client=None, phone_nos="", content="", **kwargs): 异步发送短信
高级用法
自定义客户端配置
from py_easy_wwtl.sms import Sms
# 初始化短信客户端,自定义客户端配置
sms_client = Sms(
account_id="YOUR_ACCOUNT_ID",
password="YOUR_PASSWORD",
product_id="YOUR_PRODUCT_ID",
client_kwargs={
"timeout": 30.0, # 设置超时时间为 30 秒
"headers": {
"User-Agent": "py_easy_wwtl"
}
}
)
# 发送短信
response = sms_client.send(
phone_nos="13800138000",
content="【测试】这是一条测试短信"
)
print(f"发送结果: {response}")
项目结构
py_easy_wwtl/
├── py_easy_wwtl/ # 主包目录
│ ├── __init__.py # 包初始化文件
│ └── sms.py # 短信发送模块
├── README.md # 项目文档
├── setup.py # 安装配置
├── requirements.txt # 依赖列表
├── LICENSE # 许可证文件
└── .gitignore # Git 忽略文件
测试
运行测试:
# 运行测试
python -m pytest
许可证
MIT License
贡献
欢迎提交 Issue 和 Pull Request!
联系方式
- 作者:guolei
- 邮箱:174000902@qq.com
- 项目地址:https://gitee.com/guolei19850528/py_easy_wwtl
致谢
- httpx - 高性能的异步 HTTP 客户端库
- py_easy_httpx - 简化 HTTP 请求的工具包
Metadata
Release files for py-easy-wwtl 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_easy_wwtl-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / py_easy_wwtl-2.0.0-py3-none-any.whl
| Download URL | py_easy_wwtl-2.0.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3c19f17bd325481e63b6d518ffac11461f951daa6c55b0f2c7068e5dedd37a97
|
|
BLAKE2b-256 checksum How to use checksums |
929a144e5c6b10e591a6bf5bea62f6b416c992c5cfd8ad5a6a8fa48f0304db58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.6
|
Security for py-easy-wwtl 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.