39 lines
695 B
PHP
39 lines
695 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
|
||
|
|
namespace wchat;
|
||
|
|
|
||
|
|
|
||
|
|
use common\Miniprogarampage;
|
||
|
|
|
||
|
|
class SmallProgram extends Miniprogarampage
|
||
|
|
{
|
||
|
|
|
||
|
|
protected static $instance;
|
||
|
|
|
||
|
|
private $url = 'https://api.weixin.qq.com/cgi-bin/token';
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return mixed
|
||
|
|
* @throws \Exception
|
||
|
|
*/
|
||
|
|
public function generateAccess_token()
|
||
|
|
{
|
||
|
|
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()) {
|
||
|
|
throw new \Exception($param->getMessage());
|
||
|
|
}
|
||
|
|
return $param->getData();
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|