2019-11-11 18:14:47 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
2020-03-05 12:41:49 +08:00
|
|
|
namespace wchat\qq;
|
2019-11-11 18:14:47 +08:00
|
|
|
|
|
|
|
|
|
2020-03-05 12:41:49 +08:00
|
|
|
use wchat\common\Miniprogarampage;
|
2019-11-11 18:14:47 +08:00
|
|
|
|
|
|
|
|
class SmallProgram extends Miniprogarampage
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
protected static $instance;
|
|
|
|
|
|
|
|
|
|
private $url = 'https://api.q.qq.com/api/getToken';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-12-02 17:53:08 +08:00
|
|
|
* @param $get_token
|
2019-11-11 18:14:47 +08:00
|
|
|
* @return mixed|null
|
|
|
|
|
*/
|
2019-12-02 17:53:08 +08:00
|
|
|
public function generateAccess_token($get_token = false)
|
2019-11-11 18:14:47 +08:00
|
|
|
{
|
|
|
|
|
if (!empty($this->config->getToken())) {
|
|
|
|
|
return $this->config->getToken();
|
|
|
|
|
}
|
|
|
|
|
$query = [
|
|
|
|
|
'grant_type' => 'client_credential',
|
|
|
|
|
'appid' => $this->config->getAppid(),
|
|
|
|
|
'secret' => $this->config->getAppsecret()
|
|
|
|
|
];
|
|
|
|
|
$param = $this->request->get($this->url, $query);
|
|
|
|
|
if (!$param->isResultsOK()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2019-12-02 17:53:08 +08:00
|
|
|
if ($get_token) {
|
|
|
|
|
return $param->getData('access_token');
|
|
|
|
|
}
|
|
|
|
|
return $param->getData();
|
2019-11-11 18:14:47 +08:00
|
|
|
}
|
|
|
|
|
}
|