多语言展示
当前在线:1768今日阅读:126今日分享:42

怎么直接用微信公众平台用户名密码绑定开发数据

微信公众平台模拟登陆php模拟微信公众平台绑定开发者数据 php 模拟微信公众平台登陆
方法/步骤
1

第一步以下保存文件名HttpClient.class.phphost = $host; $this->port = $port; } public function __destruct() { foreach ($this as $index => $value) unset($this->$index); } public function __toString() { return $this->getContent(); } // --- Query execution methods: public function get($path, $data = null) { /* Executes a GET request for the specified path. Returns true on success and false on failure. If false, an error message describing the problem encountered can be accessed using the getError() method. $data: optional - if specified, appends it to a query string as part of the get request. $data can be an array of key value pairs, in which case a matching query string will be constructed. */ $this->path = $path; $this->method = 'GET'; if ($data) $this->path .= '?'.http_build_query($data); return $this->doRequest(); } public function post($path, $data) { /* Executes a POST request to the specified path, sending the information specified in $data. Returns true on success or false on failure. If false, an error message describing the problem encountered can be accessed using the getError() method. $data: optional - an array of key value pairs, in which case a matching post request will be constructed. */ $this->path = $path; $this->method = 'POST'; $this->postdata = http_build_query($data); $result = $this->doRequest(); $this->postdata = null; } public function ok() { // Use this after get() or post() to check the status of the last request. // Returns true if the status was 200 OK - otherwise returns false. return ($this->status == 200); } // --- Response accessors: public function getContent() { // Returns the content of the HTTP response. This is usually an HTML document. return $this->content; } public function getStatus() { // Returns the status code of the response - 200 means OK, 404 means file not found, etc. return $this->status; } public function getHeaders() { // Returns the HTTP headers returned by the server as an associative array. return $this->headers; } public function getHeader($header) { // Returns the specified response header, or false if it does not exist. $header = strtolower($header); if (isset($this->headers[$header])) { return $this->headers[$header]; } else { return false; } } public function getError() { // Returns a string describing the most recent error. return $this->errormsg; } public function getCookies($host = null) { /* Returns an array of cookies set by the server, for the current host, or (optionally) for a different host. May return null, if no cookies have been set. $host: optional - specifies a different host for which to retrieve current cookies. Defaults to using the current host. */ return @$this->cookies[$host ? $host : $this->host]; } public function getRequestURL() { // Returns the full URL that has been requested. $url = 'http://'.$this->host; if ($this->port != 80) { $url .= ':'.$this->port; } $url .= $this->path; return $url; } // --- Configuration methods: public function setUserAgent($string) { // Sets the user agent string to be used in the request. // Default is "Incutio HttpClient v$version". $this->user_agent = $string; } public function setAuthorization($username, $password) { // Sets the HTTP authorization username and password to be used in requests. // Warning: don't forget to unset this in subsequent requests to other servers! $this->username = $username; $this->password = $password; } public function setCookies($array, $replace = false) { /* Adds/overwrites or replace cookies to be sent in the request. $array: an associative array containing name-value pairs. $replace: optional, defaults to false - if true, erases all existing cookies, otherwise adds new (and overwrites existing) cookies. */ if ($replace || !is_array(@$this->cookies[$this->host])) $this->cookies[$this->host] = array(); $this->cookies[$this->host] =  $this->cookies[$this->host] ; } public function useGzip($boolean) { // Specify if the client should request gzip encoded content from the server - // this saves bandwidth, but can increase processor time. Enabled by default. $this->use_gzip = $boolean; } public function setPersistCookies($boolean) { /* Specify if the client should persist cookies between requests. Enabled by default. Note: This currently ignores the cookie path (and time) completely. Time is not important, but path could possibly lead to security problems. */ $this->persist_cookies = $boolean; } public function setPersistReferers($boolean) { // Specify if the client should use the URL of the previous request as the // referral of a subsequent request. Enabled by default. $this->persist_referers = $boolean; } public function setHandleRedirects($boolean) { // Specify if the client should automatically follow redirected requests. // Enabled by default. $this->handle_redirects = $boolean; } public function setMaxRedirects($num) { // Set the maximum number of redirects allowed before the client // gives up (mainly to prevent infinite loops). Defaults to 5 redirects. $this->max_redirects = $num; } public function setHeadersOnly($boolean) { // If enabled, the client will only retrieve the headers from a page. // This could be useful for implementing things like link checkers. // Disabled by default. $this->headers_only = $boolean; } public function setDebug($boolean) { // Enables debugging messages in HTML output from the client. // Disabled by default. $this->debug = $boolean; } // --- Static utility methods: public static function quickGet($url, $data = null) { /* Static shortcut method to quickly create and configure a new instance of this class, and perform a GET query. Thanks to string-magic, you can use the return value from this method directly in an echo statement, if you like. */ $bits = parse_url($url); $host = $bits['host']; $port = isset($bits['port']) ? $bits['port'] : 80; $path = isset($bits['path']) ? $bits['path'] : '/'; if (isset($bits['query'])) $path .= '?'.$bits['query']; $client = new HttpClient($host, $port); $client->get($path, $data); return $client; } public static function quickPost($url, $data) { // Similar to [HttpClient::quickGet()], but performs a POST query. $bits = parse_url($url); $host = $bits['host']; $port = isset($bits['port']) ? $bits['port'] : 80; $path = isset($bits['path']) ? $bits['path'] : '/'; $client = new HttpClient($host, $port); $client->post($path, $data); return $client; } // --- Internal helper methods: protected function debug($msg, $object = false) { /* Displays an internal message for debugging and troubleshooting, if debugging is enabled. Use [HttpClient::setDebug()] to enable debugging. */ if ($this->debug) { echo '

HttpClient Debug: ' . $msg; if ($object) echo '
' . htmlspecialchars(print_r($object,true)) . '
'; echo '
'; } } protected function doRequest() { // Performs the actual HTTP request, returning true on success, false on error. if (!$fp = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout)) { // * Set error message: switch($errno) { case -3: $this->errormsg = 'Socket creation failed (-3)'; case -4: $this->errormsg = 'DNS lookup failure (-4)'; case -5: $this->errormsg = 'Connection refused or timed out (-5)'; default: $this->errormsg = 'Connection failed ('.$errno.')'; $this->errormsg .= ' '.$errstr; $this->debug($this->errormsg); } return false; } socket_set_timeout($fp, $this->timeout); $request = $this->buildRequest(); $this->debug('Request', $request); fwrite($fp, $request); // * Reset all the variables that should not persist between requests: $this->headers = array(); $this->content = ''; $this->errormsg = ''; // * Set a couple of flags: $inHeaders = true; $atStart = true; // * Now start reading back the response: while (!feof($fp)) { $line = fgets($fp, 4096); if ($atStart) { // * Deal with first line of returned data: $atStart = false; if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) { $this->errormsg = "Status code line invalid: ".htmlentities($line); $this->debug($this->errormsg); return false; } $http_version = $m[1]; // * not used $this->status = $m[2]; $status_string = $m[3]; // * not used $this->debug(trim($line)); continue; } if ($inHeaders) { if (trim($line) == '') { $inHeaders = false; $this->debug('Received Headers', $this->headers); if ($this->headers_only) { break; // * Skip the rest of the input } continue; } if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) { // * Skip to the next header: continue; } $key = strtolower(trim($m[1])); $val = trim($m[2]); // * Deal with the possibility of multiple headers of same name: if (isset($this->headers[$key])) { if (is_array($this->headers[$key])) { $this->headers[$key][] = $val; } else { $this->headers[$key] = array($this->headers[$key], $val); } } else { $this->headers[$key] = $val; } continue; } // * We're not in the headers, so append the line to the contents: $this->content .= $line; } fclose($fp); // * If data is compressed, uncompress it: if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] == 'gzip') { $this->debug('Content is gzip encoded, unzipping it'); $this->content = substr($this->content, 10); // * See http://www.php.net/manual/en/function.gzencode.php $this->content = gzinflate($this->content); } // * If $persist_cookies, deal with any cookies: if ($this->persist_cookies && isset($this->headers['set-cookie'])) { $cookies = $this->headers['set-cookie']; if (!is_array($cookies)) $cookies = array($cookies); if (!is_array(@$this->cookies[$this->host])) $this->cookies[$this->host] = array(); foreach ($cookies as $cookie) { if (preg_match('/([^=]+)=([^;]+);/', $cookie, $m)) { $this->cookies[$this->host][$m[1]] = $m[2]; } } } // * If $persist_referers, set the referer ready for the next request: if ($this->persist_referers) { $this->debug('Persisting referer: '.$this->getRequestURL()); $this->referer = $this->getRequestURL(); } // * Finally, if handle_redirects and a redirect is sent, do that: if ($this->handle_redirects) { if (++$this->redirect_count >= $this->max_redirects) { $this->errormsg = 'Number of redirects exceeded maximum ('.$this->max_redirects.')'; $this->debug($this->errormsg); $this->redirect_count = 0; return false; } $location = isset($this->headers['location']) ? $this->headers['location'] : ''; $location .= isset($this->headers['uri']) ? $this->headers['uri'] : ''; if ($location) { $this->debug("Following redirect to: $location" . (@$url['host'] ? ", host: ".$url['host'] : '')); $url = parse_url($location); if (@$url['host']) $this->host = $url['host']; return $this->get(($url['path']{0} == '/' ? '' : '/') . $url['path']); } } return true; } protected function buildRequest() { // Constructs the headers of the HTTP request. $headers = array(); $headers[] = "{$this->method} {$this->path} HTTP/1.0"; // * Using 1.1 leads to all manner of problems, such as "chunked" encoding $headers[] = "Host: {$this->host}"; $headers[] = "User-Agent: {$this->user_agent}"; $headers[] = "Accept: {$this->accept}"; if ($this->use_gzip) $headers[] = "Accept-encoding: {$this->accept_encoding}"; $headers[] = "Accept-language: {$this->accept_language}"; if ($this->referer) $headers[] = "Referer: {$this->referer}"; // * Cookies: if (@$this->cookies[$this->host]) { $cookie = 'Cookie: '; foreach ($this->cookies[$this->host] as $key => $value) { $cookie .= "$key=$value; "; } $headers[] = $cookie; } // * Basic authentication: if ($this->username && $this->password) $headers[] = 'Authorization: BASIC '.base64_encode($this->username.':'.$this->password); // * If this is a POST, set the content type and length: if ($this->postdata) { $headers[] = 'Content-Type: application/x-www-form-urlencoded'; $headers[] = 'Content-Length: '.strlen($this->postdata); } $request = implode("\r\n", $headers)."\r\n\r\n".$this->postdata; return $request; }}

2

第二步这里是开始绑定数据'登陆成功', '-21'=>'用户不存在', '-23'=>'密码错误', '-8'=>'需要验证', '-302'=>'开发地址验证失败',);$host = 'mp.weixin.qq.com';$user = '';//公众号$pass= '';//密码$http = new HttpClient($host);$http->setPersistCookies(true);$http->setPersistReferers(true);$http->setCookies(null);$http->get('/');$http->post('/cgi-bin/login', array('f'=>'json','imgcode'=>trim($p->imgcode),'username'=>$user,'pwd'=>md5(substr($pass, 0,16))));$content = trim($http->getContent());$jsonData = json_decode($content);header('content-type:text/html;charset=utf-8');echo '

';print_r($jsonData);//微信平台连接失败if($content==''){ }//登陆失败else if($jsonData&&$jsonData->base_resp->ret!=0){	echo $error[$jsonData->base_resp->ret];}//登陆成功else{	$redirect_url 	= $jsonData->redirect_url;	$url_info 			= array();	/*	Array	(			[path] => /cgi-bin/home			[query] => t=home/index&lang=zh_CN&token=1593764392	)	*/	$url_info 			= parse_url($redirect_url);	/*	 	Array	(	   [t] => home/index	   [lang] => zh_CN	   [token] => 1593764392	)	*/	parse_str($url_info['query'],$getParams);	print_r($url_info);	print_r($getParams);	//flag=0关闭开发者模式,flag=1开启开发者模式	$http->post('/misc/skeyform?form=advancedswitchform&lang=zh_CN', array('flag'=>1,'type'=>2,'token'=>$getParams['token']));	$url_config = 'http://stealbluly.vicp.net/mpapi.html?appid=114';	$token = '62a8059ee1779a2608b6b05c26b55b6f';	//配置开发地址	$http->post('/advanced/callbackprofile?t=ajax-response&lang=zh_CN&token='.$getParams['token'], array('url'=>$url_config,'callback_token'=>$token ));	$content_dev = $http->getContent();	$jsonData_dev = json_decode($content_dev);	print_r($jsonData_dev);	//验证成功	if($jsonData_dev->ret==0){ 	}//验证失败	else{		echo $error[$jsonData_dev->ret];	}	//获取公众号信息	$http->get('/advanced/advanced?action=dev&t=advanced/dev&token='.$getParams['token'].'&lang=zh_CN&f=json');	$content_user_info   = $http->getContent() ;	$jsonData_user_info = json_decode($content_user_info);	//存放微信公众号信息	$weixin_user_info = array();	//公众号信息	if($jsonData_user_info->user_info){		$weixin_user_info['user'] = array(				'nick_name'=>$jsonData_user_info->user_info->nick_name,				'user_name'=>$jsonData_user_info->user_info->user_name,		);	}	//公众号开发信息	if($jsonData_user_info->advanced_info){		$weixin_user_info['advanced'] = array(				'url'=>$jsonData_user_info->advanced_info->dev_info->callback_url,				'token'=>$jsonData_user_info->advanced_info->dev_info->callback_token,							'appid'=>$jsonData_user_info->advanced_info->dev_info->app_id,				'appsecret'=>$jsonData_user_info->advanced_info->dev_info->app_key,		);	}	print_r($weixin_user_info);}echo $content;?>

推荐信息