/** * 检测微信登录 */ public function loginCallback($code) { if (!$code) { return false; } $accessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?" . "appid={$this->appId}&secret={$this->appSecret}&code={$code}&grant_type=authorization_code"; $accessToken = RequestUtil::get($accessTokenUrl); LogUtil::weixinLog('授权登录:', $accessToken); if (!$accessToken || $accessToken['error']) { return false; } $this->saveAuthorize($accessToken); // 判断是否已经获取了微信用户信息 $customerModel = new CustomerModel(); $customer = $customerModel->readOne($this->getOpenId()); if (!$customer) { $userInfo = $this->getWeixinUserInfo($this->getToken(), $this->getOpenId()); $customerModel->insert($this->getOpenId(), 0, $userInfo['nickname'], $userInfo['headimgurl'], $userInfo['city'], $userInfo['province'], $userInfo['sex']); } else { if (!$customer['nick_name']) { $userInfo = $this->getWeixinUserInfo($this->getToken(), $this->getOpenId()); $customerModel->update($this->getOpenId(), $userInfo['nickname'], $userInfo['headimgurl'], $userInfo['city'], $userInfo['province'], $userInfo['sex']); } else { } } return true; }