EventsController.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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. $t = Request::g('a');
  319. if ($t == 1) {
  320. print_r($data);
  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. if ($t == 1) {
  340. print_r($newUserExpData);
  341. }
  342. $this->setOutput('newUserExpData', $newUserExpData);
  343. //138****1234 的用户 2018.4.20 15:10 获得 某某某某活动 奖品。
  344. $objEvents = new LotteryEvents ();
  345. foreach ($data as $k => $v) {
  346. if (isset($v['pic'])) {
  347. $data[$k]['pic'] = explode(',', $v['pic']);
  348. }
  349. if ($v['events_id']) {
  350. $d = $objEvents->findIdsBy(array('id' => $v['events_id']));
  351. $t = $objEvents -> gets($d);
  352. $eventsData = array_pop($t);
  353. }
  354. $type = isset($eventsData['type']) ? $eventsData['type'] : $eventsData[$v['events_id']]['type'];
  355. $data[$k]['user'] = array();
  356. $data[$k]['user']['cdate'] = date('Y.m.d H:i', isset($v['winners_time']) ? $v['winners_time'] : $v['create_time']);
  357. $data[$k]['user']['events'] = isset($eventsData['events_name']) ? $eventsData['events_name'] : $eventsData[$v['events_id']]['events_name'];
  358. $data[$k]['user']['headimgurl'] = $this->getUserHead($users[$v['uid']]);
  359. $data[$k]['user']['ext'] = '';
  360. if ($type == 6) {
  361. $data[$k]['user']['ext'] = '邀请';
  362. } elseif ($type == 4) {
  363. $data[$k]['user']['ext'] = '试用资格';
  364. } elseif ($type == 7) {
  365. $data[$k]['user']['ext'] = '优惠券';
  366. } elseif ($type == 1) {
  367. $data[$k]['user']['ext'] = '奖品';
  368. }
  369. if (isset($v['express']['phone']) && $v['express']['phone']) {
  370. $data[$k]['user']['mobile'] = substr_replace($v['express']['phone'],'****',3,4);
  371. } elseif (isset($newUserExpData[$v['uid']]['phone']) && $newUserExpData[$v['uid']]['phone']) {
  372. $data[$k]['user']['mobile'] = substr_replace($newUserExpData[$v['uid']]['phone'],'****',3,4);
  373. } else {
  374. unset($data[$k]);
  375. }
  376. }
  377. return $data;
  378. }
  379. /**
  380. * 获取头像
  381. */
  382. public function getUserHead($user)
  383. {
  384. if (!is_array($user)) {
  385. $objUserData = new UserInfo();
  386. $user = $objUserData -> get($user);
  387. }
  388. if (isset($user['headimgurl']) && $user['headimgurl']) {
  389. $result = $user['headimgurl'];
  390. } else {
  391. $result = 'http://news.mydrivers.com/Img/20110518/04481549.png';
  392. }
  393. return $result;
  394. }
  395. /**
  396. * 判断当前用户是否已经登录
  397. * true 需要
  398. * false 不需要
  399. */
  400. public function ckLogin() {
  401. $cookieInfo = Cookie::get ( $this->userCookieName );
  402. $cookieInfo = html_entity_decode ( $cookieInfo );
  403. $userInfo = json_decode ( $cookieInfo, true );
  404. /*
  405. * if(!$this->checkSign($userInfo['sign'] , $userInfo)){ return true; }
  406. */
  407. if ($userInfo ['is_new'] == 0) {
  408. return true;
  409. }
  410. return false;
  411. }
  412. /**
  413. * 获取登录地址
  414. * $thisUrl : 活动URL地址
  415. */
  416. public function getLoginUrl($thisUrl) {
  417. $type = Request::g('type');
  418. if ($type == 'share' && !strstr($thisUrl, 'share')) {
  419. $thisUrl .= '/share';
  420. }
  421. // 1.拼接一个 referer 地址 
  422. $cookieInfo = html_entity_decode ( Cookie::get ( $this->userCookieName ) );
  423. $cookieInfo = json_decode ( $cookieInfo, true );
  424. $uid = $cookieInfo ['id'];
  425. $args = array (
  426. 'cas_uid' => $uid,
  427. 'cas_return_url' => urlencode ( $thisUrl ) // 绑定用户后的跳转地址
  428. );
  429. $args ['sign'] = $this->createSign ( $args );
  430. $refererUrl = urlencode ( String::jointUrl ( Request::schemeDomain () . '/SetUser/', $args ) ); // passport 返回统一着陆页
  431. // 2. 拼接passport请求地址
  432. $passport_url = Config::getInstance ()->get ( 'passport_url' );
  433. $passport_third_url = Config::getInstance ()->get ( 'passport_third_url' );
  434. $weixin = $this->checkIsFromWeixin();
  435. if ($passport_third_url && !$weixin) {
  436. $passport_url = $passport_third_url;
  437. }
  438. $passport_url .= '&referer=' . $refererUrl;
  439. $arr = $this->convertUrlQuery ( $passport_url );
  440. $arr ['sign'] = $this->createSign ( $arr );
  441. $passport_url .= '&sign=' . $arr ['sign'];
  442. $passport_url .= '&cas_uid=' . $uid;
  443. $this->setOutput('applogin', 2);
  444. $this->applogin = 2;
  445. if (!$weixin) {
  446. $tokenid = Request::g('tokenid');
  447. if (!$tokenid) {
  448. $tokenid = Request::g('tokenId');
  449. }
  450. if ($tokenid) {
  451. Cookie::set ( 'tokenid', $tokenid, 60 * 60 * 24 * 20 ,'.'.$_SERVER['HTTP_HOST']);
  452. }
  453. if (isset($_COOKIE['tokenid'])) {
  454. $tokenid = $_COOKIE['tokenid'];
  455. }
  456. if ($tokenid) {
  457. # 先检查有没有过期吧
  458. /*
  459. $config = Config::getInstance()->get('passport');
  460. $param['authorizedCode'] = 'fulishe';
  461. $param['tokenId'] = $tokenid;
  462. $data = $this->httpPost($config['url'], $param);
  463. $data = json_decode($data, true);
  464. if (isset($data['data']) && isset($data['data']['tokenId']) && $data['data']['tokenId']) {
  465. } else {
  466. # 已过期
  467. $this->setOutput('applogin', 1);
  468. $this->applogin = 1;
  469. return $passport_url;
  470. }
  471. */
  472. # app中已登陆
  473. $passport_url .= '&tokenid=' . $tokenid;
  474. } else {
  475. # app中未登陆
  476. $this->setOutput('applogin', 1);
  477. $this->applogin = 1;
  478. }
  479. #
  480. }
  481. return $passport_url;
  482. }
  483. private function httpPost($url, $param) {
  484. $curl = curl_init();
  485. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  486. curl_setopt($curl, CURLOPT_TIMEOUT, 500);
  487. curl_setopt($curl, CURLOPT_URL, $url);
  488. curl_setopt($curl, CURLOPT_POST, 1);
  489. curl_setopt($curl, CURLOPT_POSTFIELDS, $param);
  490. $res = curl_exec($curl);
  491. curl_close($curl);
  492. return $res;
  493. }
  494. public function convertUrlQuery($url) {
  495. $arr = parse_url ( $url );
  496. $query = $arr ['query'];
  497. $queryParts = explode ( '&', $query );
  498. $params = array ();
  499. foreach ( $queryParts as $param ) {
  500. $item = explode ( '=', $param );
  501. $params [$item [0]] = $item [1];
  502. }
  503. return $params;
  504. }
  505. /**
  506. * 通过活动创建时间,返回活动ID
  507. */
  508. public function getEventsCreateTimeToId() {
  509. $create_time = Request::g ( 'create_time' );
  510. $create_time = strtotime ( $create_time );
  511. $objEvents = new LotteryEvents ();
  512. $ids = $objEvents->findIdsBy ( array (
  513. 'create_time' => $create_time
  514. ) );
  515. return array_pop ( $ids );
  516. }
  517. /**
  518. * 活动相关页面获取 plat_form_id 方法
  519. */
  520. public function getPlatFormId() {
  521. $url = Request::g ( 'url' );
  522. $objDPlatform = new Platform ();
  523. $data = $objDPlatform->getsAll ();
  524. foreach ( $data as $key => $d ) {
  525. if ($d ['url'] == $url) {
  526. $plat_form_id = $key;
  527. $this->platform = $d;
  528. }
  529. }
  530. if (empty ( $plat_form_id )) {
  531. $plat_form_id = Cookie::get ( 'plat_form_id' );
  532. } else {
  533. Cookie::set ( 'plat_form_id', $plat_form_id, 60 * 60 * 24 * 29, '.' . $_SERVER ['HTTP_HOST'] );
  534. }
  535. return $plat_form_id;
  536. }
  537. /**
  538. * 生成请求参数的sign
  539. *
  540. * @param array $params
  541. * @return String
  542. */
  543. public function createSign(array $params) {
  544. if ($params && is_array ( $params )) {
  545. ksort ( $params );
  546. $str = $this->key;
  547. foreach ( $params as $key => $value ) {
  548. if ($key != 'sign') {
  549. $str .= $key . $value;
  550. }
  551. }
  552. return strtoupper ( md5 ( $str ) );
  553. }
  554. return '';
  555. }
  556. /**
  557. * 指定的sign值是否正确
  558. *
  559. * @param String $sign
  560. * 给定需要验证的sign值
  561. * @param Array $params
  562. * 用来计算sign值的参数集合
  563. * @return Boolean
  564. */
  565. public function checkSign($sign, $params = null) {
  566. $sign2 = $this->createSign ( $params );
  567. return ($sign2 == $sign);
  568. }
  569. public function checkIsFromWeixin($title) {
  570. $state = false;
  571. $user_agent = $_SERVER ['HTTP_USER_AGENT'];
  572. if (preg_match ( '/MicroMessenger/i', $user_agent )) {
  573. $state = true;
  574. }
  575. return $state;
  576. }
  577. /**
  578. *
  579. * @param string $title
  580. */
  581. public function checkIsFromMobile($title) {
  582. //return true;
  583. if (Request::get ( 'debugs' ) == 'rabin') {
  584. return true;
  585. }
  586. // PC 端显示二维码页
  587. $isMobile = false;
  588. $user_agent = $_SERVER ['HTTP_USER_AGENT'];
  589. /*
  590. if (preg_match ( '/MicroMessenger|Mobile/i', $user_agent )) {
  591. $isMobile = true;
  592. }
  593. */
  594. if (preg_match ( '/MicroMessenger|Mobile/i', $user_agent )) {
  595. $isMobile = true;
  596. }
  597. if (! $isMobile) {
  598. include_once Config::getInstance ()->get ( 'App_Path' ) . DS . 'include/phpqrcode/phpqrcode.php';
  599. $IMG_UPLOAD_PATH = Config::getInstance ()->get ( 'upload.path' ) . DS . 'qrcode';
  600. $IMG_UPLOAD_URL = Config::getInstance ()->get ( 'upload.url' ) . DS . 'qrcode';
  601. if (! file_exists ( $IMG_UPLOAD_PATH )) {
  602. if (! mkdir ( $IMG_UPLOAD_PATH, 0775, true )) {
  603. self::fail_exit ( '创建二维码失败,原因:图片目录不存在' );
  604. }
  605. }
  606. $url = Request::url ();
  607. $fileName = Math::md5_16 ( $url ) . '.png';
  608. $save_path = $IMG_UPLOAD_PATH . DS . $fileName;
  609. $save_url = $IMG_UPLOAD_URL . DS . $fileName;
  610. if (! file_exists ( $save_path )) {
  611. \QRcode::png ( $url, $save_path, 3, 6 );
  612. }
  613. $this->tpl = 'pc_qrcode';
  614. $this->setOutput ( 'qrcode', $save_url );
  615. $this->setOutput ( 'title', $title );
  616. $this->setOutput('user_agent', $user_agent);
  617. exit ( $this->render () );
  618. }
  619. }
  620. }