本帖最后由 caruko 于 2013-9-27 11:37 编辑
这是我写的,去年过年期间,百度抢红包的代码,验证码用的第三方平台。
其中用到工具:
curl
ivon 转码
conset 论坛里有的直接通过管道赋值变量用。- @echo off
- setlocal ENABLEDELAYEDEXPANSION
- ::本机代理,测试用 set "daili=-x 127.0.0.1:8888"
- set ag=-A "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN)"
-
- ::填入手机号码
- set phone=********
- ::起始日期
- set Bday=1980-01-13
- ::循环多少次日期
- set max=10
- :loop
- set /a k+=1
- for /f "skip=2 tokens=1-3 delims=年月日 " %%a in ('Calendar /A !Bday! 00:00:00 1 00:00:00') do (
- set /a yy=%%a,mm=%%b+100,dd=%%c+100
- set "Bday=%%a-%%b-%%c"
- set "nday=!yy!!mm:~-2!!dd:~-2!"
- )
- if !k! geq !max! exit
-
- :main
- conset /d @ >nul
- conset /d _ >nul
- set "@phone=!phone!"
- set "@birth=!nday!"
- call :putUser
- ::call :search
- call :topic
- call :lottery
- echo,!nday!
- call :拿奖 && goto :loop
- echo,剩余抽奖次数:!@count!
- if !@count! geq 1 (
- goto :main
- ) else (
- goto :loop
- )
- goto :eof
-
-
- :putUser
- echo,验证用户...
- 2>nul curl !ag! !daili! -b cookies.txt -c cookies.txt -d "phone=!@phone!&birth=!@birth!&validcode=!@validcode!&valid=!@valid!&_r=0.7948380977831662" -e http://www.baidu.com/chunjie/show/welcome http://www.baidu.com/chunjie/submit/checkusr |iconv -f utf-8 -c|conset _rjson=
- for /f "tokens=2-7 delims={}:," %%a in ('conset /v _rjson') do (
- if %%b=="4001" echo,"生日错误!"
- if %%b=="4002" echo,"手机号错误!"
- if %%b=="4003" (
- echo,"验证码错误!";
- call :getCoed
- call :putUser
- )
- if %%b=="5001" echo,"unable"
- if %%b=="6001" echo,"系统繁忙,请稍后再试^_^"
- if %%b=="0" (
- set /a auto=0
- echo,验证成功,得到搜索字串..
- call :stv %%c %%d
- call :stv %%e %%f
- )
- )
- set "@cookie=CJKEY=!@key!;CJEGG=1;CJPHONE=!@phone!;CJBIRTH=!@birth!"
- goto :eof
-
-
-
- :getCoed
- echo,获取验证码...
- 2>nul curl !ag! !daili! --cookie "!@cookie!" -b cookies.txt "http://www.baidu.com/chunjie/data/valid?phone=!@phone!&birth=!@birth!&_r=0.2951152564330317" |conset _rjson=
- for /f "tokens=1-3 delims={}," %%a in ('conset /v _rjson') do (
- for /f "tokens=1,2 delims=:" %%A in ("%%a") do (
- call :stv %%A %%B
- )
- for /f "tokens=1,2 delims=:" %%A in ("%%b") do (
- call :stv %%A %%B
- )
- for /f "tokens=1* delims=:" %%A in ("%%c") do (
- call :stv %%A %%B
- )
- )
- 2>nul curl !ag! !daili! "!@validUrl!" >code.jpg
- gdip "/t:cmd /c" code.jpg*250*150
- set /p @valid=请输入验证码:
- goto :eof
-
-
- :search
- echo,开始搜索,取得cookie...
- for /f "delims=" %%a in ('echo,!@query!^|urlencode.bat') do set "@query_URL=%%a"
- 2>nul curl !ag! !daili! -I -c cookies.txt -e "http://www.baidu.com/chunjie/show/welcome" "http://www.baidu.com/s?bhjc=zl&wd=!@query_URL!" |findstr "Set-Cookie"|conset @Set-Cookie=
- for /f "tokens=1* delims=:" %%a in ('conset /v @Set-Cookie') do (
- for /f "tokens=1 delims=; " %%A in ("%%b") do (
- set @%%A
- set "@cookie=!@cookie!;%%A"
- )
- )
- goto :eof
-
- :topic
- echo,获取KEY...
- 2>nul curl !daili! -H "Cookie: !@cookie!" --cookie "!@cookie!" -c cookies.txt -e "http://www.baidu.com/s?bhjc=zl&wd=!@query!" http://www.baidu.com/chunjie/show/topic >topic.txt
- cut topic.txt {errNo });|conset @top=
- set @top=errNo!@top!
- for %%a in (!@top!) do (
- for /f "tokens=1,2 delims=:" %%A in ("%%a") do (
- call :stv top_%%A %%B
- )
- )
- goto :eof
-
-
- :lottery
- echo,获取礼品...
- set /a ff=0
- 2>nul curl !daili! -H "Cookie: !@cookie!" --cookie "!@cookie!" -c cookies.txt -d "key=!@top_nextKey!&key1=areyoucheating&_r=0.8628629175014569" -e http://www.baidu.com/chunjie/show/topic http://www.baidu.com/chunjie/submit/lottery|iconv -f utf-8 -c|conset @prize=
- set @prize=!@prize::{=!
- set @prize=!@prize:{=!
- set @prize=!@prize:}=!
- set @prize=!@prize: =!
- for %%D in (!@prize!) do (
- for /f "tokens=1,2 delims=:" %%a in ("%%D") do (
- call :stv %%a %%b
- )
- )
- goto :eof
-
- :拿奖
- if not "!@prizeid!"=="" (
- msg * "你中奖了!注意拿奖!"
- echo,================================>>prize.txt
- set @>>prize.txt
- echo,================================>>prize.txt
- exit /b 0
- )
- exit /b 1
-
-
- :stv
- set "@%~1=%~2"
- goto :eof
-
-
- :自动识别验证码
- echo,正在自动识别验证码...
- curl -F "__EVENTTARGET=" -F "__EVENTARGUMENT=" -F "__VIEWSTATE=/wEPDwUKLTE3NDE4NzE0NQ9kFgJmD2QWAgIDD2QWAgIBDxYCHgdlbmN0eXBlBRNtdWx0aXBhcnQvZm9ybS1kYXRhFgICCw8WAh4EVGV4dAVL5rWL6K+V56ev5YiG5Y+v5ZCR5a6i5pyN6aKG5Y+W44CCPGEgaHJlZj0nVXNlclJlZy5hc3B4Jz7njJvlh7vmiJHms6jlhow8L2E+ZGSzCjPNYUlhvk8bVKkIiv+SjYK/eQ==" -F "__EVENTVALIDATION=/wEWBAKKjaLKDgKlhNbxBQKqw6i0BAKyjrOQAs5tN9SZNKrbdIQmtQWmWarKLf/a" -F "ctl00$ContentPlaceHolder1$txtUser=username" -F "ctl00$ContentPlaceHolder1$txtPass=password" -F "ctl00$ContentPlaceHolder1$file1=@code.jpg;type=image/jpeg" -F "ctl00$ContentPlaceHolder1$btnRecognize=开始识别" http://www.uuwise.com/OnlineDemo.aspx |conset _rjson=
- for /f "tokens=2,4 delims=:,)" %%a in ('conset /v _rjson') do (
- set "@valid=%%a"
- set "codeid=%%b"
- set "codeid=!codeid:'=!"
- copy code.jpg log\%%a_%%b.jpg
- echo,%%a,%%b,!date!!time!>>yzm.log
- )
- exit /b 0
复制代码
|