DefaultController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Class DefaultController
  4. * @author Blackbinbin
  5. */
  6. class DefaultController extends BaseController {
  7. public function __construct() {
  8. parent::__construct(true);
  9. }
  10. /**
  11. * 判断ip,输出首页
  12. */
  13. public function actionIndex() {
  14. // if (ENV != ENV_DEV) {
  15. // header('Location: https://dice.eosget.io/#/box');
  16. // Response::exitMsg('');
  17. // } else {
  18. // // 清除无效的cookie
  19. // Account::checkToken();
  20. //
  21. // if (ENV != ENV_DEV) {
  22. // $GLOBALS['eosProtocol'] = "https";
  23. // $GLOBALS['eosHost'] = "api.eosbeijing.one";
  24. // $GLOBALS['eosPort'] = 443;
  25. // }
  26. $this->tpl->display('index');
  27. // }
  28. }
  29. /**
  30. * 判断ip,输出首页
  31. */
  32. public function actionMini() {
  33. $this->tpl->display('mini');
  34. }
  35. /**
  36. * 判断ip,输出首页
  37. */
  38. public function actionSw() {
  39. // 不需要默认头部信息
  40. $GLOBALS['FORBID_ORIGIN'] = true;
  41. $path = BASE_DIR . 'dist/sw.js';
  42. // 增加浏览器缓存
  43. $filemd5 = md5_file($path);
  44. $this->_addEtag($filemd5);
  45. $content = file_get_contents($path);
  46. header("Content-Type: application/javascript; charset=utf-8");
  47. Response::exitMsg($content, CODE_SUCCESS, null, true);
  48. }
  49. private function _addEtag($etag) {
  50. // always send headers
  51. header("Etag: $etag");
  52. // exit if not modified
  53. if (@trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
  54. header("HTTP/1.1 304 Not Modified");
  55. Response::exitMsg('', CODE_SUCCESS, '304 Not Modified');
  56. }
  57. }
  58. /**
  59. * 分享跳转
  60. * @author solu
  61. * @param $args
  62. */
  63. public function actionShare($args) {
  64. $rules = [
  65. 'group_name' => ['string', 'reg' => '/^[a-z0-9\.]+/i', 'desc' => '群名'],
  66. ];
  67. Param::checkParam2($rules, $args);
  68. $objGroup = new GroupInfo();
  69. $group = $objGroup->objTable->getRow(['group_name' => $args['group_name']], ['_field' => 'group_id, group_name, group_title']);
  70. $groupId = $group['group_id'] ?: GroupInfo::OFFICIAL_ID;
  71. $format = '%s/#/group/%s';
  72. if (is_mobile_request()) {
  73. $format = '%s/h5.html#/group/%s';
  74. }
  75. $url = sprintf($format, URL_SELF, $groupId);
  76. Response::exitMsg("<script>location.replace('{$url}')</script>");
  77. }
  78. }