mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]整理服务组件代码
This commit is contained in:
parent
91b5423d27
commit
09b6a6c32b
@ -96,11 +96,11 @@ class BasicApi {
|
|||||||
list($module, $controller, $action, $method) = explode('/', $this->request->path() . '///');
|
list($module, $controller, $action, $method) = explode('/', $this->request->path() . '///');
|
||||||
if (!empty($module) && !empty($controller) && !empty($action) && !empty($method)) {
|
if (!empty($module) && !empty($controller) && !empty($action) && !empty($method)) {
|
||||||
$action = ucfirst($action);
|
$action = ucfirst($action);
|
||||||
$Api = "app\\{$module}\\{$controller}\\{$action}Api";
|
$Api = config('app_namespace') . "\\{$module}\\{$controller}\\{$action}Api";
|
||||||
if (method_exists($Api, $method)) {
|
if (method_exists($Api, $method)) {
|
||||||
return $Api::$method($this);
|
return $Api::$method($this);
|
||||||
}
|
}
|
||||||
return $this->response('访问的接口不存在!', 'NOT_FOUND');
|
return $this->response('访问的接口不存在!', 'API_NOT_FOUND');
|
||||||
}
|
}
|
||||||
return $this->response('不符合标准的接口!', 'API_ERROR');
|
return $this->response('不符合标准的接口!', 'API_ERROR');
|
||||||
}
|
}
|
||||||
|
@ -81,41 +81,37 @@ class BasicWechat extends Controller {
|
|||||||
$split = stripos($this->url, '?') === false ? '?' : '&';
|
$split = stripos($this->url, '?') === false ? '?' : '&';
|
||||||
$wxoauth_url = "{$this->url}{$split}redirectcode=" . encode($this->url);
|
$wxoauth_url = "{$this->url}{$split}redirectcode=" . encode($this->url);
|
||||||
}
|
}
|
||||||
$wechat = &load_wechat('Oauth');
|
|
||||||
// 微信网页授权处理
|
// 微信网页授权处理
|
||||||
|
$wechat = &load_wechat('Oauth');
|
||||||
if (!$this->request->get('code', false)) {
|
if (!$this->request->get('code', false)) {
|
||||||
$this->redirect($wechat->getOauthRedirect($wxoauth_url, 'webOauth', 'snsapi_base'));
|
$this->redirect($wechat->getOauthRedirect($wxoauth_url, 'webOauth', 'snsapi_base'));
|
||||||
}
|
}
|
||||||
if (FALSE === ($result = $wechat->getOauthAccessToken()) || empty($result['openid'])) {
|
if (FALSE === ($result = $wechat->getOauthAccessToken()) || empty($result['openid'])) {
|
||||||
Log::error("微信网页授权失败,{$wechat->errMsg}[{$wechat->errCode}]");
|
Log::error("微信网页授权失败, {$wechat->errMsg}[{$wechat->errCode}]");
|
||||||
exit("微信网页授权失败,{$wechat->errMsg}[{$wechat->errCode}]");
|
exit("微信网页授权失败, {$wechat->errMsg}[{$wechat->errCode}]");
|
||||||
}
|
}
|
||||||
session('openid', $this->openid = $result['openid']);
|
session('openid', $this->openid = $result['openid']);
|
||||||
!$fullMode && $this->redirect($redirect_url);
|
empty($fullMode) && $this->redirect($redirect_url);
|
||||||
// 微信粉丝信息处理
|
// 微信粉丝信息处理
|
||||||
$this->fansinfo = WechatService::getFansInfo($this->openid);
|
$this->fansinfo = WechatService::getFansInfo($this->openid);
|
||||||
if (empty($this->fansinfo['expires_in']) || $this->fansinfo['expires_in'] < time()) {
|
if (empty($this->fansinfo['expires_in']) || intval($this->fansinfo['expires_in']) < time()) {
|
||||||
/* 使用普通授权,获取用户资料;未关注时重新使用高级授权 */
|
/* 使用普通授权, 获取用户资料; 未关注时重新使用高级授权 */
|
||||||
if ($result['scope'] === 'snsapi_base') {
|
if ($result['scope'] === 'snsapi_base') :
|
||||||
$user = load_wechat('User')->getUserInfo($this->openid);
|
$user = load_wechat('User')->getUserInfo($this->openid);
|
||||||
if (empty($user['subscribe'])) {
|
empty($user['subscribe']) && $this->redirect($wechat->getOauthRedirect($wxoauth_url, 'webOauth', 'snsapi_userinfo'));
|
||||||
$this->redirect($wechat->getOauthRedirect($wxoauth_url, 'webOauth', 'snsapi_userinfo'));
|
/* 使用高级授权, 获取完整用户资料 */
|
||||||
}
|
elseif ($result['scope'] === 'snsapi_userinfo') :
|
||||||
} /* 使用高级授权,获取用户资料 */
|
|
||||||
elseif ($result['scope'] === 'snsapi_userinfo') {
|
|
||||||
$user = $wechat->getOauthUserinfo($result['access_token'], $this->openid);
|
$user = $wechat->getOauthUserinfo($result['access_token'], $this->openid);
|
||||||
}
|
endif;
|
||||||
if ((empty($user) || !array_key_exists('nickname', $user))) {
|
/* 授权结果处理, 更新粉丝信息 */
|
||||||
Log::error("微信网页授权获取用户信息失败,{$wechat->errMsg}[{$wechat->errCode}]");
|
if ((empty($user) || !array_key_exists('nickname', $user))) :
|
||||||
exit("微信网页授权获取用户信息失败,{$wechat->errMsg}[{$wechat->errCode}]");
|
Log::error("微信网页授权获取用户信息失败, {$wechat->errMsg}[{$wechat->errCode}]");
|
||||||
}
|
exit("微信网页授权获取用户信息失败, {$wechat->errMsg}[{$wechat->errCode}]");
|
||||||
/* 更新粉丝信息 */
|
endif;
|
||||||
$user['expires_in'] = $result['expires_in'] + time() - 100;
|
$user['expires_in'] = $result['expires_in'] + time() - 100;
|
||||||
$user['refresh_token'] = $result['refresh_token'];
|
$user['refresh_token'] = $result['refresh_token'];
|
||||||
$user['access_token'] = $result['access_token'];
|
$user['access_token'] = $result['access_token'];
|
||||||
if (!WechatService::setFansInfo($user, $wechat->appid)) {
|
WechatService::setFansInfo($user, $wechat->appid) or exit('微信网页授权用户保存失败!');
|
||||||
exit('微信网页授权获取用户信息保存失败');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$this->redirect($redirect_url);
|
$this->redirect($redirect_url);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user