EventsController.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. <?php
  2. namespace Cas\Controller;
  3. use KIF\Core\Request;
  4. use KIF\Cookie;
  5. use Cas\Module\User;
  6. use KIF\Core\Config;
  7. use KIF\String\String;
  8. use Cas\Dao\Platform;
  9. use Cas\Dao\LotteryEvents;
  10. use KIF\Math\Math;
  11. use Cas\Module\Lottery;
  12. use Cas\Module\LotteryLog;
  13. use Cas\Dao\LotteryUserFeedback;
  14. use Cas\Dao\LotteryData;
  15. use Cas\Dao\UserInfo;
  16. use KIF\Dao\SqlHelper;
  17. use Cas\Dao\Focus;
  18. use Cas\Dao\LotteryUserExpress;
  19. use Cas\Dao\LotteryUserHelp;
  20. use Cas\Dao\LotteryUserHelpLog;
  21. /**
  22. * 活动页面的控制器
  23. *
  24. * @author lihuanchun
  25. *
  26. */
  27. class EventsController extends Controller {
  28. private $userCookieName = "USER_INFO_4";
  29. private $key;
  30. public function __construct() {
  31. $this->key = Config::getInstance ()->get ( 'passport_sign_key' );
  32. // 初始化一个本站用户
  33. $cookieInfo = Cookie::get ( $this->userCookieName );
  34. if (! $cookieInfo) {
  35. $objMUser = new User ();
  36. $uid = $objMUser->initUser ();
  37. $userinfo = $objMUser->get ( $uid );
  38. $userinfo ['sign'] = $this->createSign ( $userinfo );
  39. $json_data = json_encode ( $userinfo, true );
  40. Cookie::set ( $this->userCookieName, $json_data, 60 * 60 * 24 * 29, '.' . $_SERVER ['HTTP_HOST'] );
  41. }
  42. // 平台信息
  43. $objPlatform = new Platform ();
  44. $plat_form_id = $this->getPlatFormId ();
  45. $platform = $objPlatform->get ( $plat_form_id );
  46. $this->setOutput ( 'platform', $platform );
  47. // 列表页URL
  48. $this->setOutput ( 'listUrl', Request::schemeDomain () . '/list/' . $platform ['url'] );
  49. // 我的礼品URL
  50. $this->setOutput ( 'giftsUrl', Request::schemeDomain () . '/list/' . $platform ['url'] . '/member/gifts' );
  51. }
  52. /**
  53. * 获取当前用户
  54. */
  55. public function getRunTimeUid() {
  56. $cookieInfo = html_entity_decode ( Cookie::get ( $this->userCookieName ) );
  57. $cookieInfo = json_decode ( $cookieInfo, true );
  58. return $cookieInfo ['id'];
  59. }
  60. /**
  61. * 获取活动基本信息
  62. */
  63. public function info($info) {
  64. $this->objMLottery = new Lottery();
  65. # 剩余天数
  66. $TIME = time();
  67. $rday = ($info['end_time'] - $TIME) / (24 * 60 * 60);
  68. $info['rday'] = ceil($rday);
  69. # 参与人数
  70. $objMLotteryLog = new LotteryLog ( null, $info['id'] );
  71. $info['user_total'] = $objMLotteryLog->getUserParticipateLogNumGroupByUid ();
  72. # 获取登录地址
  73. $url = Request::g('url');
  74. $plat_form_id = $this->getPlatFormId();
  75. $thisUrl = $this->objMLottery -> getEventsUrl($info['type'],$info['create_time'],$url);
  76. $loginUrl = $this -> getLoginUrl($thisUrl);
  77. $info['thisUrl'] = $thisUrl;
  78. $this->thisUrl = $thisUrl;
  79. $this->setOutput('thisUrl', $thisUrl);
  80. $this->setOutput('loginUrl', $loginUrl);
  81. # 判断是否需要登录
  82. $ckLogin = $this->ckLogin();
  83. $this->setOutput('ckLogin', $ckLogin);
  84. # 获取用户信息
  85. $objUserData = new UserInfo();
  86. $uid = $this->getRunTimeUid();
  87. $userData = $objUserData -> get($uid);
  88. $userData['headimgurl'] = $this->getUserHead($userData);
  89. $this->setOutput('uid', $uid);
  90. $this->setOutput('userInfo', $userData);
  91. $source_user = Request::g('source_user');
  92. if (!$source_user) {
  93. $source_user = $uid;
  94. }
  95. $this->setOutput('source_user', $source_user);
  96. if ($source_user != $uid) {
  97. $userData = $objUserData -> get($source_user);
  98. $userData['headimgurl'] = $this->getUserHead($userData);
  99. }
  100. if (!$userData['nickname']) {
  101. $userData['nickname'] = '福利社网友';
  102. }
  103. $this->setOutput('userSourceInfo', $userData);
  104. $info['end'] = 1; //未过期
  105. if ($TIME > $info['end_time']) {
  106. $info['end'] = 2;//已过期
  107. }
  108. # 抽奖、优惠券、邀请、试用
  109. $type = array(1,4,6,7);
  110. if (in_array($info['type'], $type)) {
  111. $info['prize'] = 1;
  112. //$info['authorize'] = true; //强制登录
  113. } else {
  114. $info['top_data'] = 1;
  115. }
  116. # 检查当前活动是否需要登录
  117. $info['login'] = 1;
  118. $authorize = $info['authorize'];
  119. if ($authorize) {
  120. if($ckLogin==true){
  121. $info['login'] = 2;//需要登录
  122. $weixin = $this->checkIsFromWeixin();
  123. if (!$weixin && $this->applogin == 2) {
  124. self::redirect($loginUrl);
  125. }
  126. //self::redirect($loginUrl);
  127. }
  128. }
  129. # 如果是试用,判断评价
  130. $condition = array('events_id' => $info['id'],'audit' => 2, 'uid' => $uid,'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_TRUE);
  131. $offset = 0;
  132. $size = 1;
  133. $order = 'id desc';
  134. $userData = $this->objMLottery->getOnesLotteryData($condition);
  135. if ($userData) {
  136. $userData['feedback'] = 1;//不需要填写反馈
  137. $userData['url'] = base64_encode($info['thisUrl']);
  138. }
  139. if ($info['type'] == 4) {
  140. $info['feedback'] = 1;
  141. if ($userData) {
  142. $objLotteryUserFeedback = new LotteryUserFeedback();
  143. $userData['feedback'] = 2;//未填写反馈
  144. $where = array();
  145. $where['uid'] = $userData['uid'];
  146. $where['events_id'] = $userData['run_time_data']['events']['id'];
  147. $where['status'] = 1;
  148. $ids = $objLotteryUserFeedback->findIdsBy ( $where, 1, $order = ' id desc');
  149. if ($ids) {
  150. $userData['feedback'] = 3;//已填写反馈
  151. }
  152. /*
  153. if (isset($userData['express']) && $userData['express']) {
  154. $userData['feedback'] = 2;//未填写反馈
  155. $where = array();
  156. $where['uid'] = $userData['uid'];
  157. $where['events_id'] = $userData['run_time_data']['events']['id'];
  158. $where['status'] = 1;
  159. $ids = $objLotteryUserFeedback->findIdsBy ( $where, 1, $order = ' id desc');
  160. if ($ids) {
  161. $userData['feedback'] = 3;//已填写反馈
  162. }
  163. } else {
  164. $userData['feedback'] = 4;//未填写收货地址
  165. }
  166. */
  167. }
  168. }
  169. if ($info['type'] == 1) {
  170. $info['feedback'] = 1;
  171. if ($userData) {
  172. $objLotteryUserFeedback = new LotteryUserFeedback();
  173. if (isset($userData['express']) && $userData['express']) {
  174. } else {
  175. $userData['feedback'] = 4;//未填写收货地址
  176. }
  177. }
  178. }
  179. $order = '`index` desc, id desc';
  180. $limit = '0,5';
  181. $condition = array ('platform_id' => $plat_form_id);
  182. $objFocus = new Focus ();
  183. $ids = $objFocus->findIdsBy ( $condition, $limit, $order );
  184. $focusData = $objFocus->gets ( $ids );
  185. $ad = false;
  186. if (isset($this->platform['ad'])) {
  187. $ad = $this->platform['ad'];
  188. }
  189. $this->setOutput('ad', $ad);
  190. $this->setOutput('focusData', $focusData);
  191. $this->setOutput('userData', $userData);
  192. $this->setOutput('info', $info);
  193. $type = Request::g('type');
  194. if ($type == 'share') {
  195. # 分享
  196. $this->share($info, $plat_form_id, $source_user);
  197. } elseif ($type == 'prize') {
  198. # 获得福利
  199. $this->prize($info, $plat_form_id, 10, false);
  200. } elseif ($type == 'feedback') {
  201. # 获得评价信息
  202. $this->feedback($info, $plat_form_id, 10, false);
  203. }
  204. $this->setOutput('type', $type);
  205. $ajax = Request::g('ajax');
  206. if ($ajax == 'ajax') {
  207. $this->tpl = 'ajax_events';
  208. $this->ajax_success_exit($this->render(true));
  209. die;
  210. }
  211. }
  212. public function share($eventsData, $plat_form_id, $uid)
  213. {
  214. $events_id = $eventsData['id'];
  215. $condition = array (
  216. 'events_id' => $events_id,
  217. 'uid' => $uid,
  218. );
  219. $objLotteryUserHelp = new LotteryUserHelp();
  220. $info = $objLotteryUserHelp->fetchOne ( $condition);
  221. if (!$info) {
  222. $id = $objLotteryUserHelp->add ( $condition);
  223. } else {
  224. $id = $info['id'];
  225. }
  226. if ($id) {
  227. $objLotteryUserHelpLog = new LotteryUserHelpLog();
  228. $condition = array (
  229. 'events_id' => $events_id,
  230. 'help_id' => $id,
  231. );
  232. $total_num = $objLotteryUserHelpLog->totals ( $condition );
  233. $ids = $objLotteryUserHelpLog->findIdsBy ( $condition, '0,50', 'id desc' );
  234. $helpData = $objLotteryUserHelpLog->gets ( $ids );
  235. if ($helpData) {
  236. foreach ($helpData as $k => $v) {
  237. $helpData[$k]['headimgurl'] = $this->getUserHead($v['uid']);
  238. }
  239. }
  240. $session = $this->shareSession($id, $uid);
  241. $this->setOutput('help_session', $session);
  242. $this->setOutput('help_id', $id);
  243. $this->setOutput('helpData', $helpData);
  244. $this->setOutput('helpDataTotal', $total_num);
  245. # 获取登录地址
  246. $thisUrl = $this->thisUrl . '/share?events_id='.$events_id.'&help_id='.$id.'&help_session='.$session.'&source_user=' . $uid;
  247. $loginUrl = $this -> getLoginUrl($thisUrl);
  248. $this->setOutput('loginUrl', $loginUrl);
  249. }
  250. }
  251. public function shareSession($id, $uid, $source_session = false)
  252. {
  253. $key = 'onepage2999';
  254. $session = md5($id . '_' . $key . '_' . $uid);
  255. if ($source_session) {
  256. if ($source_session == $session) {
  257. return true;
  258. } else {
  259. return false;
  260. }
  261. } else {
  262. return $session;
  263. }
  264. }
  265. public function feedback($eventsData, $plat_form_id, $limit = 10, $uid = false)
  266. {
  267. $objFeedBack = new LotteryUserFeedback ();
  268. $page = Request::varGetInt ( 'page', 1 );
  269. $size = $limit;
  270. $offset = ($page - 1) * $size;
  271. $limit = "{$offset},{$size}";
  272. $order = ' id desc';
  273. $condition = array (
  274. 'events_id' => $eventsData['id'],
  275. 'status' => 1,
  276. );
  277. $ids = $objFeedBack->findIdsBy ( $condition, $limit, $order );
  278. $data = $objFeedBack->gets ( $ids );
  279. $total_num = $objFeedBack->totals ( $condition );
  280. $uids = array();
  281. if ($data) {
  282. foreach ($data as $k => $v) {
  283. $uids[] = $v['uid'];
  284. }
  285. # 通过UIDs 获取用户信息
  286. $objMUser = new User();
  287. $users = $objMUser -> gets($uids);
  288. }
  289. if ($data) {
  290. $data = $this->userData($data, $eventsData);
  291. }
  292. $this->setOutput('fdData', $data);
  293. $this->setOutput('fdDataTotals', $total_num);
  294. }
  295. public function prize($eventsData, $plat_form_id, $limit = 10, $uid = false)
  296. {
  297. $condition = array('audit' => 2, 'platform_id' => SqlHelper::addCompareOperator('&', $plat_form_id), 'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_TRUE);
  298. if (isset($eventsData['id'])) {
  299. $condition['events_id'] = $eventsData['id'];
  300. }
  301. if ($uid) {
  302. $condition['uid'] = $uid;
  303. }
  304. $totals = $this->objMLottery -> getLotteryDataListNum($condition);
  305. $page = Request::varGetInt ( 'page', 1 );
  306. $size = $limit;
  307. $offset = ($page - 1) * $size;
  308. $order = 'update_time desc';
  309. $data = $this->objMLottery->getLotteryDataList($condition, "{$offset},{$size}", $order);
  310. if ($data) {
  311. $data = $this->userData($data, $eventsData);
  312. $this->setOutput('userEventsData', $data);
  313. $this->setOutput('userEventsDataTotals', $totals);
  314. }
  315. }
  316. public function userData($data, $eventsData)
  317. {
  318. $uids = array();
  319. foreach ($data as $k => $v) {
  320. $uids[] = $v['uid'];
  321. }
  322. # 通过UIDs 获取用户信息
  323. $objMUser = new User();
  324. $users = $objMUser -> gets($uids);
  325. $objLotteryUserExpress = new LotteryUserExpress();
  326. $condition = array(
  327. 'uid' => $uids
  328. );
  329. $tmpUserExpIds = $objLotteryUserExpress->findIdsBy($condition);
  330. $userExpData = $objLotteryUserExpress -> gets($tmpUserExpIds);
  331. $newUserExpData = array();
  332. foreach($userExpData as $k => $v){
  333. $newUserExpData[$v['uid']] = $v;
  334. }
  335. $this->setOutput('newUserExpData', $newUserExpData);
  336. //138****1234 的用户 2018.4.20 15:10 获得 某某某某活动 奖品。
  337. $objEvents = new LotteryEvents ();
  338. foreach ($data as $k => $v) {
  339. if (isset($v['pic'])) {
  340. $data[$k]['pic'] = explode(',', $v['pic']);
  341. }
  342. if ($v['events_id']) {
  343. $d = $objEvents->findIdsBy(array('id' => $v['events_id']));
  344. $t = $objEvents -> gets($d);
  345. $eventsData = array_pop($t);
  346. }
  347. $type = isset($eventsData['type']) ? $eventsData['type'] : $eventsData[$v['events_id']]['type'];
  348. $data[$k]['user'] = array();
  349. $data[$k]['user']['cdate'] = date('Y.m.d H:i', isset($v['winners_time']) ? $v['winners_time'] : $v['create_time']);
  350. $data[$k]['user']['events'] = isset($eventsData['events_name']) ? $eventsData['events_name'] : $eventsData[$v['events_id']]['events_name'];
  351. $data[$k]['user']['headimgurl'] = $this->getUserHead($users[$v['uid']]);
  352. $data[$k]['user']['ext'] = '';
  353. if ($type == 6) {
  354. $data[$k]['user']['ext'] = '邀请';
  355. } elseif ($type == 4) {
  356. $data[$k]['user']['ext'] = '试用资格';
  357. } elseif ($type == 7) {
  358. $data[$k]['user']['ext'] = '优惠券';
  359. } elseif ($type == 1) {
  360. $data[$k]['user']['ext'] = '奖品';
  361. }
  362. if (isset($v['express']['phone']) && $v['express']['phone']) {
  363. $data[$k]['user']['mobile'] = substr_replace($v['express']['phone'],'****',3,4);
  364. } elseif (isset($newUserExpData[$v['uid']]['phone']) && $newUserExpData[$v['uid']]['phone']) {
  365. $data[$k]['user']['mobile'] = substr_replace($newUserExpData[$v['uid']]['phone'],'****',3,4);
  366. } else {
  367. unset($data[$k]);
  368. }
  369. }
  370. return $data;
  371. }
  372. /**
  373. * 获取头像
  374. */
  375. public function getUserHead($user)
  376. {
  377. if (!is_array($user)) {
  378. $objUserData = new UserInfo();
  379. $user = $objUserData -> get($user);
  380. }
  381. if (isset($user['headimgurl']) && $user['headimgurl']) {
  382. $result = $user['headimgurl'];
  383. } else {
  384. $result = 'http://news.mydrivers.com/Img/20110518/04481549.png';
  385. }
  386. return $result;
  387. }
  388. /**
  389. * 判断当前用户是否已经登录
  390. * true 需要
  391. * false 不需要
  392. */
  393. public function ckLogin() {
  394. $cookieInfo = Cookie::get ( $this->userCookieName );
  395. $cookieInfo = html_entity_decode ( $cookieInfo );
  396. $userInfo = json_decode ( $cookieInfo, true );
  397. /*
  398. * if(!$this->checkSign($userInfo['sign'] , $userInfo)){ return true; }
  399. */
  400. if ($userInfo ['is_new'] == 0) {
  401. return true;
  402. }
  403. return false;
  404. }
  405. /**
  406. * 获取登录地址
  407. * $thisUrl : 活动URL地址
  408. */
  409. public function getLoginUrl($thisUrl) {
  410. $type = Request::g('type');
  411. if ($type == 'share' && !strstr($thisUrl, 'share')) {
  412. $thisUrl .= '/share';
  413. }
  414. // 1.拼接一个 referer 地址 
  415. $cookieInfo = html_entity_decode ( Cookie::get ( $this->userCookieName ) );
  416. $cookieInfo = json_decode ( $cookieInfo, true );
  417. $uid = $cookieInfo ['id'];
  418. $args = array (
  419. 'cas_uid' => $uid,
  420. 'cas_return_url' => urlencode ( $thisUrl ) // 绑定用户后的跳转地址
  421. );
  422. $args ['sign'] = $this->createSign ( $args );
  423. $refererUrl = urlencode ( String::jointUrl ( Request::schemeDomain () . '/SetUser/', $args ) ); // passport 返回统一着陆页
  424. // 2. 拼接passport请求地址
  425. $passport_url = Config::getInstance ()->get ( 'passport_url' );
  426. $passport_third_url = Config::getInstance ()->get ( 'passport_third_url' );
  427. $weixin = $this->checkIsFromWeixin();
  428. if ($passport_third_url && !$weixin) {
  429. $passport_url = $passport_third_url;
  430. }
  431. $passport_url .= '&referer=' . $refererUrl;
  432. $arr = $this->convertUrlQuery ( $passport_url );
  433. $arr ['sign'] = $this->createSign ( $arr );
  434. $passport_url .= '&sign=' . $arr ['sign'];
  435. $passport_url .= '&cas_uid=' . $uid;
  436. $this->setOutput('applogin', 2);
  437. $this->applogin = 2;
  438. if (!$weixin) {
  439. $tokenid = Request::g('tokenid');
  440. if (!$tokenid) {
  441. $tokenid = Request::g('tokenId');
  442. }
  443. if ($tokenid) {
  444. Cookie::set ( 'tokenid', $tokenid, 60 * 60 * 24 * 20 ,'.'.$_SERVER['HTTP_HOST']);
  445. }
  446. if (isset($_COOKIE['tokenid'])) {
  447. $tokenid = $_COOKIE['tokenid'];
  448. }
  449. if ($tokenid) {
  450. # 先检查有没有过期吧
  451. $config = Config::getInstance()->get('passport');
  452. $param['authorizedCode'] = 'fulishe';
  453. $param['tokenId'] = $tokenid;
  454. $data = $this->httpPost($config['url'], $param);
  455. $data = json_decode($data, true);
  456. if (isset($data['data']) && isset($data['data']['tokenId']) && $data['data']['tokenId']) {
  457. } else {
  458. # 已过期
  459. $this->setOutput('applogin', 1);
  460. $this->applogin = 1;
  461. return $passport_url;
  462. }
  463. # app中已登陆
  464. $passport_url .= '&tokenid=' . $tokenid;
  465. } else {
  466. # app中未登陆
  467. $this->setOutput('applogin', 1);
  468. $this->applogin = 1;
  469. }
  470. #
  471. }
  472. return $passport_url;
  473. }
  474. private function httpPost($url, $param) {
  475. $curl = curl_init();
  476. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  477. curl_setopt($curl, CURLOPT_TIMEOUT, 500);
  478. curl_setopt($curl, CURLOPT_URL, $url);
  479. curl_setopt($curl, CURLOPT_POST, 1);
  480. curl_setopt($curl, CURLOPT_POSTFIELDS, $param);
  481. $res = curl_exec($curl);
  482. curl_close($curl);
  483. return $res;
  484. }
  485. public function convertUrlQuery($url) {
  486. $arr = parse_url ( $url );
  487. $query = $arr ['query'];
  488. $queryParts = explode ( '&', $query );
  489. $params = array ();
  490. foreach ( $queryParts as $param ) {
  491. $item = explode ( '=', $param );
  492. $params [$item [0]] = $item [1];
  493. }
  494. return $params;
  495. }
  496. /**
  497. * 通过活动创建时间,返回活动ID
  498. */
  499. public function getEventsCreateTimeToId() {
  500. $create_time = Request::g ( 'create_time' );
  501. $create_time = strtotime ( $create_time );
  502. $objEvents = new LotteryEvents ();
  503. $ids = $objEvents->findIdsBy ( array (
  504. 'create_time' => $create_time
  505. ) );
  506. return array_pop ( $ids );
  507. }
  508. /**
  509. * 活动相关页面获取 plat_form_id 方法
  510. */
  511. public function getPlatFormId() {
  512. $url = Request::g ( 'url' );
  513. $objDPlatform = new Platform ();
  514. $data = $objDPlatform->getsAll ();
  515. foreach ( $data as $key => $d ) {
  516. if ($d ['url'] == $url) {
  517. $plat_form_id = $key;
  518. $this->platform = $d;
  519. }
  520. }
  521. if (empty ( $plat_form_id )) {
  522. $plat_form_id = Cookie::get ( 'plat_form_id' );
  523. } else {
  524. Cookie::set ( 'plat_form_id', $plat_form_id, 60 * 60 * 24 * 29, '.' . $_SERVER ['HTTP_HOST'] );
  525. }
  526. return $plat_form_id;
  527. }
  528. /**
  529. * 生成请求参数的sign
  530. *
  531. * @param array $params
  532. * @return String
  533. */
  534. public function createSign(array $params) {
  535. if ($params && is_array ( $params )) {
  536. ksort ( $params );
  537. $str = $this->key;
  538. foreach ( $params as $key => $value ) {
  539. if ($key != 'sign') {
  540. $str .= $key . $value;
  541. }
  542. }
  543. return strtoupper ( md5 ( $str ) );
  544. }
  545. return '';
  546. }
  547. /**
  548. * 指定的sign值是否正确
  549. *
  550. * @param String $sign
  551. * 给定需要验证的sign值
  552. * @param Array $params
  553. * 用来计算sign值的参数集合
  554. * @return Boolean
  555. */
  556. public function checkSign($sign, $params = null) {
  557. $sign2 = $this->createSign ( $params );
  558. return ($sign2 == $sign);
  559. }
  560. public function checkIsFromWeixin($title) {
  561. $state = false;
  562. $user_agent = $_SERVER ['HTTP_USER_AGENT'];
  563. if (preg_match ( '/MicroMessenger/i', $user_agent )) {
  564. $state = true;
  565. }
  566. return $state;
  567. }
  568. /**
  569. *
  570. * @param string $title
  571. */
  572. public function checkIsFromMobile($title) {
  573. //return true;
  574. if (Request::get ( 'debugs' ) == 'rabin') {
  575. return true;
  576. }
  577. // PC 端显示二维码页
  578. $isMobile = false;
  579. $user_agent = $_SERVER ['HTTP_USER_AGENT'];
  580. /*
  581. if (preg_match ( '/MicroMessenger|Mobile/i', $user_agent )) {
  582. $isMobile = true;
  583. }
  584. */
  585. if (preg_match ( '/MicroMessenger|Mobile/i', $user_agent )) {
  586. $isMobile = true;
  587. }
  588. if (! $isMobile) {
  589. include_once Config::getInstance ()->get ( 'App_Path' ) . DS . 'include/phpqrcode/phpqrcode.php';
  590. $IMG_UPLOAD_PATH = Config::getInstance ()->get ( 'upload.path' ) . DS . 'qrcode';
  591. $IMG_UPLOAD_URL = Config::getInstance ()->get ( 'upload.url' ) . DS . 'qrcode';
  592. if (! file_exists ( $IMG_UPLOAD_PATH )) {
  593. if (! mkdir ( $IMG_UPLOAD_PATH, 0775, true )) {
  594. self::fail_exit ( '创建二维码失败,原因:图片目录不存在' );
  595. }
  596. }
  597. $url = Request::url ();
  598. $fileName = Math::md5_16 ( $url ) . '.png';
  599. $save_path = $IMG_UPLOAD_PATH . DS . $fileName;
  600. $save_url = $IMG_UPLOAD_URL . DS . $fileName;
  601. if (! file_exists ( $save_path )) {
  602. \QRcode::png ( $url, $save_path, 3, 6 );
  603. }
  604. $this->tpl = 'pc_qrcode';
  605. $this->setOutput ( 'qrcode', $save_url );
  606. $this->setOutput ( 'title', $title );
  607. $this->setOutput('user_agent', $user_agent);
  608. exit ( $this->render () );
  609. }
  610. }
  611. }