mirror of
https://github.com/WhaleFell/SMSBoom.git
synced 2026-07-04 19:06:49 +08:00
feat: 添加代理,随机UA
1. 通过代理调用短信接口. 2. 随机的User-Agent. 3. 去除循环模式, 新增"设置执行次数"模式, 参数"--frequency | -t", 用于指定要循环执行的次数.
This commit is contained in:
19
utils/req.py
19
utils/req.py
@@ -5,7 +5,7 @@ from httpx import Limits
|
||||
from typing import Union, List
|
||||
import asyncio
|
||||
|
||||
from utils import default_header
|
||||
from utils import default_header_user_agent
|
||||
from utils.models import API
|
||||
from utils.log import logger
|
||||
|
||||
@@ -20,7 +20,7 @@ def reqAPI(api: API, client: Union[httpx.Client, httpx.AsyncClient]) -> httpx.Re
|
||||
return resp
|
||||
|
||||
|
||||
def reqFunc(api: Union[API, str], phone: Union[tuple, str]) -> bool:
|
||||
def reqFunc(api: Union[API, str], phone: Union[tuple, str], proxy: dict) -> bool:
|
||||
"""请求接口方法"""
|
||||
# 多手机号支持
|
||||
if isinstance(phone, tuple):
|
||||
@@ -28,27 +28,27 @@ def reqFunc(api: Union[API, str], phone: Union[tuple, str]) -> bool:
|
||||
else:
|
||||
phone_lst = [phone]
|
||||
|
||||
with httpx.Client(headers=default_header, verify=False) as client:
|
||||
with httpx.Client(headers=default_header_user_agent(), verify=False, proxies=proxy) as client:
|
||||
for ph in phone_lst:
|
||||
try:
|
||||
if isinstance(api, API):
|
||||
api = api.handle_API(ph)
|
||||
resp = reqAPI(api, client)
|
||||
logger.info(f"{api.desc}-{resp.text[:30]}")
|
||||
logger.info(f"{api.desc}-{resp.text[:30]}-当前使用代理:{proxy['all://']}")
|
||||
else:
|
||||
api = api.replace("[phone]", ph).replace(" ", "").replace('\n', '').replace('\r', '')
|
||||
resp = client.get(url=api, headers=default_header)
|
||||
logger.info(f"GETAPI接口-{resp.text[:30]}")
|
||||
logger.info(f"GETAPI接口-{resp.text[:30]}-当前使用代理:{proxy['all://']}")
|
||||
return True
|
||||
except httpx.HTTPError as why:
|
||||
logger.error(f"请求失败{why}")
|
||||
logger.error(f"请求失败{why}-当前使用代理:{proxy['all://']}")
|
||||
return False
|
||||
|
||||
|
||||
async def asyncReqs(src: Union[API, str], phone: Union[tuple, str], semaphore):
|
||||
"""异步请求方法
|
||||
:param:
|
||||
:return:
|
||||
:param:
|
||||
:return:
|
||||
"""
|
||||
# 多手机号支持
|
||||
if isinstance(phone, tuple):
|
||||
@@ -94,8 +94,7 @@ def callback(result):
|
||||
logger.info(f"请求结果:{log.text[:30]}")
|
||||
|
||||
|
||||
async def runAsync(apis: List[Union[API,str]], phone: Union[tuple, str]):
|
||||
|
||||
async def runAsync(apis: List[Union[API, str]], phone: Union[tuple, str]):
|
||||
tasks = []
|
||||
|
||||
for api in apis:
|
||||
|
||||
Reference in New Issue
Block a user