public function fetchInfo() { global $srkEnv; $code = $_GET['code']; $data = (object) array('client_id' => $srkEnv->thirdPartyLogin['github']->clientId, 'client_secret' => $srkEnv->thirdPartyLogin['github']->clientSecret, 'code' => $code, 'accept' => 'json'); $postRes = decipherGetStr(webPostData('https://github.com/login/oauth/access_token', $data)); if (isset($postRes['access_token'])) { $accessToken = $postRes['access_token']; $dataStr = webGetData('https://api.github.com/user?access_token=' . $accessToken); $userInfo = json_decode($dataStr); if (!$userInfo) { return 'Data fetching error'; } $userData = (object) array('userId' => 'github_' . $userInfo->login, 'email' => $userInfo->email, 'nickname' => $userInfo->name, 'accessToken' => $accessToken, 'avatarURL' => $userInfo->avatar_url, 'source' => 'github'); $user = new UserData(); $user->registerThirdParty($userData); $writeRes = $user->writeUser(); if (!$writeRes) { $_SESSION['userId'] = $userData->userId; } return $writeRes; } else { return 'Access code error'; } }