Skip to content

Commit

Permalink
从qq的开放平台获取用户数据
Browse files Browse the repository at this point in the history
  • Loading branch information
ideal committed Jun 15, 2015
1 parent fc070ec commit bafe80e
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions upload/src/applications/u/service/PwThirdLoginService.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ public function getAccessToken($platform, $authcode)
}
switch($platform) {
case 'qq':
$result = json_decode(substr($data, 10, -4), true);
if (substr($data, 0, 8) == 'callback') {
$result = json_decode(substr($data, 10, -4), true);
} else {
parse_str($data, $result);
}
if (isset($result['error'])) {
return array(false, array($result['error'], $result['error_description']));
} else {
Expand All @@ -117,7 +121,7 @@ public function getUserInfo($platform, $accesstoken)
if (!$openid[0]) {
return $openid;
}
$openid = $openid['openid'];
$openid = $openid[1];
}

$thirdPlatforms = Wekit::C('webThirdLogin');
Expand All @@ -132,7 +136,27 @@ public function getUserInfo($platform, $accesstoken)
default:
break;
}
$data = $this->_request($url, array());
$data = $this->_request($url, array());
$userinfo = array();
switch($platform) {
case 'qq':
$result = json_decode($data, true);
if ($result['ret'] != 0) {
$userinfo[0] = false;
$userinfo[1] = array('code' => $result['ret'],
'msg' => $result['msg']
);
} else {
$userinfo[0] = true;
$userinfo[1] = array('nickname' => $result['nickname'],
'gender' => $result['gender'], // 男 or 女
'avatar' => $result['figureurl_qq_2'],
);
}
return $userinfo;
default:
return array(false, '');
}
}

public function getOpenId($url)
Expand Down

0 comments on commit bafe80e

Please sign in to comment.