request->get(); $code = isset($get['code']) ? $get['code'] : ''; if(isset($get['state']) && $get['state'] == 'authdeny'){ util::stop('auth fail'); } $account = ''; $params = $get['params']; $suffixUrl = base64_decode($params); $openMerchant = xhWxOpenService::getMerchant(); $user = []; $baseInfo = []; $data = weixinUtil::getOpenId($code,$openMerchant);//没关注公众号,用户授权获取openId $openId = $data['openid']; $access_token = $data['access_token']; $admin = xhAdminService::getByOpenId($openId); if(empty($admin)){ if($get['authScope'] == 'snsapi_userinfo'){ //经测试,已经关注公众号的粉丝直接点击菜单上的链接时,不走下面的静默自动方式,走这条,也会以静默自动的方式处理获取openId; $baseInfo = weixinUtil::authGetUserInfo($openId,$access_token);//用户授权方式获取用户信息 }else{ $baseInfo = weixinUtil::autoGetUserInfo($openId,$openMerchant);//静默自动方式获取用户信息 } $admin = xhAdminService::generateAdmin($baseInfo); } xhAdminService::loginByThird($admin); $url = 'http://'.$_SERVER['HTTP_HOST'].$suffixUrl; $this->redirect($url); } public function actionLogout() { xhAdminService::logout(); echo 'ok'; } }