Skip to main content

TQ短信验证码API Python客户端

Project description

TQ短信验证码API Python客户端

一个简单易用的TQ短信验证码API Python客户端库。

安装

pip install tq-sms

快速开始

基本使用

from tq_sms import TQSmsClient

# 使用用户名和密码初始化(会自动登录)
client = TQSmsClient(username="您的用户名", password="您的密码")

# 或者使用已有的token
# client = TQSmsClient(token="您的token")

# 获取余额
balance = client.get_wallet()
print(f"余额: {balance['data']['balances']}")

# 获取手机号
phone_result = client.get_phone(channel_id="您的渠道ID")
phone_number = phone_result['data']['mobile']
print(f"获取到手机号: {phone_number}")

# 获取验证码
code_result = client.get_code(channel_id="您的渠道ID", phone_num=phone_number)
if code_result['data']['code']:
    print(f"验证码: {code_result['data']['code']}")

# 如果没获取到验证码,拉黑手机号
else:
    client.blacklist_phone(channel_id="您的渠道ID", phone_no=phone_number)
    print("已拉黑手机号")

高级使用

# 获取验证码(带重试机制)
code = client.get_code_with_retry(
    channel_id="您的渠道ID", 
    phone_num=phone_number, 
    max_retries=50
)

if code:
    print(f"验证码: {code}")
else:
    print("获取验证码失败")
    # 拉黑手机号
    client.blacklist_phone(channel_id="您的渠道ID", phone_no=phone_number)

API 方法

login()

登录获取token(如果初始化时提供了用户名密码会自动调用)

get_wallet()

获取用户余额

get_phone(channel_id, phone_num=None, operator=None, scope=None)

获取手机号

  • channel_id: 渠道ID(必需)
  • phone_num: 指定手机号码(可选)
  • operator: 运营商类型,0=全部,5=虚拟,4=非虚拟(可选)
  • scope: 指定号段,多个号段用逗号隔开(可选)

get_code(channel_id, phone_num)

获取验证码

  • channel_id: 渠道ID(必需)
  • phone_num: 手机号码(必需)

blacklist_phone(channel_id, phone_no)

拉黑手机号码

  • channel_id: 渠道ID(必需)
  • phone_no: 手机号码(必需)

get_code_with_retry(channel_id, phone_num, max_retries=100)

获取验证码(带重试机制)

  • channel_id: 渠道ID(必需)
  • phone_num: 手机号码(必需)
  • max_retries: 最大重试次数,默认100次(可选)

注意事项

  1. 所有API调用均会自动添加1秒休眠,避免请求过于频繁
  2. 网络请求具有自动重试机制,遇到网络错误会无限重试
  3. 建议获取验证码最多重试100次
  4. 如果没有获取到手机号,务必调用拉黑手机号接口
  5. Token具有永久有效性,请妥善保管

错误处理

所有方法在失败时会抛出异常:

  • ValueError: 参数错误
  • Exception: API调用失败

许可证

MIT License

贡献

欢迎提交Issue和Pull Request。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tq_share_sms-1.0.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tq_share_sms-1.0.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file tq_share_sms-1.0.0.tar.gz.

File metadata

  • Download URL: tq_share_sms-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for tq_share_sms-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4585a5ff28e4f77417f455ee063a4cb36e6f4cc6bd1bb95cbc66b1f68ff88812
MD5 39b0e8eeffdd94c6807f04532c8f3e31
BLAKE2b-256 8001b0ac0687ab4f824ff832e96af18231dca2284d077c1c31fd1f6e2bfd38ec

See more details on using hashes here.

File details

Details for the file tq_share_sms-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tq_share_sms-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for tq_share_sms-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e23e55a17d767e21916f608912e4fda62da77e76c34e0c54d7c7b207a3358737
MD5 e7114817cf9e2f5165f4abf66b98406b
BLAKE2b-256 b01f06dd4e8f2427897a38739fa71f448fdaedab77513db369fda61cb1f01619

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page