wechat-php-sdk icon indicating copy to clipboard operation
wechat-php-sdk copied to clipboard

修改“根据code获取成员信息",获取成功后,显示'$json['error']未定义'错误

Open spristar opened this issue 8 years ago • 0 comments

  • [ 1782] 1.public function getUserId($code,$agentid=0){ if (!$agentid) $agentid=$this->agentid; if (!$this->access_token && !$this->checkAuth()) return false; $result = $this->http_get(self::API_URL_PREFIX.self::USER_GETINFO_URL.'access_token='.$this->access_token.'&code='.$code.'&agentid='.$agentid); if ($result) { $json = json_decode($result,true); //if (!$json || !empty($json['errcode']) || $json['errcode']!=0) {// change it to the below if (isset($json['errcode'])) {//主要修改这里,将上一行修改如左侧代码 /* *无论怎样,微信服务器端都会返回信息,也即!$json 总是为真 *但是,当用正确的code时,微信服务器回复的信息里并无$json['errcode']这一项 *这样导致"或"判断时,会出现$json['errcode']未定义错误 * 修改之后则不会了,会更加准确的判断服务器回复内容,便于后续处理 */
    $this->errCode = $json['errcode']; $this->errMsg = $json['errmsg']; return false;
    } return $json; } return false; }

spristar avatar Jul 28 '17 09:07 spristar