protected $appid = 'xxxxxxxxxxxxxxxxx';
protected $appsecrt = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
public function getSessionKey()
{
//获取access_token
//获取openID
$code = $this->request->param('code');
if($code) {
$token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->appid."&secret=".$this->appsecrt;
$str_token = file_get_contents($token);
$json_token = json_decode($str_token);
$arr_token = get_object_vars($json_token);
$this->success('获取成功',['access_token'=>$arr_token['access_token']],'20000');
}else{
$this->error('获取失败,code不存在','','20001');
}
}