app.php 12 KB

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