Commit 174552dd by HanSon

UUid方法

1 parent 76bd6189
...@@ -29,22 +29,33 @@ class Robot ...@@ -29,22 +29,33 @@ class Robot
$this->client = new Client(); $this->client = new Client();
} }
/**
* 获取UUID
* @throws \Exception
*/
public function getUuid() public function getUuid()
{ {
$response = $this->client->get('https://login.weixin.qq.com/jslogin', [ $content = $this->client->get('https://login.weixin.qq.com/jslogin', [
'query' => [ 'query' => [
'appid' => 'wx782c26e4c19acffb', 'appid' => 'wx782c26e4c19acffb',
'fun' => 'new', 'fun' => 'new',
'lang' => 'zh_CN', 'lang' => 'zh_CN',
'_' => time() * 1000 . random_int(1, 999) '_' => time() * 1000 . random_int(1, 999)
] ]
]); ])->getBody()->getContents();
$content = $response->getBody()->getContents();
preg_match('/window.QRLogin.code = (\d+); window.QRLogin.uuid = \"(\S+?)\"/', $content, $matches); preg_match('/window.QRLogin.code = (\d+); window.QRLogin.uuid = \"(\S+?)\"/', $content, $matches);
return $matches; if(!$matches){
throw new \Exception('获取UUID失败');
}
$this->uuid = $matches[2];
}
public function __get($value)
{
return $this->$value;
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -9,4 +9,5 @@ ...@@ -9,4 +9,5 @@
require_once __DIR__ . './../vendor/autoload.php'; require_once __DIR__ . './../vendor/autoload.php';
$robot = new \Hanson\Robot\Robot(); $robot = new \Hanson\Robot\Robot();
print_r($robot->getUuid());
\ No newline at end of file \ No newline at end of file
$robot->getUuid();
echo $robot->uuid;
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!