码迷,mamicode.com
首页 > Web开发 > 详细

PHP培训 CURL模拟登录

时间:2016-09-30 15:42:56      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

  php教程本文简述的是curl模拟登录,今天小编直接把代码发出来分享给大家。但是,现在微信改版啦,登录公众号必须扫二维码认证。这篇代码,我还是依旧发出来,供大家参考使用!

  //模拟微信登入

  $cookie_file = tempnam(‘./temp‘,‘cookie‘);

  $login_url = ‘https://mp.weixin.qq.com/cgi-bin/login‘;

  $data = ‘f=json&imgcode=&pwd=ae4e792c8c289cc8e390c86c99ea249b&username=97653723@qq.com‘;

  $ch = curl_init($login_url);

  curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

  curl_setopt($ch,CURLOPT_POST,1);

  curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);

  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);

  curl_setopt($ch,CURLOPT_REFERER,‘https://mp.weixin.qq.com‘);

  curl_setopt($ch,CURLOPT_POSTFIELDS,$data);

  $content = curl_exec($ch);

  curl_close($ch);

  $newurl = json_decode($content,1);

  $newurl = $newurl[‘redirect_url‘];

  //获取登入后页面的源码

  $go_url = ‘https://mp.weixin.qq.com‘.$newurl;

  $ch = curl_init($go_url);

  curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

  curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file);

  curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,0);

  curl_setopt($ch, CURLOPT_HEADER, 0);

  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  $content = curl_exec($ch);

  //var_dump(curl_error($ch));

  print_r($content);

  curl_close($ch);

  ?>

PHP培训 CURL模拟登录

标签:

原文地址:http://www.cnblogs.com/52zz/p/5923516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!