Skip to content

Commit

Permalink
1.完善核心功能 2.对demo例子中的回调链接进行编码
Browse files Browse the repository at this point in the history
  • Loading branch information
shinn-lancelot committed Jul 18, 2018
1 parent b5c2070 commit 0fe1bf4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion demo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$appsecret = '1429a684d8c8407c684c29f404d4c379';
$scope = 'snsapi_userinfo';
$proxy_scope = '';
$redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$redirect_uri = urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$code = '';
isset($_GET['code']) && $code = $_GET['code'];
$access_token = '';
Expand Down
12 changes: 8 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
if (!empty($code) && $proxyScope == 'code') {
$redirectUri = $_COOKIE['redirect_uri'];
if (!empty($redirectUri)) {
header('Location:' . $redirectUri . '?&code=' . $code . '&state=' . $state);
$mark = strpos($redirectUri, '?') === false ? '?' : '';
header('Location:' . $redirectUri . $mark . '&code=' . $code . '&state=' . $state);
} else {
exit('授权登录失败,请退出重试');
}
Expand All @@ -27,8 +28,10 @@
$scope = $scope ? $scope : 'snsapi_userinfo';

$protocol = isHttps() ? 'https' : 'http';
$queryString = $proxyScope == 'access_token' ? '?&' . http_build_query(array('app_id'=>$appId,'app_secret'=>$appSecret,'proxy_scope'=>$proxyScope)) : '';
$proxyRedirectUri = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $queryString;
$phpSelf = $_SERVER['PHP_SELF'];
$mark = strpos($phpSelf, '?') === false ? '?' : '';
$queryString = $proxyScope == 'access_token' ? $mark . '&' . http_build_query(array('app_id'=>$appId,'app_secret'=>$appSecret,'proxy_scope'=>$proxyScope)) : '';
$proxyRedirectUri = $protocol . '://' . $_SERVER['HTTP_HOST'] . $phpSelf . $queryString;
$redirectUri = $_REQUEST['redirect_uri'];

// code为空,进行重定向获取code
Expand Down Expand Up @@ -103,7 +106,8 @@
if (!isset($res['errcode']) || empty($res['errcode'])) {
$redirectUri = $_COOKIE['redirect_uri'];
if (!empty($redirectUri)) {
header('Location:' . $redirectUri . '?&access_token=' . $res['access_token'] . '&openid=' . $openid);
$mark = strpos($redirectUri, '?') === false ? '?' : '';
header('Location:' . $redirectUri . $mark . '&access_token=' . $res['access_token'] . '&openid=' . $openid);
} else {
exit('授权登录失败,请退出重试');
}
Expand Down

0 comments on commit 0fe1bf4

Please sign in to comment.