EventsController.class.php 19 KB

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