Files
kiri-wchat/wchat/officialaccount/AfficialAccount.php
T

43 lines
927 B
PHP
Raw Normal View History

2019-11-11 18:14:47 +08:00
<?php
2020-03-05 12:41:49 +08:00
namespace wchat\officialaccount;
2019-11-11 18:14:47 +08:00
2020-03-05 12:41:49 +08:00
use wchat\common\HttpClient;
use wchat\common\Miniprogarampage;
2019-11-11 18:14:47 +08:00
abstract class AfficialAccount extends Miniprogarampage
{
protected static $instance;
private $url = 'https://api.weixin.qq.com/cgi-bin/token?';
/**
2020-09-10 17:25:46 +08:00
* @param bool $get_token
2019-11-11 18:14:47 +08:00
* @return mixed
2020-09-10 17:25:46 +08:00
* @throws \Exception
2019-11-11 18:14:47 +08:00
*/
2020-09-10 17:25:46 +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();
}
$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());
}
2020-09-10 17:25:46 +08:00
if ($get_token) {
return $result->getData('access_token');
}
2019-11-11 18:14:47 +08:00
return $result->getData();
}
}