123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- namespace Cas\Controller;
- use KIF\Core\Request;
- use KIF\Cookie;
- use Cas\Module\User;
- use KIF\Core\Config;
- use KIF\String\String;
- use Cas\Dao\Platform;
- use Cas\Dao\LotteryEvents;
- use KIF\Math\Math;
- /**
- * 活动页面的控制器
- *
- * @author lihuanchun
- *
- */
- class EventsController extends Controller {
- private $userCookieName = "USER_INFO";
- private $key;
- public function __construct() {
- $this->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 () );
- }
- }
- }
|