文件名:api_request_script.bat ,直接右键点击执行即可。
@echo off
setlocal:: 配置:: 替换为实际接口URL
set "logFile=log.txt"
set "errorLogFile=error_log.txt"
set "interval=3"
:: 请求间隔(秒)
set "duration=10800"
:: 总时长(秒),3小时 = 10800秒:: 获取脚本开始时间
set "startTime=%TIME%":loop
:: 计算当前时间
set "currentTime=%TIME%"set "url=https://test.aa.com/api-87/apisserver/api/tradePlatform/test?key=%currentTime%" :: 计算经过时间(秒)
for /F "tokens=1-4 delims=:.," %%a in ("%startTime%") do set /A "startSeconds=(((%%a*60+1%%b %% 60)*60+1%%c %% 60)*60+1%%d %% 60)"
for /F "tokens=1-4 delims=:.," %%a in ("%currentTime%") do set /A "currentSeconds=(((%%a*60+1%%b %% 60)*60+1%%c %% 60)*60+1%%d %% 60)"
set /A "elapsedTime=currentSeconds-startSeconds":: 检查是否超出总时长
if %elapsedTime% geq %duration% goto end:: 请求接口
(echo %TIME% - Requesting %url%curl -s %url%echo.
) >> "%logFile%" 2>> "%errorLogFile%":: 等待指定间隔
timeout /t %interval% /nobreak >nul:: 回到循环开始
goto loop:end
echo Finished logging after 3 hours.
endlocal