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

44 lines
879 B
PHP

<?php
namespace wchat\wx;
use wchat\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($get_token = false)
{
if (!empty($this->config->getToken())) {
return $this->config->getToken();
}
$query = [
'grant_type' => 'client_credential',
'appid' => $this->config->getAppid(),
'secret' => $this->config->getAppsecret()
];
$this->request->setErrorField('errcode');
$this->request->setErrorMsgField('errmsg');
$param = $this->request->get($this->url, $query);
if (!$param->isResultsOK()) {
throw new \Exception($param->getMessage());
}
if ($get_token) {
return $param->getData('access_token');
}
return $param->getData();
}
}