Python library for Mitake SMS API - 三竹簡訊 Python SDK
Project description
三竹簡訊 Python 函式庫
三竹簡訊 API 的 Python 包裝函式庫,讓您可以透過台灣三竹簡訊服務發送簡訊。
特色
- ✅ 預設 UTF-8 編碼:完美支援中文簡訊,不會出現亂碼
- ✅ 單筆與批次發送:支援單筆與批次簡訊發送
- ✅ 預約發送:支援預約時間發送簡訊
- ✅ 狀態查詢:查詢簡訊發送狀態與帳戶餘額
- ✅ 錯誤處理:完整的錯誤處理機制
- ✅ 易於使用:簡潔的 API 設計
安裝
pip install mitake
快速開始
基本設定
from mitake import MitakeClient
# 方法 1:直接輸入帳號密碼
client = MitakeClient(username="your_username", password="your_password")
# 方法 2:使用環境變數
# 設定 MITAKE_USERNAME 和 MITAKE_PASSWORD 環境變數
client = MitakeClient()
發送單筆簡訊
# 發送中文簡訊(自動使用 UTF-8 編碼,不會有亂碼問題)
result = client.send_sms(
to="0912345678", # 台灣手機號碼
message="你好,我是小海!這是測試訊息 🎉"
)
print(result)
發送批次簡訊
messages = [
{"to": "0912345678", "message": "嗨!這是第一則訊息"},
{"to": "0987654321", "message": "嗨!這是第二則訊息", "message_id": "custom_id_1"},
{
"to": "0966666666",
"message": "這是完整參數的訊息",
"message_id": "full_example",
"send_time": "20241231235900", # YYYYMMDDHHMMSS 格式
"dest_name": "收訊人姓名"
}
]
result = client.send_batch_sms(messages)
print(result)
預約發送
# 預約指定時間發送簡訊
result = client.send_sms(
to="0912345678",
message="這是預約發送的簡訊!",
send_time="2024-12-31 23:59:00" # YYYY-MM-DD HH:MM:SS 格式
)
查詢帳戶餘額
balance = client.query_account_balance()
print(f"帳戶餘額:{balance}")
查詢簡訊狀態
# 查詢已發送簡訊的狀態
status = client.query_message_status(["message_id_1", "message_id_2"])
print(status)
環境變數設定
您可以使用環境變數來設定認證資訊:
export MITAKE_USERNAME="你的帳號"
export MITAKE_PASSWORD="你的密碼"
錯誤處理
from mitake import MitakeClient, MitakeError, AuthenticationError, APIError
try:
client = MitakeClient()
result = client.send_sms("0912345678", "測試訊息")
except AuthenticationError as e:
print(f"認證失敗:{e}")
except APIError as e:
print(f"API 錯誤:{e}")
print(f"狀態碼:{e.status_code}")
print(f"回應內容:{e.response_data}")
except MitakeError as e:
print(f"三竹簡訊錯誤:{e}")
API 方法
send_sms(to, message, message_id=None, send_time=None)
發送單筆簡訊
參數:
to(str): 收訊人手機號碼(台灣格式:09xxxxxxxx)message(str): 簡訊內容message_id(str, 可選): 自訂訊息 IDsend_time(str, 可選): 預約發送時間(YYYY-MM-DD HH:MM:SS 格式)
send_batch_sms(messages)
發送批次簡訊
參數:
messages(List[Dict]): 訊息列表,每個訊息包含:to(str): 收訊人手機號碼(必填)message(str): 簡訊內容(必填)message_id(str, 可選): 自訂訊息 IDsend_time(str, 可選): 預約發送時間(YYYYMMDDHHMMSS 格式)valid_time(str, 可選): 訊息有效時間(YYYYMMDDHHMMSS 格式)dest_name(str, 可選): 收訊人姓名callback_url(str, 可選): 狀態回報網址
query_account_balance()
查詢帳戶餘額
query_message_status(message_ids)
查詢簡訊發送狀態
參數:
message_ids(List[str]): 要查詢的訊息 ID 列表
UTF-8 編碼支援
本函式庫預設使用 UTF-8 編碼,完美支援中文簡訊:
# ✅ 正確:支援中文、表情符號等
client.send_sms("0912345678", "你好!今天天氣真好 ☀️")
# ✅ 正確:支援各種特殊字元
client.send_sms("0912345678", "測試特殊符號:{} [] | ^ ~ 等等")
系統需求
- Python 3.7+
- requests 函式庫
授權條款
MIT License
開發者
使用前請確保您已向三竹資訊申請 API 發送權限,並提供程式發送主機的 IP 位址進行鎖定。
更多 API 詳細資訊請參考:三竹簡訊 API 文件
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 Distribution
mitake-0.9.1.tar.gz
(10.6 kB
view details)
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
mitake-0.9.1-py3-none-any.whl
(14.3 kB
view details)
File details
Details for the file mitake-0.9.1.tar.gz.
File metadata
- Download URL: mitake-0.9.1.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a299c7363dd770ea6212d19404c753e57bc58167093880909e4a59fb957efb5e
|
|
| MD5 |
f44b7ea8d5f6678dd3a2025fdf7f421b
|
|
| BLAKE2b-256 |
c309d9c79cc5901d67cf9f776c030b0f51c349f7009d3347afc33540074d92fa
|
File details
Details for the file mitake-0.9.1-py3-none-any.whl.
File metadata
- Download URL: mitake-0.9.1-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2dd4906301ab1cf13cf3f432ad70aea93545069d57445aeba3ab8b3afa5b1c5
|
|
| MD5 |
4e5dea1f0e4b794ff15f7c1a541e28e8
|
|
| BLAKE2b-256 |
ece40fbec7bb68638d964d5e3095d2723b9d440171ec60fb2a26765362eb193b
|