微信公众平台视频教程-微信模拟登录之登录

widuu 2013-12-22 PHP技术 3,014 3 喜欢 (0)

微度云课堂

一步一步开始做一个微信的模拟web端,怎么个意思呢?就是我们用模拟登录的方式,让你做一个跟微信公众一摸一样的平台,也可以发微信,发群信息,发获取用户信息,获取fackid等等--今天我们主要介绍的微信的模拟登录




wechat.php 代码

[php]
<?php

class wechat{

private $username;
private $password;
private $cookie;
private $token;

public function __construct($username,$password){
$this->username = $username;
$this->password = $password;
$this->dologin();
var_dump($this->token);
var_dump($this->cookie);
}

private function dologin(){
$header = array(
'Accept:application/json, text/javascript, */*; q=0.01',
'Accept-Encoding:gzip,deflate,sdch',
'Accept-Language:zh-CN,zh;q=0.8,ja;q=0.6,en;q=0.4',
'AlexaToolbar-ALX_NS_PH:AlexaToolbar/alxg-3.2',
'Connection:keep-alive',
'Host:mp.weixin.qq.com',
'Origin:https://mp.weixin.qq.com',
'Referer:https://mp.weixin.qq.com/',
);
$PostData = array(
"username"=>$this->username,
"pwd" =>md5($this->password),
"f"=>"json"
);
$useragent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36";
$url = "https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_USERAGENT,$useragent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $PostData);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $this->cookie);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch);
curl_close($ch);
$data = explode("\n",$result);
foreach ($data as $key => $value) {
if(preg_match("/ErrMsg/i", $value)){
$this->token = substr($value,strrpos($value,"=")+1,-1);
}
if(preg_match("/^Set-Cookie\:([^=]+)\=([^;]+)/i", $value,$match)){
$this->cookie .= $match[1].'='.$match[2];
}
}
}
}

new wechat("帐号","密码");
[/php]

转载请注明来自微度网络,本文标题:《微信公众平台视频教程-微信模拟登录之登录》

喜欢 0 发布评论
Top