curl模拟找回密码(华夏保险)直接找回密码页面 http://www.ihxlife.com/forget...
输入手机号15677748704(测试)获取验证码 直接会提示验证码错误
但先进入官网后通过官网链接进入页面能获取验证码
通过代码实现 先访问主页面获取cookie 再利用获取的cookie访问找回密码页面更新cookie
然后获取验证码 ——————失败 短信验证码发送失败
public function forgetpwdindex(){ $ukey = 'huaxia' . date(ymdhis) . uniqid(); $cookieverify = app_cookie . / . $ukey . .tmp; $url = 'http://www.ihxlife.com/';//登录主页的url来获取cookie $this->getcookie($url, $cookieverify);//获取到登录页面的cookie //获取找回密码页的cookie $pwdurl='http://www.ihxlife.com/forget/forgetpwd'; $ch = curl_init(); curl_setopt($ch, curlopt_url, $pwdurl); curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (macintosh; intel mac os x 10.10; rv:40.0) gecko/20100101 firefox/40.0'); curl_setopt($ch, curlopt_ssl_verifypeer, 0); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_timeout, 120); // 设置超时限制防止死循环 curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_httpheader, array('accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'accept-encoding:gzip, deflate', 'accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3', 'connection:keep-alive', 'host:www.ihxlife.com')); curl_setopt($ch, curlopt_referer,'http://www.ihxlife.com/'); curl_setopt($ch, curlopt_cookiefile, $cookieverify); curl_setopt($ch, curlopt_cookiejar, $cookieverify); curl_exec($ch); curl_close($ch); //echo $cookieverify.
; $this->assign('key', $ukey);//传到页面中 在页面中post该数据 拼组cookie文件 $this->display(); } public function sendpwdmobilecode(){ if(i('post.key')==''||i('post.mobile')==''){ echo json_encode(array('status'=>'10001','message'=>'参数错误')); die; } $requireurl='http://www.ihxlife.com/sms/smscode_send';//请求地址 $postdata='mobile='.i('post.mobile').'&busitype=10019&effectivetime=180'; $cookieverify = app_cookie . / . i('post.key') . .tmp; echo $cookieverify.
; $referer='http://www.ihxlife.com/forget/forgetpwd'; echo $this->curlpost($requireurl,$postdata,$cookieverify,$referer,30,true);}
public function getcookie($url, $cookieverify) { echo $cookieverify.
; $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (macintosh; intel mac os x 10.10; rv:40.0) gecko/20100101 firefox/40.0'); curl_setopt($ch, curlopt_ssl_verifypeer, 0); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_httpheader, array('accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'accept-encoding:gzip, deflate','accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3','connection:keep-alive','host:www.ihxlife.com')); curl_setopt($ch, curlopt_timeout, 120); // 设置超时限制防止死循环 curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_cookiejar, $cookieverify); curl_exec($ch); curl_close($ch); } public function curlpost($url, $post_fields, $cookieverify, $referer = '', $timeout = 30, $header = ''){ $curl = curl_init(); curl_setopt($curl, curlopt_url, $url); curl_setopt($curl, curlopt_ssl_verifypeer, 0); curl_setopt($curl, curlopt_ssl_verifyhost, 1); curl_setopt($curl, curlopt_useragent, 'mozilla/5.0 (macintosh; intel mac os x 10.10; rv:40.0) gecko/20100101 firefox/40.0'); curl_setopt($curl, curlopt_followlocation, 1); if ($referer) { curl_setopt($curl, curlopt_referer, $referer); } else { curl_setopt($curl, curlopt_autoreferer, 1); } if ($header) { //curl_setopt($curl, curlopt_httpheader, array('host:www.ihxlife.com', 'x-requested-with:xmlhttprequest')); curl_setopt($curl, curlopt_httpheader, array('accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'accept-encoding:gzip, deflate', 'accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3', 'content-type:application/x-www-form-urlencoded; charset=utf-8', 'connection:keep-alive', 'host:www.ihxlife.com', 'x-requested-with:xmlhttprequest')); } curl_setopt($curl, curlopt_postfields, $post_fields); curl_setopt($curl, curlopt_post, 1); curl_setopt($curl, curlopt_cookiefile, $cookieverify); curl_setopt($curl, curlopt_cookiejar, $cookieverify); curl_setopt($curl, curlopt_timeout, $timeout); curl_setopt($curl, curlopt_header, 0); curl_setopt($curl, curlopt_returntransfer, 1); $resultdata = curl_exec($curl); // 执行操作 curl_close($curl); return $resultdata;}
回复内容: curl模拟找回密码(华夏保险)直接找回密码页面 http://www.ihxlife.com/forget...
输入手机号15677748704(测试)获取验证码 直接会提示验证码错误
但先进入官网后通过官网链接进入页面能获取验证码
通过代码实现 先访问主页面获取cookie 再利用获取的cookie访问找回密码页面更新cookie
然后获取验证码 ——————失败 短信验证码发送失败
public function forgetpwdindex(){ $ukey = 'huaxia' . date(ymdhis) . uniqid(); $cookieverify = app_cookie . / . $ukey . .tmp; $url = 'http://www.ihxlife.com/';//登录主页的url来获取cookie $this->getcookie($url, $cookieverify);//获取到登录页面的cookie //获取找回密码页的cookie $pwdurl='http://www.ihxlife.com/forget/forgetpwd'; $ch = curl_init(); curl_setopt($ch, curlopt_url, $pwdurl); curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (macintosh; intel mac os x 10.10; rv:40.0) gecko/20100101 firefox/40.0'); curl_setopt($ch, curlopt_ssl_verifypeer, 0); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_timeout, 120); // 设置超时限制防止死循环 curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_httpheader, array('accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'accept-encoding:gzip, deflate', 'accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3', 'connection:keep-alive', 'host:www.ihxlife.com')); curl_setopt($ch, curlopt_referer,'http://www.ihxlife.com/'); curl_setopt($ch, curlopt_cookiefile, $cookieverify); curl_setopt($ch, curlopt_cookiejar, $cookieverify); curl_exec($ch); curl_close($ch); //echo $cookieverify.
; $this->assign('key', $ukey);//传到页面中 在页面中post该数据 拼组cookie文件 $this->display(); } public function sendpwdmobilecode(){ if(i('post.key')==''||i('post.mobile')==''){ echo json_encode(array('status'=>'10001','message'=>'参数错误')); die; } $requireurl='http://www.ihxlife.com/sms/smscode_send';//请求地址 $postdata='mobile='.i('post.mobile').'&busitype=10019&effectivetime=180'; $cookieverify = app_cookie . / . i('post.key') . .tmp; echo $cookieverify.
; $referer='http://www.ihxlife.com/forget/forgetpwd'; echo $this->curlpost($requireurl,$postdata,$cookieverify,$referer,30,true);}
public function getcookie($url, $cookieverify) { echo $cookieverify.
; $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (macintosh; intel mac os x 10.10; rv:40.0) gecko/20100101 firefox/40.0'); curl_setopt($ch, curlopt_ssl_verifypeer, 0); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_httpheader, array('accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'accept-encoding:gzip, deflate','accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3','connection:keep-alive','host:www.ihxlife.com')); curl_setopt($ch, curlopt_timeout, 120); // 设置超时限制防止死循环 curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_cookiejar, $cookieverify); curl_exec($ch); curl_close($ch); } public function curlpost($url, $post_fields, $cookieverify, $referer = '', $timeout = 30, $header = ''){ $curl = curl_init(); curl_setopt($curl, curlopt_url, $url); curl_setopt($curl, curlopt_ssl_verifypeer, 0); curl_setopt($curl, curlopt_ssl_verifyhost, 1); curl_setopt($curl, curlopt_useragent, 'mozilla/5.0 (macintosh; intel mac os x 10.10; rv:40.0) gecko/20100101 firefox/40.0'); curl_setopt($curl, curlopt_followlocation, 1); if ($referer) { curl_setopt($curl, curlopt_referer, $referer); } else { curl_setopt($curl, curlopt_autoreferer, 1); } if ($header) { //curl_setopt($curl, curlopt_httpheader, array('host:www.ihxlife.com', 'x-requested-with:xmlhttprequest')); curl_setopt($curl, curlopt_httpheader, array('accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'accept-encoding:gzip, deflate', 'accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3', 'content-type:application/x-www-form-urlencoded; charset=utf-8', 'connection:keep-alive', 'host:www.ihxlife.com', 'x-requested-with:xmlhttprequest')); } curl_setopt($curl, curlopt_postfields, $post_fields); curl_setopt($curl, curlopt_post, 1); curl_setopt($curl, curlopt_cookiefile, $cookieverify); curl_setopt($curl, curlopt_cookiejar, $cookieverify); curl_setopt($curl, curlopt_timeout, $timeout); curl_setopt($curl, curlopt_header, 0); curl_setopt($curl, curlopt_returntransfer, 1); $resultdata = curl_exec($curl); // 执行操作 curl_close($curl); return $resultdata;}
问题解决了。这个网站在加载主页登录模块的验证码时更新了cookie。我之前的思路一直在要加载页面要加载页面 然后没有注意到这里 只要再访问下主页验证码保存更新的验证码就好!