curl 模拟找回密码出现不能理解的错误
curl模拟找回密码(华夏保险)直接找回密码页面 http://www.ihxlife.com/forget...
输入手机号15677748704(测试)获取验证码 直接会提示验证码错误
但先进入官网后通过官网链接进入页面能获取验证码
通过代码实现 先访问主页面获取cookie 再利用获取的cookie访问找回密码页面更新cookie
然后获取验证码 ——————失败 短信验证码发送失败
<code> 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."<br>"; $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."<br>"; $referer='http://www.ihxlife.com/forget/forgetPwd'; echo $this->curlPost($requireUrl,$postData,$cookieVerify,$referer,30,true); } </code>
<code> public function getCookie($url, $cookieVerify) { echo $cookieVerify."<br>"; $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; }</code>
回复内容:
curl模拟找回密码(华夏保险)直接找回密码页面 http://www.ihxlife.com/forget...
输入手机号15677748704(测试)获取验证码 直接会提示验证码错误
但先进入官网后通过官网链接进入页面能获取验证码
通过代码实现 先访问主页面获取cookie 再利用获取的cookie访问找回密码页面更新cookie
然后获取验证码 ——————失败 短信验证码发送失败
<code> 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."<br>"; $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."<br>"; $referer='http://www.ihxlife.com/forget/forgetPwd'; echo $this->curlPost($requireUrl,$postData,$cookieVerify,$referer,30,true); } </code>
<code> public function getCookie($url, $cookieVerify) { echo $cookieVerify."<br>"; $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; }</code>
问题解决了。这个网站在加载主页登录模块的验证码时更新了cookie。我之前的思路一直在要加载页面要加载页面 然后没有注意到这里 只要再访问下主页验证码保存更新的验证码就好!

Alat AI Hot

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool
Gambar buka pakaian secara percuma

Clothoff.io
Penyingkiran pakaian AI

AI Hentai Generator
Menjana ai hentai secara percuma.

Artikel Panas

Alat panas

Notepad++7.3.1
Editor kod yang mudah digunakan dan percuma

SublimeText3 versi Cina
Versi Cina, sangat mudah digunakan

Hantar Studio 13.0.1
Persekitaran pembangunan bersepadu PHP yang berkuasa

Dreamweaver CS6
Alat pembangunan web visual

SublimeText3 versi Mac
Perisian penyuntingan kod peringkat Tuhan (SublimeText3)

Topik panas



PHP 8.4 membawa beberapa ciri baharu, peningkatan keselamatan dan peningkatan prestasi dengan jumlah penamatan dan penyingkiran ciri yang sihat. Panduan ini menerangkan cara memasang PHP 8.4 atau naik taraf kepada PHP 8.4 pada Ubuntu, Debian, atau terbitan mereka

Untuk bekerja dengan tarikh dan masa dalam cakephp4, kami akan menggunakan kelas FrozenTime yang tersedia.

CakePHP ialah rangka kerja sumber terbuka untuk PHP. Ia bertujuan untuk menjadikan pembangunan, penggunaan dan penyelenggaraan aplikasi lebih mudah. CakePHP adalah berdasarkan seni bina seperti MVC yang berkuasa dan mudah difahami. Model, Pandangan dan Pengawal gu

Untuk mengusahakan muat naik fail, kami akan menggunakan pembantu borang. Di sini, adalah contoh untuk muat naik fail.

Pengesah boleh dibuat dengan menambah dua baris berikut dalam pengawal.

Log masuk CakePHP adalah tugas yang sangat mudah. Anda hanya perlu menggunakan satu fungsi. Anda boleh log ralat, pengecualian, aktiviti pengguna, tindakan yang diambil oleh pengguna, untuk sebarang proses latar belakang seperti cronjob. Mengelog data dalam CakePHP adalah mudah. Fungsi log() disediakan

Kod Visual Studio, juga dikenali sebagai Kod VS, ialah editor kod sumber percuma — atau persekitaran pembangunan bersepadu (IDE) — tersedia untuk semua sistem pengendalian utama. Dengan koleksi sambungan yang besar untuk banyak bahasa pengaturcaraan, Kod VS boleh menjadi c

CakePHP ialah rangka kerja MVC sumber terbuka. Ia menjadikan pembangunan, penggunaan dan penyelenggaraan aplikasi lebih mudah. CakePHP mempunyai beberapa perpustakaan untuk mengurangkan beban tugas yang paling biasa.
