public function beforeAction() { parent::beforeAction(); Wk_Request::startSession(WAKA_DOMAIN); if (isset($_SESSION['user'])) { $this->curUser = $_SESSION['user']; } if (isset($this->curUser)) { Wk::app()->user = new Wk_WebUser(); Wk::app()->user->userid = $this->curUser->id; Wk::app()->user->utoken = ""; } if (isset($this->curUser)) { WkAdminUserService::getInstance()->setLoginCookie($this->curUser); } else { unset($_COOKIE['WAKAUID']); unset($_COOKIE['WAKAUMB']); setcookie('WAKAUID', '', time() - 3600, '/', WAKA_DOMAIN); setcookie('WAKAUMB', '', time() - 3600, '/', WAKA_DOMAIN); } $access = $this->access(); if (!empty($access['?']) && in_array($this->actionName, $access['?'])) { if ($this->isLogin()) { throw new Wk_Exception('', TErrorConstants::E_LOGIN); } } elseif (!empty($access['*']) && in_array($this->actionName, $access['*'])) { } elseif ($this->isGuest()) { throw new Wk_Exception('', TErrorConstants::E_NOT_LOGIN); } }
/** * @return bool */ public static function isAjax() { if (!isset(self::$_isAjax)) { self::$_isAjax = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; } return self::$_isAjax; }
public function _templateAction() { $config = isset($_GET['__config__']) ? $_GET['__config__'] : null; if (!isset($config)) { throw new Wk_Exception("", -1); } if (!empty($config['redirect'])) { Wk_Request::redirect($config['redirect']); } $needLogin = isset($config['needLogin']) ? $config['needLogin'] : 0; if (isset($needLogin) && $needLogin == 1 && !$this->isLogin()) { $this->redirectLogin(); } $needLogout = isset($config['needLogout']) ? $config['needLogout'] : 0; if (isset($needLogout) && $needLogout == 1 && $this->isLogin()) { // throw new K_Exception('', TErrorConstants::E_LOGIN); Wk_Request::redirect("/"); } $path = $config['path']; if (!empty($path)) { unset($_GET['__config__']); $content = $this->renderReleaseTemplate($path, true); echo $content; } Wk::app()->stop(); }
/** * 用户绑定手机号(微信登录) * @return Wk_User * @throws Wk_Exception */ public function bindMobileAction() { $mobile = Wk_Request::getGetString("mobile", null, false); $code = Wk_Request::getGetString("code", null, false); if (!WkSmsCodeService::getInstance()->verifyCode($mobile, $code)) { throw new Wk_Exception("请输入正确的验证码", -1); } return WkUserService::getInstance()->bindMobile($mobile, $this->curUser, false); }
/** * 管理员注册(内部接口) * @apiMethod post * @apiParam string mobile 手机号 * @apiParam string password 密码 * @apiParam string rePassword 密码确认 * @return array * @throws Wk_Exception */ public function submitAdminRegisterAction() { $mobile = Wk_Request::getRequestString("mobile", null, false); $password = Wk_Request::getRequestString("password", null, false); $rePassword = Wk_Request::getRequestString("rePassword", null, false); if ($password != $rePassword) { throw new Wk_Exception("管理员注册两次密码不一致,请重新输入", -1); } $userid = WkAdminUserService::getInstance()->submitAdminUserRegister($mobile, $password); return ['userid' => $userid]; }
public function beforeAction() { // if (empty($_COOKIE['PHPSESSID'])) { // throw new K_Exception('illegal request', -1); // } // $queries = array_merge((!empty($_GET) ? $_GET : []), (!empty($_POST) ? $_POST : [])); // ksort($queries); parent::beforeAction(); $this->curLat = Wk_Request::getRequestFloat('curLat', 0); $this->curLng = Wk_Request::getRequestFloat('curLng', 0); $this->curDest = Wk_Request::getRequestFloat('curDest', 0); }
private function route($controllerName, $actionName) { $controllerClass = ucfirst($controllerName . 'Controller'); if (class_exists($controllerClass)) { /** @var K_Controller $runC */ $runC = new $controllerClass($actionName); $this->controller = $runC; $runC->run($actionName); } else { if (Wk_Request::isAjax()) { } else { Wk_Request::redirect('/'); } } $this->stop(); }
public function _templateAction() { if ($this->isGuest() && strpos($_SERVER['REQUEST_URI'], '/admin/login') !== 0) { Wk_Request::redirect('/admin/login'); } if ($this->isLogin() && strpos($_SERVER['REQUEST_URI'], '/admin/login') === 0) { Wk_Request::redirect('/admin'); } $config = isset($_GET['__config__']) ? $_GET['__config__'] : null; if (!isset($config)) { throw new Wk_Exception("", -1); } $path = $config['path']; if (!empty($path)) { unset($_GET['__config__']); $content = $this->renderReleaseTemplate($path, true); echo $content; } Wk::app()->stop(); }
private function authWeb() { try { Wk_Request::startSession(WAKA_DOMAIN); if (isset($_SESSION['appParam'])) { $token = $_SESSION['appParam']['token']; $retUser = WkUserService::getInstance()->getUserByToken($token); $this->curUser = $retUser; } else { $token = ''; } $this->curToken = $token; if (isset($this->curUser)) { WkUserService::getInstance()->setLoginCookie($this->curUser); } else { unset($_COOKIE['WAKAUID']); setcookie('WAKAUID', '', time() - 3600, '/', WAKA_DOMAIN); } } catch (Exception $e) { Wk::logger()->err($e); throw new Wk_Exception('', -1); } }
private static function formatSMessage() { $prefix = date('Y-m-d H:i:s ', Wk_Request::getTime()); $user = Wk::app()->user; if (isset($user) && !empty($user->userid) && !empty($user->utoken)) { $prefix .= '[userid:' . $user->userid . ']'; $prefix .= '[usertoken:' . $user->utoken . ']'; } if (session_status() == PHP_SESSION_ACTIVE) { $prefix .= '[SESSION_ID:' . session_id() . ']'; } if (!empty($_COOKIE['SERVERID'])) { $prefix .= '[SERVERID:' . $_COOKIE['SERVERID'] . ']'; } $prefix .= $_SERVER['REQUEST_URI']; $referStr = '[REFER:'; $hasRefer = false; $locStr = '[LOC:'; $hasLoc = false; if (!empty($_SERVER['REQUEST_URI'])) { $urlArr = parse_url($_SERVER['REQUEST_URI']); //$prefix .= "[PATH:{$urlArr['path']}]"; $getParams = []; parse_str($urlArr['query'], $getParams); if (!empty($getParams)) { //$prefix .= '[GET:'; foreach ($getParams as $key => $value) { // if (!in_array($key, ['v','vc','vd','token','timestr','sign','lang'])) { // $prefix .= "$key=$value&"; // } } //$prefix .= ']'; } } $prefix .= " "; // if (isset(K::app()->getController()) && !empty(K::app()->getController()->appParam)) { // $prefix .= '[APP_PARAM:'; // foreach (K::app()->getController()->appParam as $key => $value) { // $prefix .= "$key=$value&"; // } // $prefix .= ']'; // } //$prefix .= self::getServerVariable('SERVER_SIGNATURE'); //$prefix .= self::getServerVariable('REQUEST_URI'); //$prefix .= self::getServerVariable('QUERY_STRING'); if (!empty($_POST)) { $prefix .= '[POST:'; foreach ($_POST as $key => $value) { if (in_array($key, ['refer', 'id1', 'id2'])) { $hasRefer = true; $referStr .= "{$key}={$value}&"; continue; } $prefix .= $key . '=' . urlencode($value) . '&'; } $prefix .= ']'; } $referStr .= ']'; $locStr .= ']'; if ($hasRefer) { $prefix .= $referStr; } if ($hasLoc) { $prefix .= $locStr; } $prefix .= $_SERVER['HTTP_USER_AGENT']; $prefix .= $_SERVER['REMOTE_ADDR']; $prefix .= $_SERVER['HTTP_REFERER']; // $prefix .= '[NETCOUNT:db('.Wk::db()->getExecuteCnt().'),mc('.K::mcd()->getUseCnt().'),redis('.K::redis()->getUseCnt().'),tbapi('.TB_BaseSrv::getUseCnt().'),trapi('.TRoad_BaseSrv::getUseCnt().'),solr('.K::solr()->getUseCnt().')]'; if (isset($_SERVER["REQUEST_TIME_FLOAT"])) { $prefix .= '[WAITING:' . round(Wk::app()->startTime - $_SERVER["REQUEST_TIME_FLOAT"], 8) * 1000 . 'ms]'; $prefix .= '[DURATION:' . round(microtime(true) - Wk::app()->startTime, 8) * 1000 . 'ms]'; } return $prefix . "\n"; }
/** * 发送手机验证码 * @throws Wk_Exception */ public function sendAction() { $mobile = Wk_Request::getGetString("mobile", null, false); WkSmsCodeService::getInstance()->sendCode($mobile, isset($this->curUser) ? $this->curUser->userid : 0); }
/** * 通过跳转方式获得微信基本授权,可获得用户信息,但是会在微信里弹授权确认框 * @apiMethod get|post * @apiParam string retUrl 微信回调URL * @apiParam string [state=userinfo] 获取的信息 */ public function getWxOAuth2Redirect_UserInfoAction() { $returl = Wk_Request::getRequestString("retUrl"); // state可以传openId, 防止用户不通过授权,这样依然可以拿到用户的一些信息。 $state = Wk_Request::getRequestString("state", "userinfo"); $redirectUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . Wk::$config['wechat']['WX_AKEY'] . "&redirect_uri=" . urlencode($returl) . "&response_type=code&scope=snsapi_userinfo&state=" . $state . "#wechat_redirect"; Wk_Request::redirect($redirectUrl); }
/** * 返回错误信息 * * @param string $errorMsg * @param int $errorCode * @param int $httpStatus */ public function returnError($errorMsg = '', $errorCode = -1, $httpStatus = 200) { if ($httpStatus !== 200) { switch ($httpStatus) { case 404: header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); echo '404 Not Found'; break; case 403: header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); echo '403 Forbidden'; break; case 500: header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error'); echo '500 Internal Server Error'; break; default: header($_SERVER['SERVER_PROTOCOL'] . ' ' . $httpStatus . ' Http Error'); echo $httpStatus . ' Http Error'; break; } } elseif (Wk_Request::isAjax()) { header('Content-Type: application/json; charset=utf-8'); if (!empty($errorMsg)) { echo json_encode(['ok' => 0, 'msg' => $errorMsg, 'code' => $errorCode], JSON_UNESCAPED_UNICODE); } else { echo json_encode(['ok' => 0, 'msg' => TErrorConstants::getErrorMsg($errorCode), 'code' => $errorCode], JSON_UNESCAPED_UNICODE); } } else { if (empty($errorMsg)) { $errorMsg = TErrorConstants::getErrorMsg($errorCode); } Wk::logger()->err('page error:' . $errorCode . (empty($errorMsg) ? '' : '(' . $errorMsg . ')')); // $this->renderView('/layouts/404'); echo 'error: ' . $errorCode . (empty($errorMsg) ? '' : '(' . $errorMsg . ')'); } Wk::app()->stop(); }