37 lines
801 B
PHP
37 lines
801 B
PHP
<?php
|
|
|
|
|
|
namespace wchat\officialaccount;
|
|
|
|
|
|
use wchat\common\HttpClient;
|
|
use wchat\common\Miniprogarampage;
|
|
|
|
abstract class AfficialAccount extends Miniprogarampage
|
|
{
|
|
protected static $instance;
|
|
|
|
private $url = 'https://api.weixin.qq.com/cgi-bin/token?';
|
|
|
|
/**
|
|
* @return mixed
|
|
* @throws
|
|
*/
|
|
public function generateAccess_token()
|
|
{
|
|
if (!empty($this->config->getToken())) {
|
|
return $this->config->getToken();
|
|
}
|
|
$requestParam['grant_type'] = 'client_credential';
|
|
$requestParam['appid'] = $this->config->getAppid();
|
|
$requestParam['secret'] = $this->config->getAppsecret();
|
|
|
|
$result = HttpClient::NewRequest()->get($this->url, $requestParam);
|
|
if (!$result->isResultsOK()) {
|
|
throw new \Exception($result->getMessage(), $result->getCode());
|
|
}
|
|
return $result->getData();
|
|
}
|
|
|
|
}
|