DefaultController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * Class DefaultController
  4. * @author Blackbinbin
  5. */
  6. class DefaultController extends BaseController {
  7. protected $ajaxLoginActions = [
  8. 'tick',
  9. ];
  10. public function __construct() {
  11. parent::__construct(true);
  12. }
  13. /**
  14. * 判断ip,输出首页
  15. */
  16. public function actionIndex() {
  17. $this->tpl->display('index');
  18. }
  19. /**
  20. * 判断ip,输出首页
  21. */
  22. public function actionMini() {
  23. $html = $this->tpl->fetch('mini');
  24. $html = str_replace('<link rel=manifest ', '<link ', $html);
  25. Response::exitMsg($html, CODE_SUCCESS, '', true);
  26. }
  27. public function actionPC() {
  28. $html = $this->tpl->fetch('pc');
  29. // <link rel=manifest href="//static.meechat.me/cdn/new.mee.chat/dist/manifest
  30. $html = str_replace('/dist/manifest.json', '/manifest_pc.json', $html);
  31. Response::exitMsg($html, CODE_SUCCESS, '', true);
  32. }
  33. public function actionH5() {
  34. $html = $this->tpl->fetch('h5');
  35. $html = str_replace('/dist/manifest.json', '/manifest_h5.json', $html);
  36. // static.meechat.me/cdn/new.mee.chat/dist/manifest.json
  37. Response::exitMsg($html, CODE_SUCCESS, '', true);
  38. }
  39. public function actionManifest($args) {
  40. if ($args['type'] == 'pc') {
  41. $startUrl = '/pc.html?pwa=1';
  42. } else {
  43. $startUrl = '/h5.html?pwa=1';
  44. }
  45. $this->tpl->assign(compact('startUrl'));
  46. $this->tpl->postfix = '.json';
  47. if (ENV == ENV_DEV) {
  48. $env = '[测试]';
  49. } else if (ENV == ENV_NEW) {
  50. $env = '[预发布]';
  51. } else {
  52. $env = '';
  53. }
  54. // 不需要默认头部信息
  55. $GLOBALS['FORBID_ORIGIN'] = true;
  56. header("Content-Type: application/json; charset=utf-8");
  57. $this->tpl->assign(compact('env'));
  58. $this->tpl->display('manifest', CODE_SUCCESS);
  59. }
  60. /**
  61. * 判断ip,输出首页
  62. */
  63. public function actionSw() {
  64. // 不需要默认头部信息
  65. $GLOBALS['FORBID_ORIGIN'] = true;
  66. $path = BASE_DIR . 'dist/sw.js';
  67. // 增加浏览器缓存
  68. $filemd5 = md5_file($path);
  69. $this->_addEtag($filemd5);
  70. $content = file_get_contents($path);
  71. header("Content-Type: application/javascript; charset=utf-8");
  72. Response::exitMsg($content, CODE_SUCCESS, null, true);
  73. }
  74. private function _addEtag($etag) {
  75. // always send headers
  76. header("Etag: $etag");
  77. // exit if not modified
  78. if (@trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
  79. header("HTTP/1.1 304 Not Modified");
  80. Response::exitMsg('', CODE_SUCCESS, '304 Not Modified');
  81. }
  82. }
  83. /**
  84. * 分享跳转
  85. * @author solu
  86. * @param $args
  87. */
  88. public function actionShare($args) {
  89. $rules = [
  90. 'group_name' => ['string', 'reg' => '/^[a-z0-9\.]+/i', 'desc' => '群名'],
  91. ];
  92. Param::checkParam2($rules, $args);
  93. $objGroup = new GroupInfo();
  94. $group = $objGroup->objTable->getRow(['group_name' => $args['group_name']], ['_field' => 'group_id, group_name, group_title']);
  95. $groupId = $group['group_id'] ?: GroupInfo::OFFICIAL_ID;
  96. $format = '%s/#/group/%s';
  97. if (is_mobile_request()) {
  98. $format = '%s/h5.html#/group/%s';
  99. }
  100. $url = sprintf($format, URL_SELF, $groupId);
  101. Response::exitMsg("<script>location.replace('{$url}')</script>");
  102. }
  103. /**
  104. * 申请群认证
  105. * @author solu
  106. * @param $args
  107. * @return array
  108. */
  109. public function actionGroupAuth($args) {
  110. $rules = [
  111. 'group_id' => ['int', 'desc' => '群id'],
  112. ];
  113. Param::checkParam2($rules, $args);
  114. $userId = User::getUserId();
  115. if (!(new UserGroup())->isAdmin($args['group_id'], $userId)) {
  116. Response::error(CODE_NO_PERMITION);
  117. }
  118. $serverId = CHAT_SERVER_ID; // 客服id
  119. $msg =<<<MSG
  120. 欢迎申请群组认证,您需要提供如下信息:
  121. 1. 项目地址(如:https://vsbet.io/)
  122. 2. 代币合约名(如:vsvscontract)
  123. 3. 代币名(如:VS)
  124. -------以下内容为可选提供----------
  125. 4. Vip合约名(如:vsvsvsvipvip)
  126. 5. Vip表名(如:t.player)
  127. 6. 等级字段名(如:vip_level)
  128. 7. 投注额字段名(如:total_energy)
  129. 4~7选项,用于后续在聊天内显示用户vip等功能。
  130. MSG;
  131. $msg = Utils::encodeRC4($msg);
  132. $objSession = new Session();
  133. $sessionId = Session::getPersonSessionId($serverId, $userId);
  134. try {
  135. $objSession->sendPersonMsg($serverId, $sessionId, Session::MSG_TYPE_TEXT, $msg, true);
  136. } catch (Exception $e) {}
  137. return compact('serverId');
  138. }
  139. /**
  140. * 问题反馈
  141. * @author solu
  142. * @param $args
  143. * @return array
  144. */
  145. public function actionTick($args) {
  146. $rules = [];
  147. Param::checkParam2($rules, $args);
  148. $userId = User::getUserId();
  149. $serverId = CHAT_SERVER_ID; // 客服id
  150. $msg =<<<MSG
  151. Hi,请问您遇到了什么问题?
  152. MSG;
  153. $msg = Utils::encodeRC4($msg);
  154. $objSession = new Session();
  155. $sessionId = Session::getPersonSessionId($serverId, $userId);
  156. try {
  157. $objSession->sendPersonMsg($serverId, $sessionId, Session::MSG_TYPE_TEXT, $msg, true);
  158. } catch (Exception $e) {}
  159. return compact('serverId');
  160. }
  161. }