在 windows bat 编程中,用 curl 可以模拟 http 请求,很方便:
curl https://api.github.com/user?access_token=XXXXXXXXXX
curl --data "param1=value1¶m2=value" https://api.github.com
我们公司现在用的移动办公,我下班比较晚,经常忘记打开,于是我自己写写了个 bat 脚本封装好 curl,然后添加到计划任务:
@ECHO OFF
setlocal
call :GetUnixTime UNIX_TIME
echo %UNIX_TIME% seconds have elapsed since 1970-01-01 00:00:00
curl --data "sign=61B9D5F0E7A8A70B90D900AD16BC6108&unique_id=00000000-4b8e-ba54-ffff-fffffcf684b5&uid=51&time=%UNIX_TIME%&access_key=a5aa2b8e53cea305ee080b466bdf1828&year_month=%date:~0,4%-%date:~5,2%&device_type=1&" host/Attendance/attendance
goto :EOF
:GetUnixTime
setlocal enableextensions
for /f %%x in ('wmic path win32_utctime get /format:list ^| findstr "="') do (
set %%x)
set /a z=(14-100%Month%%%100)/12, y=10000%Year%%%10000-z
set /a ut=y*365+y/4-y/100+y/400+(153*(100%Month%%%100+12*z-3)+2)/5+Day-719469
set /a ut=ut*86400+100%Hour%%%100*3600+100%Minute%%%100*60+100%Second%%%100
endlocal & set "%1=%ut%"
goto :EOF