是因爲PHP增長嚴謹性,首先要加下判斷數組值是否存在,而後在獲取!
if (isset($result->access_token)) { html
}web
$curl = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$this->app_id.'&secret='.$this->app_secret.'&code='.$code.'&grant_type=authorization_code';
$content = $this->_request($curl);
$result = json_decode($content);
//先判斷是否有值,而後經過access_token和openid拉取用戶信息
if (isset($result->access_token)) {
$webAccess_token = $result->access_token;
$openid = $result->openid;
}