key = Config::getInstance ()->get ( 'passport_sign_key' ); // 初始化一个本站用户 $cookieInfo = Cookie::get ( $this->userCookieName ); if (! $cookieInfo) { $objMUser = new User (); $uid = $objMUser->initUser (); $userinfo = $objMUser->get ( $uid ); $userinfo ['sign'] = $this->createSign ( $userinfo ); $json_data = json_encode ( $userinfo, true ); Cookie::set ( $this->userCookieName, $json_data, 60 * 60 * 24 * 29, '.' . $_SERVER ['HTTP_HOST'] ); } // 平台信息 $objPlatform = new Platform (); $plat_form_id = $this->getPlatFormId (); $platform = $objPlatform->get ( $plat_form_id ); $this->setOutput ( 'platform', $platform ); // 列表页URL $this->setOutput ( 'listUrl', Request::schemeDomain () . '/list/' . $platform ['url'] ); // 我的礼品URL $this->setOutput ( 'giftsUrl', Request::schemeDomain () . '/list/' . $platform ['url'] . '/member/gifts' ); } /** * 获取当前用户 */ public function getRunTimeUid() { $cookieInfo = html_entity_decode ( Cookie::get ( $this->userCookieName ) ); $cookieInfo = json_decode ( $cookieInfo, true ); return $cookieInfo ['id']; } /** * 判断当前用户是否已经登录 * true 需要 * false 不需要 */ public function ckLogin() { $cookieInfo = Cookie::get ( $this->userCookieName ); $cookieInfo = html_entity_decode ( $cookieInfo ); $userInfo = json_decode ( $cookieInfo, true ); /* * if(!$this->checkSign($userInfo['sign'] , $userInfo)){ return true; } */ if ($userInfo ['is_new'] == 0) { return true; } return false; } /** * 获取登录地址 * $thisUrl : 活动URL地址 */ public function getLoginUrl($thisUrl) { // 1.拼接一个 referer 地址  $cookieInfo = html_entity_decode ( Cookie::get ( $this->userCookieName ) ); $cookieInfo = json_decode ( $cookieInfo, true ); $uid = $cookieInfo ['id']; $args = array ( 'cas_uid' => $uid, 'cas_return_url' => urlencode ( $thisUrl ) // 绑定用户后的跳转地址 ); $args ['sign'] = $this->createSign ( $args ); $refererUrl = urlencode ( String::jointUrl ( Request::schemeDomain () . '/SetUser/', $args ) ); // passport 返回统一着陆页 // 2. 拼接passport请求地址 $passport_url = Config::getInstance ()->get ( 'passport_url' ); $passport_url .= '&referer=' . $refererUrl; $arr = $this->convertUrlQuery ( $passport_url ); $arr ['sign'] = $this->createSign ( $arr ); $passport_url .= '&sign=' . $arr ['sign']; return $passport_url; } 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; } /** * 通过活动创建时间,返回活动ID */ public function getEventsCreateTimeToId() { $create_time = Request::g ( 'create_time' ); $create_time = strtotime ( $create_time ); $objEvents = new LotteryEvents (); $ids = $objEvents->findIdsBy ( array ( 'create_time' => $create_time ) ); return array_pop ( $ids ); } /** * 活动相关页面获取 plat_form_id 方法 */ public function getPlatFormId() { $url = Request::g ( 'url' ); $objDPlatform = new Platform (); $data = $objDPlatform->getsAll (); foreach ( $data as $key => $d ) { if ($d ['url'] == $url) { $plat_form_id = $key; } } if (empty ( $plat_form_id )) { $plat_form_id = Cookie::get ( 'plat_form_id' ); } else { Cookie::set ( 'plat_form_id', $plat_form_id, 60 * 60 * 24 * 29, '.' . $_SERVER ['HTTP_HOST'] ); } return $plat_form_id; } /** * 生成请求参数的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 ''; } /** * 指定的sign值是否正确 * * @param String $sign * 给定需要验证的sign值 * @param Array $params * 用来计算sign值的参数集合 * @return Boolean */ public function checkSign($sign, $params = null) { $sign2 = $this->createSign ( $params ); return ($sign2 == $sign); } /** * * @param string $title */ public function checkIsFromMobile($title) { return true; if (Request::get ( 'kif_debug' ) == '@kimiss') { return true; } // PC 端显示二维码页 $isMobile = false; $user_agent = $_SERVER ['HTTP_USER_AGENT']; if (preg_match ( '/MicroMessenger|Mobile/i', $user_agent )) { $isMobile = true; } if (! $isMobile) { include_once Config::getInstance ()->get ( 'App_Path' ) . DS . 'include/phpqrcode/phpqrcode.php'; $IMG_UPLOAD_PATH = Config::getInstance ()->get ( 'upload.path' ) . DS . 'qrcode'; $IMG_UPLOAD_URL = Config::getInstance ()->get ( 'upload.url' ) . DS . 'qrcode'; if (! file_exists ( $IMG_UPLOAD_PATH )) { if (! mkdir ( $IMG_UPLOAD_PATH, 0775, true )) { self::fail_exit ( '创建二维码失败,原因:图片目录不存在' ); } } $url = Request::url (); $fileName = Math::md5_16 ( $url ) . '.png'; $save_path = $IMG_UPLOAD_PATH . DS . $fileName; $save_url = $IMG_UPLOAD_URL . DS . $fileName; if (! file_exists ( $save_path )) { \QRcode::png ( $url, $save_path, 3, 6 ); } $this->tpl = 'pc_qrcode'; $this->setOutput ( 'qrcode', $save_url ); $this->setOutput ( 'title', $title ); $this->setOutput('user_agent', $user_agent); exit ( $this->render () ); } } }