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