[TOC] # 易语言 [易语言接入demo下载](http://wlcdn.c2567.com/%E6%98%93%E8%AF%AD%E8%A8%80%E6%A8%A1%E5%9D%97.zip) # php ``` /** * PHPDEMO * 每个网站都有不同,请勿按部就搬,本DEMO只是一个使用流程的说明. * 一定要做好COOKIES的处理,一定要做好COOKIES的处理,一定要做好COOKIES的处理,重要的事情说3遍! */ shibie(); function shibie(){ $user = '填写您的用户名 (在 http://jiyan.c2567.com/index.php/login/index.html 注册)'; $pass = '填写您的密码 (在 http://jiyan.c2567.com/index.php/login/index.html 注册)'; $gt = 'ec47641997d5292180681a247db3c92e'; $challenge = json_decode(curl_request('https://www.jianshu.com/captchas/new?t='), true); // ================================================== // 得到验证码参数 // { // "success": 1, // "gt": "ec47641997d5292180681a247db3c92e", // "challenge": "8fba5e5b5932a25af6d4cc7d2980b325", // "new_captcha": 1 // } // 这里的success:0,使用&model=4,如果success:1那就用&model=3。 // ================================================== $referer = 'https://www.jianshu.com'; $model = 3; $uri = json_decode(curl_request('http://jiyanapi.c2567.com/shibie?gt='.$gt.'&challenge='.$challenge['challenge'].'&referer='.$referer.'&model='.$model.'&user='.$user.'&pass='.$pass), true); if ($uri['code'] == '10000') { $get_challenge = $uri['data']['challenge']; $get_validate = $uri['data']['validate']; $POSTDATA = 'username=demo&password=12345678&geetest_challenge='.$get_challenge.'&geetest_validate='.$get_validate.'&geetest_seccode='.$get_validate.'%7Cjordan'; $result = curl_request('http://www.xxxx.com/VerifyLoginServlet.php', $POSTDATA,'PHPSESSID=9c5qt417fj4i6ntvh8mp2osu19;'); echo $result; } } //参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies function curl_request($url,$post='',$cookie='', $returnCookie=0){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)'); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_AUTOREFERER, 1); curl_setopt($curl, CURLOPT_REFERER, "http://XXXX"); if($post) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post); } if($cookie) { curl_setopt($curl, CURLOPT_COOKIE, $cookie); } curl_setopt($curl, CURLOPT_HEADER, $returnCookie); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); if (curl_errno($curl)) { return curl_error($curl); } curl_close($curl); if($returnCookie){ list($header, $body) = explode("\r\n\r\n", $data, 2); preg_match_all("/Set\-Cookie:([^;]*);/", $header, $matches); $info['cookie'] = substr($matches[1][0], 1); $info['content'] = $body; return $info; }else{ return $data; } } ``` # 其他伪代码 ## 第三代验证码识别模式例子 访问 ``` http://www.adidas.com.cn/captcha/ajax/getestStart/?t=1497062366111 ``` 得到验证码参数 ``` { success: 0, gt: "0f6dcb26b411a6c0fd7d4a0ef5891dd3", challenge: "7cbbc409ec990f19c78c75bd1e06f21532", new_captcha: 1 } ``` 由于这里的 `success: 0`, 所以使用 `&model=4` 请求识别 ``` http://jiyanapi.c2567.com/shibie?gt=0f6dcb26b411a6c0fd7d4a0ef5891dd3&challenge=7cbbc409ec990f19c78c75bd1e06f21532&model=4&referer=http://www.adidas.com.cn&return=json&user=test&pass=test ``` 识别成功 ``` { status: "ok", challenge: "7cbbc409ec990f19c78c75bd1e06f21532", validate: "a068849c0dabd81b9154f305145c7222" } ``` ## 第二代验证码伪代码 ### 这里北京工商示例 此为伪代码,以供参考 ``` #访问页面 返回文本 = http.GET (“http://bj.gsxt.gov.cn/sydq/loginSydqAction!sydq.dhtml”) #获取验证码参数 返回文本 = http.GET (“http://bj.gsxt.gov.cn/pc-geetest/register”) challenge = Json (返回文本, “challenge”) gt = Json (返回文本, “gt”) #{"success":1,"gt":"73a7e78f77d457e28a6ad4f12d4bb63e","challenge":"02254f9ffc17e3e1f7d44657431e477e"} # 这里需要判断 success 的值,success=1无需设置,success=0设置为&model=1 #提交识别 返回文本 = http.GET (“http://jiyanapi.c2567.com/shibie?user=test&pass=test&return=json&ip=&gt=” + gt + “&challenge=” + challenge) #识别成功返回结果,如果status为no 请重新获取验证码参数,重新识别。 # { # status: "ok", # challenge: "3d033f099597f5ae63e2e2c902301d183z", # validate: "8f6ebd56291ed6569ac40c1d74780985" # } status = Json (返回文本, “status”) challenge = Json (返回文本, “challenge”) validate = Json (返回文本, “validate”) #验证验证码结果正确性 http.POST (“http://bj.gsxt.gov.cn/pc-geetest/validate”, “geetest_challenge=” + challenge + “&geetest_validate=” + validate + “&geetest_seccode=” + validate + “%7Cjordan”, , )) # 没问题将会返回 {"status":"success","version":"3.3.0"} 如果有误请检查cookie是否处理好. #提交查询得到正确结果 返回文本 = http.POST (“http://bj.gsxt.gov.cn/es/esAction!entlist.dhtml?urlflag=0&challenge=” + challenge, “nowNum=&keyword=aaa&urlflag=0&clear=%E8%AF%B7%E8%BE%93%E5%85%A5%E4%BC%81%E4%B8%9A%E5%90%8D%E7%A7%B0%E3%80%81%E7%BB%9F%E4%B8%80%E7%A4%BE%E4%BC%9A%E4%BF%A1%E7%94%A8%E4%BB%A3%E7%A0%81%E6%88%96%E6%B3%A8%E5%86%8C%E5%8F%B7”) ``` ## 这里是需要传入gt和challenge的示例 ``` 返回数据 = get( "http://verify.panda.tv/captcha/get?app=pandatv&_=1462575041275" ) gt = 返回数据.gt challenge = 返回数据.challenge ret = get( "http://jiyanapi.c2567.com/shibie?gt=gt&challenge=challenge&referer=http://verify.panda.tv&user=test&pass=test&return=json" ) if( status == "ok"){ //识别成功 //返回结果, { status: "ok", challenge: "3d033f099597f5ae63e2e2c902301d183z", validate: "8f6ebd56291ed6569ac40c1d74780985" } }else if( status == "no"){ //无需理会,重新获取验证码参数提交 { status: "no", msg: "行为异常" } }else if( status == "stop"){ //请停止识别,并提示错误信息 { status: "stop", msg: "用户名不存在或密码错误" } } ```