Files
kiri-wchat/wchat/wx/SmallProgram.php
T

45 lines
921 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\wx;
2019-11-11 18:14:47 +08:00
2020-03-05 12:41:49 +08:00
use wchat\common\Miniprogarampage;
2019-11-11 18:14:47 +08:00
class SmallProgram extends Miniprogarampage
{
protected static $instance;
private $url = 'https://api.weixin.qq.com/cgi-bin/token';
2020-11-14 03:04:25 +08:00
/**
* @param bool $get_token
* @return mixed
* @throws \Exception
*/
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();
}
$query = [
'grant_type' => 'client_credential',
'appid' => $this->config->getAppid(),
'secret' => $this->config->getAppsecret()
];
2020-04-01 11:53:15 +08:00
$this->request->setErrorField('errcode');
$this->request->setErrorMsgField('errmsg');
2019-11-11 18:14:47 +08:00
$param = $this->request->get($this->url, $query);
if (!$param->isResultsOK()) {
throw new \Exception($param->getMessage());
}
2020-09-10 17:25:46 +08:00
if ($get_token) {
return $param->getData('access_token');
}
2019-11-11 18:14:47 +08:00
return $param->getData();
}
}