diff --git a/application/admin/controller/ApiCommon.php b/application/admin/controller/ApiCommon.php index f3b9718..5e60370 100644 --- a/application/admin/controller/ApiCommon.php +++ b/application/admin/controller/ApiCommon.php @@ -12,6 +12,7 @@ use think\Request; use think\Db; use app\common\adapter\AuthAdapter; use app\common\controller\Common; +use think\Session; class ApiCommon extends Common @@ -25,7 +26,7 @@ class ApiCommon extends Common $authKey = trim($header['authkey']); $sessionId = trim($header['sessionid']); - if ($authKey == "wxwork") { + if ($authKey == "wxwork" && Session::get('user_id')) { return; } $paramArr = $request->param(); diff --git a/application/admin/model/User.php b/application/admin/model/User.php index e471d72..39689d4 100644 --- a/application/admin/model/User.php +++ b/application/admin/model/User.php @@ -13,6 +13,7 @@ use app\admin\model\Common; use com\verify\HonrayVerify; use think\Cache; use think\Request; +use think\Session; class User extends Common { @@ -647,8 +648,15 @@ class User extends Common $data['loginExpire'] = $loginExpire; //保存authKey信息 $userData = []; - $userData['authkey'] = $authKey; - $userData['authkey_time'] = time() + $loginExpire; + + $wxuser_id = Session::get('wxuser_id'); + if ($wxuser_id) { + $data['authKey'] = 'wxwork'; + $userData['wxwork_id'] = $wxuser_id; + } else { + $userData['authkey'] = $authKey; + $userData['authkey_time'] = time() + $loginExpire; + } //把状态未激活至为启用 if ($userInfo['status'] == 2) { $userData['status'] = 1; diff --git a/application/common/behavior/AuthenticateBehavior.php b/application/common/behavior/AuthenticateBehavior.php index b82e6e5..fde9335 100644 --- a/application/common/behavior/AuthenticateBehavior.php +++ b/application/common/behavior/AuthenticateBehavior.php @@ -9,6 +9,7 @@ namespace app\common\behavior; use think\Cache; use think\Request; use think\Db; +use think\Session; class AuthenticateBehavior { @@ -32,7 +33,7 @@ class AuthenticateBehavior /*获取头部信息*/ $header = $request->header(); $authKey = trim($header['authkey']); - if ($authKey == "wxwork") { + if ($authKey == "wxwork" && Session::get('user_id')) { return true; } diff --git a/application/crm/controller/Callback.php b/application/crm/controller/Callback.php index 27fb95c..e5b2475 100644 --- a/application/crm/controller/Callback.php +++ b/application/crm/controller/Callback.php @@ -126,7 +126,14 @@ class Callback extends Controller $code = Request::instance()->get('code'); $api = new Api(config('wework.corpId'), config('wework.corpSecret')); $userInfo = $api->getUserInfo($code); - Session::set('user_id', $userInfo['userid']); - return redirect('http://web.lbschem.com:8088/?authkey=wxwork&sessionid=wxwork'); + if ($userInfo) { + Session::set('wxuser_id', $userInfo['userid']); + $adminUser = db('admin_user')->where('wxwork_id', $userInfo['userid'])->find(); + if ($adminUser) { + Session::set('user_id', $adminUser['id']); + return redirect('http://web.lbschem.com:8088/?authkey=wxwork&sessionid='.session_id()); + } + } + return redirect('http://web.lbschem.com:8088/'); } } \ No newline at end of file