/** * @return int */ public function waitForLogin() { $url = sprintf('https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip=%s&uuid=%s&_=%s', self::$tip, self::$uuid, time()); $responseData = Requests::get($url); preg_match('/window.code=(\\d+)/', $responseData->body, $statusCodeArray); //print_r($statusCodeArray); $statusCode = (int) $statusCodeArray[1]; if ($statusCode == 201) { echo '扫描成功,请在手机上面点登录 :)<br/>'; self::$tip = 0; } else { if ($statusCode == 200) { echo '正在登录,请稍后......'; preg_match('/window.redirect_uri="(\\S+?)"/', $responseData->body, $responseArray); self::$redirect_uri = $responseArray[1] . '&fun=new'; self::$base_uri = substr(self::$redirect_uri, 0, strrpos(self::$redirect_uri, '/')); //echo self::$redirect_uri.'<br/>'.self::$base_uri; } else { if ($statusCode == 408) { exit('登录超时!请刷新页面重新扫描二维码......'); } } } return $statusCode; }