app.php 12 KB

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