微网通联短信发送 Python SDK,提供简单易用的微网通联短信平台 API 交互功能,支持短信发送、签名生成等操作。
Project description
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 请求的工具包
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_easy_wwtl-2.0.0-py3-none-any.whl.
File metadata
- Download URL: py_easy_wwtl-2.0.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c19f17bd325481e63b6d518ffac11461f951daa6c55b0f2c7068e5dedd37a97
|
|
| MD5 |
b4d566a600128d46a75896f4ee74e528
|
|
| BLAKE2b-256 |
929a144e5c6b10e591a6bf5bea62f6b416c992c5cfd8ad5a6a8fa48f0304db58
|