Files
kiri-wchat/wchat/officialaccount/AfficialAccount.php
T
2020-09-10 17:25:46 +08:00

43 lines
927 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?';
/**
* @param bool $get_token
* @return mixed
* @throws \Exception
*/
public function generateAccess_token($get_token = false)
{
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());
}
if ($get_token) {
return $result->getData('access_token');
}
return $result->getData();
}
}