mirror of
https://github.com/WhaleFell/SMSBoom.git
synced 2026-05-05 16:23:06 +08:00
Merge branch 'master' into master
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
import random
|
||||
|
||||
USER_AGENT_LIST = [
|
||||
|
||||
@@ -4,15 +4,19 @@ from pydantic import BaseModel
|
||||
from typing import Union, Optional
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
from utils import default_header_user_agent
|
||||
|
||||
|
||||
|
||||
class API(BaseModel):
|
||||
"""处理自定义 API 数据"""
|
||||
desc: str = "Default"
|
||||
url: str
|
||||
method: str = "GET"
|
||||
|
||||
header: Optional[Union[str, dict]] = default_header_user_agent()
|
||||
|
||||
data: Optional[Union[str, dict]]
|
||||
|
||||
def replace_data(self, content: Union[str, dict], phone: str) -> str:
|
||||
@@ -31,7 +35,8 @@ class API(BaseModel):
|
||||
"""返回整数字符串时间戳"""
|
||||
return str(int(datetime.now().timestamp()))
|
||||
|
||||
def handle_API(self, phone: str = None):
|
||||
|
||||
def handle_API(self, phone: str=None):
|
||||
""" 传入手机号处理 API
|
||||
:param API: one API basemodel
|
||||
:return: API basemodel
|
||||
|
||||
21
utils/req.py
21
utils/req.py
@@ -5,7 +5,9 @@ from httpx import Limits
|
||||
from typing import Union, List
|
||||
import asyncio
|
||||
|
||||
|
||||
from utils import default_header_user_agent
|
||||
|
||||
from utils.models import API
|
||||
from utils.log import logger
|
||||
|
||||
@@ -20,7 +22,9 @@ def reqAPI(api: API, client: Union[httpx.Client, httpx.AsyncClient]) -> httpx.Re
|
||||
return resp
|
||||
|
||||
|
||||
|
||||
def reqFunc(api: Union[API, str], phone: Union[tuple, str], proxy: dict) -> bool:
|
||||
|
||||
"""请求接口方法"""
|
||||
# 多手机号支持
|
||||
if isinstance(phone, tuple):
|
||||
@@ -28,27 +32,33 @@ def reqFunc(api: Union[API, str], phone: Union[tuple, str], proxy: dict) -> bool
|
||||
else:
|
||||
phone_lst = [phone]
|
||||
|
||||
|
||||
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]}-当前使用代理:{proxy['all://']}")
|
||||
|
||||
logger.info(f"{api.desc}-{resp.text[:30]}")
|
||||
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]}-当前使用代理:{proxy['all://']}")
|
||||
logger.info(f"GETAPI接口-{resp.text[:30]}")
|
||||
return True
|
||||
except httpx.HTTPError as why:
|
||||
logger.error(f"请求失败{why}-当前使用代理:{proxy['all://']}")
|
||||
logger.error(f"请求失败{why}")
|
||||
|
||||
return False
|
||||
|
||||
|
||||
async def asyncReqs(src: Union[API, str], phone: Union[tuple, str], semaphore):
|
||||
"""异步请求方法
|
||||
|
||||
:param:
|
||||
:return:
|
||||
|
||||
"""
|
||||
# 多手机号支持
|
||||
if isinstance(phone, tuple):
|
||||
@@ -94,7 +104,10 @@ 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