index-apk.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // by 请勿倒卖,已申请软著,否则追究法律责任
  3. error_reporting(0);
  4. include "../../system/db.class.php";
  5. include "../../system/user.php";
  6. Chk_authkey();
  7. $GLOBALS["userlogined"] || reJSON(-1);
  8. $id = $_POST["id"] ? bees_decrypt(SafeRequest("id", "post")) : 0;
  9. $time = SafeRequest("time", "post");
  10. $filename = SafeRequest("filename", "post");
  11. preg_match("/^(\\d+\\-\\d+)\$/", $time) || reJSON(-2);
  12. $tmp = IN_ROOT . "data/tmp/" . $time . "/app.apk";
  13. is_file($tmp) || reJSON(-2);
  14. $in_size = intval(filesize($tmp));
  15. $explode = explode("-", $time);
  16. $icontime = md5($explode[0] . "-" . $explode[1] . "-" . rand(2, pow(2, 24))) . ".png";
  17. $apptime = md5($explode[1] . "-" . $explode[0] . "-" . rand(2, pow(2, 24))) . ".apk";
  18. is_file(IN_ROOT . "data/attachment/" . $apptime) && reJSON(-2);
  19. $in_size + $GLOBALS["xfcms_in_spaceuse"] > $GLOBALS["xfcms_in_spacetotal"] && reJSON(-4);
  20. $originalName = SafeRequest("originalName", "post");
  21. $icon = SafeRequest("icon", "post");
  22. if (strpos($icon, "data:image/png;base64") === false) {
  23. $icon = pack("H*", $icon);
  24. }
  25. $ext = SafeRequest("ext", "post");
  26. $in_name = SafeRequest("appName", "post");
  27. $in_bsvs = SafeRequest("version", "post");
  28. $in_bid = SafeRequest("packageName", "post");
  29. $in_bvs = SafeRequest("versionCode", "post");
  30. $in_size = SafeRequest("fileSize", "post");
  31. $in_mnvs = SafeRequest("minSdkVersion", "post");
  32. $in_form = $ext == "apk" ? "Android" : "iOS";
  33. if (preg_match("/^(data:\\s*image\\/(\\w+);base64,)/", $icon, $result)) {
  34. $img_base64 = str_replace($result[1], "", $icon);
  35. $img_base64 = base64_decode($img_base64);
  36. $fileext = $result[2];
  37. if (in_array(strtolower($fileext), array("pjpeg", "jpeg", "jpg", "gif", "bmp", "png"))) {
  38. $basedir = IN_ROOT . "data/image/app";
  39. $imgdir = date("Y/m/d");
  40. creatdir($basedir . "/" . $imgdir);
  41. $filepath = $basedir . "/" . $imgdir . "/" . $icontime;
  42. $in_icon = $imgdir . "/" . $icontime;
  43. file_put_contents($filepath, $img_base64);
  44. }
  45. }
  46. $in_nick = $in_team = $in_udids = "";
  47. $type = 0;
  48. $function = PHP_OS == "Linux" ? "rename" : "copy";
  49. $function($tmp, IN_ROOT . "data/attachment/" . $apptime);
  50. $deduct = getDeduct($in_size);
  51. $data = array("in_name" => $in_name, "in_type" => $type, "in_size" => $in_size, "in_form" => $in_form, "in_mnvs" => $in_mnvs, "in_bid" => $in_bid, "in_bsvs" => $in_bsvs, "in_bvs" => $in_bvs, "in_nick" => $in_nick, "in_team" => $in_team, "in_icon" => $in_icon, "in_app" => $apptime, "in_deduct" => $deduct, "in_originalName" => $filename, "in_updatetime" => time(), "remote" => 0);
  52. $app = db("appid")->where("in_uid", $GLOBALS["xfcms_in_userid"])->where("in_form", $in_form)->where("in_bid", $in_bid)->where("in_name", $in_name)->find();
  53. if ($app) {
  54. $id = $app["in_id"];
  55. db("app")->where("in_appid", $id)->update(array("in_release" => "0"));
  56. db("appid")->where("in_id", $id)->update($data);
  57. @unlink(IN_ROOT . "data/image/app/" . $app["in_icon"]);
  58. } else {
  59. $data = array_merge($data, array("in_uid" => $GLOBALS["xfcms_in_userid"], "in_uname" => $GLOBALS["xfcms_in_username"], "in_udids" => $in_udids, "in_link" => creatLink(), "in_deduct" => $deduct, "in_addtime" => time()));
  60. $id = db("appid")->insertGetId($data);
  61. }
  62. $logData = db("appid")->where("in_id", $id)->find();
  63. $logData["in_appid"] = $logData["in_id"];
  64. unset($logData["in_id"]);
  65. $logData["in_addtime"] = time();
  66. db("app")->strict(false)->insert($logData);
  67. db("user")->where("in_userid", $GLOBALS["xfcms_in_userid"])->inc("in_spaceuse", $in_size)->update();
  68. reJSON(array("id" => bees_encrypt($id)), 1);