app.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <?php
  2. namespace app\index;
  3. class app extends Base
  4. {
  5. protected $template_note;
  6. function getMobileType() {
  7. $userAgent = $_SERVER['HTTP_USER_AGENT'];
  8. // 检查iOS设备
  9. if (dstrpos($userAgent, ['iphone', 'ipad', 'ipod', 'ios'])) {
  10. return 'ios';
  11. }
  12. // 检查Android设备
  13. if (dstrpos($userAgent, ['android'])) {
  14. return 'android';
  15. }
  16. return 'unknown';
  17. }
  18. function index($info = '', $module = '')
  19. {
  20. $uri = trim($_SERVER['REQUEST_URI'], '/');
  21. if($uri){
  22. $check = db("combine")->where('short', $uri)->find();
  23. // print_r($check);die;
  24. if(!empty($check)){
  25. $system = $this->getMobileType();
  26. header("Location: ".$check[$system]);
  27. }
  28. }
  29. $ssid = SafeRequest('ssid', 'get');
  30. $authcode = SafeRequest('authcode', 'get');
  31. $authcode && setcookie('downcode', $authcode);
  32. //微信
  33. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false || (strpos($_SERVER['HTTP_USER_AGENT'], 'QQ') !== false && strpos($_SERVER['HTTP_USER_AGENT'], '_SQ_') !== false)) {
  34. //include 'source/template/weixin.php';
  35. //exit;
  36. }
  37. $domain = $_SERVER['HTTP_HOST'];
  38. if (IN_TZDOMAIN && IN_SJDOMAIN && $domain == IN_TZDOMAIN) {
  39. $sjdomain = explode(',', IN_SJDOMAIN);
  40. for ($i = 0; $i < count($sjdomain); $i++) {
  41. $sjdomain[$i];
  42. }
  43. $rsl = max(intval(IN_DOMAIN_RANDOMSTR_LEN), 1);
  44. $out = rand(0, count($sjdomain) - 1);
  45. $ssl= is_ssl()?'https://':'http://';
  46. $sjurl = $ssl . str_replace('*', Randomstr($rsl), $sjdomain[$out]) . $_SERVER['PATH_INFO'] . ($ssid ? '?ssid=' . $ssid . '&' : '?') . 't=' . time();
  47. redirect($sjurl);
  48. }
  49. //链接有效期
  50. if (IN_APPDOWNPAGETIME && is_numeric(IN_APPDOWNPAGETIME)) {
  51. if (!isset($_GET['t'])) {
  52. $ssl= is_ssl()?'https://':'http://';
  53. $sjurl = $ssl . $domain . $_SERVER['PATH_INFO'] . ($ssid ? '?ssid=' . $ssid . '&' : '?') . 't=' . time();
  54. redirect($sjurl);
  55. }
  56. $timestr = $_GET['t'];
  57. if (!$ssid && !isset($_GET['authcode']) && !isset($_GET['password']) && $timestr < strtotime('-' . IN_APPDOWNPAGETIME . ' minute')) {
  58. exit('<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /><title>友情提示</title></head><body bgcolor="#FFFFFF"><center><br><br><br><br><br><br><br><font size="5" color="red">链接已过期,请重新下载!</font></center></body></html>');
  59. }
  60. }
  61. if ($info == 's') {
  62. return redirect("/$module/$info");
  63. }
  64. $link = trim($info);
  65. $id = auth_codes($info, 'de');
  66. if (is_numeric($id)) {
  67. $row = db('appid')->where('in_id', $id)->find();
  68. } else {
  69. $row = db('appid')->where('in_link', $link)->find();
  70. }
  71. $this->template_note = getTemplateData(isset($row['template_language']) ? $row['template_language'] : 'zh');
  72. if (!$row || $row['in_sign_type'] == 2 && (!$row['in_super'] || !IN_SUPER) || $row['in_sign_type'] == 1 && !IN_DIST_ON) {
  73. $this->reError('APP_EXPIRED');
  74. }
  75. if (is_mobile() && $row['in_captcha'] && (!$_SESSION['captcha' . $row['in_id']] || $_SESSION['captcha' . $row['in_id']] != $_SESSION['code'])) {
  76. $this->captcha($row);
  77. exit();
  78. }
  79. if ($row['in_applock']) {
  80. //非法操作
  81. $this->reError([-2 => 'APP_EXPIRED', -1 => 'APP_CHECKING', 1 => 'APP_ILLEGAL'][$row['in_applock']]);
  82. }
  83. $password = SafeRequest("password", "get");
  84. if (!empty($password) && $password != $row['in_apppwd']) {
  85. //密码错误
  86. $this->reError('APP_PASSWORD_ERROR');
  87. }
  88. $user = db('user')->where('in_userid', $row['in_uid'])->find();
  89. if (!$user || $user['in_islock'] || $user['in_release']) {
  90. //非法操作
  91. $this->reError('APP_EXPIRED');
  92. }
  93. if ($user['in_verify'] != 1 && IN_VERIFY > 0) {
  94. //未实名认证
  95. $this->reError('REALNAME_LAYER_TITLE');
  96. }
  97. if ($user['in_points'] <= $row['in_deduct'] && !$row['in_super'] or $row['in_applimit'] <= $row['in_downloads'] && $row['in_applimit'] != 0) {
  98. //分发次数耗尽
  99. $this->reError('APP_DOWNLOAD_TIMES_OVER');
  100. }
  101. if (dstrpos($_SERVER['HTTP_USER_AGENT'], ['iphone', 'ipad', 'ipod', 'mac', 'ios', 'playbook'])) {
  102. if ($row['in_form'] == 'Android') {
  103. if ($row['in_kid']) {
  104. redirect(getlink($row['in_kid'], $module == 's'));
  105. }
  106. }
  107. } else if (dstrpos($_SERVER['HTTP_USER_AGENT'], ['android'])) {
  108. if ($row['in_form'] == 'iOS') {
  109. if ($row['in_kid']) {
  110. redirect(getlink($row['in_kid']));
  111. }
  112. }
  113. }
  114. if (!empty($row['in_appstore'])) {
  115. //跳转应用商店
  116. redirect($row['in_appstore']);
  117. }
  118. //超级签名
  119. if ($row['in_sign_type'] == 2 && $row['in_super'] && IN_SUPER) {
  120. if ($ssid) {
  121. $super_sign = db('super_sign')->where('id', $ssid)->find();
  122. if (!$super_sign) {
  123. redirect(getlink($row['in_id']));
  124. }
  125. $udid = $super_sign['udid'];
  126. if ($udid) {
  127. setcookie('udid', $udid, time() + 999999999);
  128. }
  129. if ($super_sign['status'] != 5) {
  130. db('super_sign')->where('id', $ssid)->update(['status' => '1', 'sign_time' => time()]);
  131. }
  132. $has_ssid = db('ios_device')->where('udid', $udid)->value('cert_iss');
  133. if (!$has_ssid && $user['device_num'] < 1 && $user['prv_device_num'] < 1) {
  134. //超级签名,设备耗尽
  135. $this->reError('APP_DOWNLOAD_TIMES_OVER');
  136. }
  137. }
  138. }
  139. $did = db('downhistory')->where('appid', $row['in_id'])->whereTime('addtime', 'today')->value('id');
  140. if (empty($did)) {
  141. $setarr = array(
  142. 'appid' => $row['in_id'],
  143. 'uid' => $row['in_uid'],
  144. 'appname' => $row['in_name'],
  145. 'appversion' => $row['in_bsvs'],
  146. 'appsize' => $row['in_size'],
  147. 'liulan' => 1,
  148. 'down' => 0,
  149. 'addtime' => date('Y-m-d H:i:s')
  150. );
  151. db('downhistory')->insert($setarr);
  152. } else {
  153. db('downhistory')->where('appid', $row['in_id'])->whereTime('addtime', 'today')->inc('liulan')->update();
  154. }
  155. if ($row['in_sign_type'] == 0) {
  156. @$this->steal($row);
  157. }
  158. if ($row['template'] == 7) {
  159. include 'source/template/7.php';
  160. } else {
  161. include 'source/template/app.php';
  162. }
  163. }
  164. function reError($msg)
  165. {
  166. $ERROR_MESSAGE = isset($this->template_note[$msg]) ? $this->template_note[$msg] : $msg;
  167. (new \app\error\error())->message($ERROR_MESSAGE, $this->template_note['BACK_HOME']);
  168. exit;
  169. }
  170. function captcha($row)
  171. {
  172. ?>
  173. <!DOCTYPE html>
  174. <html lang="">
  175. <head>
  176. <title><?php echo $row['in_name'] ?></title>
  177. <meta charset="utf-8"/>
  178. <meta name="viewport"
  179. content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  180. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
  181. <meta name="renderer" content="webkit"/>
  182. <meta name="keywords" content="<?php echo IN_KEYWORDS ?>"/>
  183. <meta property="og:url" content="https://<?php echo $_SERVER['HTTP_HOST'] ?>/"/>
  184. <meta property="og:title" content="<?php echo IN_NAME ?>"/>
  185. <meta name="description" content="<?php echo IN_DESCRIPTION ?>"/>
  186. <?php $this->static_() ?>
  187. <script src="/static/index/js/clipboard.min.js"></script>
  188. <script>
  189. function update_seccode() {
  190. document.getElementById('img_seccode').src = '<?php echo IN_PATH ?>index/seccode?' + Math.random();
  191. }
  192. </script>
  193. <style>
  194. .tit {
  195. display: table;
  196. width: 100%;
  197. }
  198. .tit a {
  199. line-height: 35px;
  200. font-size: 15px;
  201. display: table-cell;
  202. width: 48%;
  203. text-align: center;
  204. border-bottom: 2px solid beige;
  205. }
  206. .tit a.active {
  207. font-size: 18px;
  208. color: #333;
  209. border-bottom: 2px solid #157df1;
  210. }
  211. .index1 {
  212. display: none;
  213. }
  214. </style>
  215. </head>
  216. <body>
  217. <div class="login-common">
  218. <div style="margin: 5px auto;overflow: hidden;border-radius: 9px;width: 90px;height: 90px;">
  219. <img src="<?php echo geticon($row['in_icon']) ?>" style="width: 100%;height: 100%;"/>
  220. </div>
  221. <div style="text-align: center;line-height: 30px;margin-bottom: 25px;">
  222. <?php echo $row['in_name'] ?>
  223. </div>
  224. <form action="" method="post">
  225. <div class="form-container">
  226. <div class="form-inner">
  227. <div class="form-group">
  228. <label class="iconfont icon-dunpai"></label>
  229. <div class="clearfix verification-code">
  230. <input class="form-control input-lg fl" placeholder="请输入图形验证码" type="text" name="captcha" maxlength="4">
  231. <img id="img_seccode" onclick="update_seccode()" style="float:right" src="/index/seccode" height="46" width="27%">
  232. </div>
  233. </div>
  234. <div id="errorMsg" style="line-height: 35px;color: orangered;display: none;">请输入验证码</div>
  235. </div>
  236. </div>
  237. <button type="button" id="submitButton" class="ms-btn ms-btn-primary input-lg mt20">确认</button>
  238. </form>
  239. </div>
  240. <script>
  241. $("#submitButton").click(function () {
  242. var captcha = $("input[name=captcha]").val();
  243. if (!captcha) {
  244. return $('#errorMsg').show();
  245. }
  246. $.post("/index/app/captcha_check", {captcha, in_id:<?php echo $row['in_id']?>}, function (ret) {
  247. ret.msg && alert(ret.msg);
  248. if (ret.code) {
  249. location.reload();
  250. }
  251. }, 'json');
  252. });
  253. </script>
  254. </body>
  255. </html>
  256. <?php }
  257. function captcha_check()
  258. {
  259. $captcha = SafeRequest('captcha');
  260. $in_id = SafeRequest('in_id');
  261. $res = intval($captcha == $_SESSION['code']);
  262. $res && $_SESSION['captcha' . $in_id] = $captcha;
  263. reJSON($res ? '' : '验证码错误', $res);
  264. }
  265. }