1、public function _construct($options) $this-_account = isset($options)?$options:; $this-_datapath =isset($options)?$this-_datapath;debug = isset($options)?false;_logcallback =_cookiename = $this-_datapath.$this-_account;getCookie($this-_cookiename); /* 把cookie写入缓存* param string $filename 缓存文件名 * para
2、m string $content 文件内容 * return bool */public function saveCookie($filename,$content) return file_put_contents($filename,$content);* 读取cookie缓存内容* param string $filename 缓存文件名 * return string cookie */public function getCookie($filename) if (file_exists($filename) $mtime = filemtime($filename);if ($
3、mtime_cookieexpired) return false; $data = file_get_contents($filename); if ($data) $this-cookie = $data; return $this-cookie; /* 删除cookie */public function deleteCookie($filename) $this-cookie = ; unlink($filename); return true;private function log($log)if ($this-debug & function_exists($this-_logc
4、allback) if (is_array($log) $log = print_r($log,true); return call_user_func($this-_logcallback,$log);/* 获取登陆二维码对应的授权码 */public function get_login_code()_logincode) return $this-_logincode; $t = time().strval(mt_rand(100,999); $codeurl =https:/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2
5、F%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN&_=.$t; $send_snoopy = new Snoopy; $send_snoopy-fetch($codeurl); $result = $send_snoopy-results; if ($result) preg_match(_logincode = $matches; $_SESSION = 0; return $this- return $result;* 通过授权码获取对应的二维码图片地址 * param string $code * retur
6、n string image url */public function get_code_image($code=)if ($code=) $code = $this- if (!$code) return false;return http:/qrcode/.$this-_logincode.?t=webwx;* 设置二维码对应的授权码 * param string $code * return class $this */public function set_login_code($code) $this-_logincode = $code; return $this;* 二维码登陆
7、验证 * return status:* =400: invaild code; 408: not auth and wait, 400,401: not valid or expired * 201: just scaned but not confirm * 200: confirm then you can get user info */public function verify_code() if (!_logincode) return false; $url =/cgi-bin/mmwebwx-bin/login?uuid=.$this-_logincode.&tip=1&$s
8、end_snoopy = new Snoopy;$send_snoopy-referer = $status = intval($matches);if ($status=201) $_SESSION = 1; if ($status=200) log(step2:.print_r($matches,true); if (count($matches)1) $ticket = $matches; $scan = $matches; $loginurl =/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=.$ticket.&scan=.$scan.&fu
9、n=new; $send_snoopy-referer =fetch($loginurl); $this-log(step3:.print_r($send_snoopy-headers,true);foreach ($send_snoopy-headers as $key = $value) $value = trim($value); if(strpos($value,Set-Cookie: ) != false)$tmp = str_replace($cookie.=$tmp; $cookie .=return $status; return false;* 获取登陆的cookie * p
10、aram bool $is_array 是否以数值方式返回,默认否,返回字符串 * return string|array */public function get_login_cookie($is_array = false) if (!$is_array)return $this- $c_arr = explode(;,$this-cookie); $cookie = array();foreach($c_arr as $item) $kitem = explode(=,trim($item); if (count($kitem)1) $key = trim($kitem); $val
11、= trim($kitem);empty($val) $cookie = $val;return $cookie;* 授权登陆后获取用户登陆信息 */public function get_login_info()cookie) return false;$submit = https:/cgi-bin/mmwebwx-bin/webwxinit?r=.$t;rawheaders= $this-log(login_info:.$send_snoopy-results);results,true); if ($result_login_user = $result; return $result
12、;* 获取头像* param string $url 传入从用户信息接口获取到的头像地址 */public function get_avatar($url) if (! if (strpos($url, http)=false) $url = http:/$url;$result = $send_snoopy- if ($result) elsereturn false;* 登出当前登陆用户 */public function logout()/cgi-bin/mmwebwx-bin/webwxlogout?redirect=1&type=1;submit($submit,array(uin=$uid,sid=$sid);deleteCookie($this-
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1