key = 'rD5carfCGbHAhF'; $this->params = $this->getRequestParams (); /* if (! $this->checkSign ( $params ['sign'], $params )) { //exit ( 'Sign error' ); } */ $this->objMUser = new User (); } /** * 用户登录caozuo */ public function doRepLogin(){ } /** * 设置用户 * 请求地址:http://cas.lishuy.com/index.php?c=API_Req&a=Page&sign=51CE47C9A3681845D5ACCF3728DABD6A * http://cas.lishuy.com/API_SetUser_Req/?sign=51CE47C9A3681845D5ACCF3728DABD6A * 参数: * passport_uid 对方UID * cas_uid 本平台UID * nickname 用户昵称 * headimgurl 用户头像地址 * sign 加密串 * * 返回 */ public function doReq() { // 1.获取传递来的相关信息 $info ['nickname'] = urlencode($this->params ['nickname']); $info ['headimgurl'] = urlencode($this->params ['headimgurl']); $info ['passport_uid'] = $this->params ['passport_uid']; $cas_uid = $this->params ['cas_uid']; // 2.绑定用户信息 if ($this->objMUser->bindingUser ( $info, $cas_uid )) { exit ( 'success' ); } ; exit ( 'fail' ); } /** * 统一着陆页面 * 页面地址:http://cas.lishuy.com/index.php?c=API_SetUser&a=Page&sign=51CE47C9A3681845D5ACCF3728DABD6A * http://cas.lishuy.com/API_SetUser_Page/?sign=51CE47C9A3681845D5ACCF3728DABD6A * 参数: * passport_uid 对方UID * cas_uid 本平台UID * nickname 用户昵称 * headimgurl 用户头像地址 * return_url 原跳转地址 * sign 加密串 */ public function doPage() { // 1.获取传递来的相关信息 $info ['nickname'] = urldecode($this->params ['nickname']); $info ['headimgurl'] = urldecode($this->params ['headimgurl']); $info ['passport_uid'] = $this->params ['uid']; $cas_uid = $this->params['cas_uid']; $back_url = urldecode($this->params['cas_return_url']); if(isset($this->params ['return_url'])){ $this_return_url = urldecode($this->params ['return_url']); $arr = $this->convertUrlQuery($this_return_url); $back_url = urldecode($arr['cas_return_url']); $cas_uid = $arr['cas_uid']; } // 2.绑定用户信息 if($info ['passport_uid']){ $userData = $this->objMUser->getUserDataPasspord($info ['passport_uid']); if(!$userData){ $this->objMUser->bindingUser ( $info, $cas_uid ); $userData = $this->objMUser->get($cas_uid); } }else{ $userData = $this->objMUser->get($cas_uid); } $userData ['key'] = Math::md5_16 ( $cas_uid ); $userData = json_encode ( $userData ); Cookie::set ( 'USER_INFO', $userData, 60 * 60 * 24 * 20 ,'.'.$_SERVER['HTTP_HOST']); header ( "Location: " . $back_url ); exit (); } /** * 校验请求的合法性 * * @param array $request_params * @param string $sign * @return Boolean */ public function verifySign(array $request_params, $sign) { if (empty ( $sign )) { return false; } $new_sign = $this->createSign ( $request_params ); if (strtolower ( $new_sign ) != strtolower ( $sign )) { return false; } return true; } /** * 获取请求的参数集。依赖 REQUEST_METHOD 做判断 * * @return array */ public function getRequestParams() { $params = array (); if ($_SERVER ['REQUEST_METHOD'] == 'POST') { $params = $_POST; if (! $params) { $params = $_GET; } } else if ($_SERVER ['REQUEST_METHOD'] == 'GET') { $params = $_GET; } else { throw new Exception ( 'NOT_SUPPORT_REQUEST_METHOD' ); } return $params; } /** * 生成请求参数的sign * * @param array $params * @return String */ public function createSign(array $params) { if ($params && is_array ( $params )) { ksort ( $params ); $str = $this->key; foreach ( $params as $key => $value ) { if ($key != 'sign') { $str .= $key . $value; } } return strtoupper ( md5 ( $str ) ); } return ''; } public function convertUrlQuery($url) { $arr = parse_url($url); $query = $arr['query']; $queryParts = explode('&', $query); $params = array(); foreach ($queryParts as $param) { $item = explode('=', $param); $params[$item[0]] = $item[1]; } return $params; } /** * 指定的sign值是否正确 * * @param String $sign * 给定需要验证的sign值 * @param Array $params * 用来计算sign值的参数集合 * @return Boolean */ public function checkSign($sign, $params = null) { $sign2 = $this->createSign ( $params ); return ($sign2 == $sign); } public function run() { $action = $this->action; $this->$action (); } public function display() { $this->render (); } }