微度云课堂

一步一步开始做一个微信的模拟web端,怎么个意思呢?就是我们用模拟登录的方式,让你做一个跟微信公众一摸一样的平台,也可以发微信,发群信息,发获取用户信息,获取fackid等等--今天我们主要介绍的微信的模拟登录
wechat.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("帐号","密码");

点赞(0) 打赏

Comment list 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部