使用curl之前先打开curl配置,具体方式百度一下就知道,开启curl扩展。密码用md5加密,这是经过测试成功的,把用户跟密码改成你的就行了
<?php
//模拟微信登入
$cookie_file = tempnam(‘./temp‘,‘cookie‘);
$login_url = ‘https://mp.weixin.qq.com/cgi-bin/login‘;
$pwd = md5("********");
$data = "f=json&imgcode=&pwd=$pwd&username=*****@***.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);
//var_dump($newurl);
//exit;
$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);
?>