app_update.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * 更新
  4. */
  5. defined('InShopNC') or exit('Access Invalid!');
  6. class app_updateControl extends mobileHomeControl
  7. {
  8. const CACHE_KEY = "app_update";
  9. const CACHE_CHECK_VERSION_ID = 1;
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. }
  14. // 验证版本
  15. public function checkVersionOp()
  16. {
  17. $ver_code = $_GET['ver_code'];
  18. $app_platform = $_GET['platform'];
  19. if (isset($app_platform) && isset($ver_code)) {
  20. // cache中读取
  21. $ret = rcache(self::CACHE_KEY, self::CACHE_CHECK_VERSION_ID);
  22. if (empty($ret)) {
  23. $model = Model();
  24. $data = $model->table('app_update')->where(array('cur_version' => '1', 'enable' => '1', 'platform' => $app_platform))->limit(1)->select();
  25. if (empty($data)) {
  26. joutput_error('系统错误!');
  27. return;
  28. }
  29. // 写入cache
  30. wcache(self::CACHE_KEY, array("cur_version" => serialize($data)), self::CACHE_CHECK_VERSION_ID);
  31. } else {
  32. $data = unserialize($ret['cur_version']);
  33. }
  34. $result = array();
  35. $lowest_compatible_version = intval($data[0]['lowest_compatible_version']);
  36. if ($ver_code === $data[0]['ver_code']) {
  37. $result['latest'] = 0;
  38. } else {
  39. $result['latest'] = 1;
  40. // 强制升级
  41. if ($lowest_compatible_version > intval($ver_code)) {
  42. $result['force_update'] = 1;
  43. } else {
  44. $result['force_update'] = 0;
  45. }
  46. $update_info = array();
  47. $update_info['ver_code'] = $data[0]['ver_code'];
  48. $update_info['app_path'] = $data[0]['app_path'];
  49. $update_info['release_note'] = $data[0]['release_note'];
  50. $update_info['remind_time'] = $data[0]['remind_time'];
  51. $parse_url = parse_url($update_info['app_path']);
  52. $update_info['md5_file'] = md5_file(BASE_ROOT_PATH . $parse_url['path']);
  53. $result['update_info'] = $update_info;
  54. }
  55. joutput_data($result);
  56. } else {
  57. output_error('请输入平台和版本号!');
  58. }
  59. }
  60. }