python 短信接码平台API
2024年4月17日大约 2 分钟约 722 字
"""
接码平台
"""
import requests
import time
from typing import Union
class SmsBase():
"""短信接码抽象类
Attributes:
name (str): 服务商名称
"""
name = ''
class TqSms:
"""天启接码 https://web.tqsms.xyz/
客服唯一土豆 https://lkcpt.me/jimZZZ
"""
name = '天启'
project_dict = {
'小红书': [
'1247966482608951299', # 渠道7 32888-2VRV5EJC9N 0.33
'1334525649104146439', # 渠道7 32888-IGKTXIZ3PP 0.42
'1248011236356919309', # 渠道7 二次 61372-2VRV5EJC9N 0.33
'1343798615805530122', # 渠道7 二次 61372-JJSZB4SND4 0.45
'1331345081352851459', # 渠道7 二次 61372-5MN8GALYA8 0.51
'1331289572402794509', # 渠道7 二次 61372-5UGGW0RL7E 0.51
'1360694836990054411', # 渠道10 二次
'1277606887105236996', # 渠道10 二次
'1287060845532024847', # 渠道10
'1317869655292907522', # 渠道10
'1360615660555603974', # 渠道10 叶子
],
}
token = '' # 一次获取永久有效
def get_token(self):
"""获得api使用的token"""
url = 'https://api.tqsms.xyz/api/login?username=xxx&password=xxx'
token = requests.get(url).json()['data']['token']
print(token)
return token
def get_money(self):
"""获取用户余额"""
url = 'https://api.tqsms.xyz/api/getWallet?token=' + self.token
money = requests.get(url).json()['data']['balances']
return money
def get_phone(self, project_name: str, phone: str = '', channel_id = '', is_actual: Union[bool, None] = None) -> dict:
"""
Args:
project_name (str): 项目名称,比如 小红书
phone (str): 指定具体手机号
is_actual (bool,None): 是否需要实卡
Returns:
dict: {'success': True, 'phone': '', 'channel_id': '', 'server_name': '天启', 'errmsg': ''}
"""
# 如果指定具体手机号
if phone:
if not channel_id:
return {'success': False, 'errmsg': 'channel_id必填'}
if channel_id not in self.project_dict[project_name]:
return {'success': False, 'errmsg': 'channel_id已失效,无法使用'}
params = {
'token': self.token,
'channelId': channel_id,
'phoneNum': phone,
'operator': 4 if is_actual else 0
}
response = requests.get('https://api.tqsms.xyz/api/getPhone', params=params)
if response.status_code >= 500:
return {'success': False, 'errmsg': f'{response.status_code} 错误'}
result = response.json()
if result['success']:
return {'success': True, 'phone': result['data']['mobile'], 'channel_id': channel_id, 'server_name': '天启'}
else:
return {'success': False, 'errmsg': result['msg']}
# 没有指定手机号的情况下
for channel_id in self.project_dict[project_name]:
params = {
'token': self.token,
'channelId': channel_id,
'operator': 4 if is_actual else 0
}
response = requests.get('https://api.tqsms.xyz/api/getPhone', params=params)
if response.status_code >= 500:
return {'success': False, 'errmsg': f'{response.status_code} 错误'}
result = response.json()
if result['success']:
return {'success': True, 'phone': result['data']['mobile'], 'channel_id': channel_id, 'server_name': '天启'}
elif result['status'] == 500: # '渠道暂时无手机号,请稍等5S再试或更换渠道'
continue
else:
return {'success': False, 'errmsg': result['msg']}
return {'success': False, 'errmsg': '所有渠道都暂时无手机号'}
def get_sms_code(self, channel_id: str, phone: str) -> dict:
"""获取短信验证码
Args:
channel_id: 信道id
phone: 手机号
Returns:
dict: {'success': True, 'code': '1234', 'errmsg': ''}
"""
params = {
'token': self.token,
'channelId': channel_id,
'phoneNum': phone
}
for i in range(50):
response = requests.get('https://api.tqsms.xyz/api/getCode', params)
if response.status_code >= 500:
return {'success': False, 'errmsg': f'{response.status_code} 错误'}
result = response.json()
if result['success'] is False:
return {'success': False, 'errmsg': result['msg']}
# 如果获取到验证码,则返回验证码
if result['data']['code']:
return {'success': True, 'code': result['data']['code']}
time.sleep(2)
return {'success': False, 'errmsg': '未接收到验证码'}
def set_blacklist(self, phone: str, channel_id: str):
"""拉黑手机号"""
params = {
'token': self.token,
'channelId': channel_id,
'phoneNo': phone,
'type': 0 # 固定数
}
response = requests.get("https://api.tqsms.xyz/api/phoneCollectAdd", params=params)
class TxSms:
"""他信 http://a.my531.com/
"""
name = '他信'
class HhlSms:
"""火狐狸 https://web.firefox.fun/
"""
name = '火狐狸'
class MgSms:
"""木瓜 https://richpva.com/"""
name = '木瓜'
class ManSms:
"""man https://sms-man.com/"""
name = 'man'
class YmSms:
"""YM https://jm00.top/"""
name = 'YM'
class FgSms:
"""飞光码 https://jm00.top/"""
name = '飞光'
class HzSms:
"""豪猪 http://my.haozhuma.com/"""
name = '豪猪'
class PPSms:
"""泡泡码 http://paopaoma.com/ """
name = '泡泡'
class YmySms:
"""玉米云 https://www.ymsms.xyz/ """
name = '玉米云'
"""快客接码API
首页:https://www.kuaikejm.app/kk/index.html
"""
sms_class_dict = {'天启': TqSms}
if __name__ == '__main__':
tq = TqSms()
phone = tq.get_phone('小红书')
print(phone)
# sms = tq.get_sms_code('小红书', phone)