Upgrade.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. // +---------------------------------------------------------------------+
  3. // | NiuCloud | [ WE CAN DO IT JUST NiuCloud ]  |
  4. // +---------------------------------------------------------------------+
  5. // | Copy right 2019-2029 www.niucloud.com  |
  6. // +---------------------------------------------------------------------+
  7. // | Author | NiuCloud <niucloud@outlook.com>  |
  8. // +---------------------------------------------------------------------+
  9. // | Repository | https://github.com/niucloud/framework.git  |
  10. // +---------------------------------------------------------------------+
  11. namespace app\model\system;
  12. use app\model\BaseModel;
  13. use think\facade\Db;
  14. class Upgrade extends BaseModel
  15. {
  16. private $url = "https://www.niushop.com.cn/auth/Upgrade/%s";
  17. private $cert;
  18. public function __construct()
  19. {
  20. if (file_exists('cert.key')) {
  21. $this->cert = file_get_contents('cert.key');
  22. }
  23. }
  24. /**
  25. * 获取可升级的版本信息
  26. */
  27. public function getUpgradeVersion()
  28. {
  29. $url = sprintf($this->url, 'getUpgradeVersion');
  30. $post_data = [
  31. 'cert' => $this->cert,
  32. 'version_release' => SYS_RELEASE,
  33. 'module_mark' => SYS_VERSION
  34. ];
  35. $re = $this->doPost($url, $post_data);
  36. $re = json_decode($re, true);
  37. return $re;
  38. }
  39. /**
  40. * 在线下载文件
  41. * @param $param
  42. */
  43. public function download($param)
  44. {
  45. //验证授权
  46. $file = $param["file"];//下载文件路径
  47. $url = sprintf($this->url, 'download');
  48. $data = array(
  49. "module_mark" => $param["module_mark"],
  50. "version_release" => $param["version_release"],
  51. "file" => $file,
  52. "token" => $param["token"]
  53. );
  54. $result = $this->doPost($url, $data);//授权
  55. if (empty($result))
  56. return $this->error();
  57. $result = json_decode($result, true);
  58. return $result;
  59. }
  60. /**
  61. * 获取版本详情
  62. */
  63. public function getUpgradeInfo($last_version_release)
  64. {
  65. $url = sprintf($this->url, 'getUpgradeInfo');
  66. $post_data = [
  67. 'cert' => $this->cert,
  68. 'version_release' => SYS_RELEASE,
  69. 'module_mark' => SYS_VERSION,
  70. 'last_version_release' => $last_version_release
  71. ];
  72. $re = $this->doPost($url, $post_data);
  73. $re = json_decode($re, true);
  74. return $re;
  75. }
  76. /**
  77. * 获取授权信息
  78. * @return bool|mixed|string
  79. */
  80. public function authInfo()
  81. {
  82. $url = sprintf($this->url, 'authInfo');
  83. $post_data = [
  84. 'cert' => $this->cert
  85. ];
  86. $re = $this->doPost($url, $post_data);
  87. $re = json_decode($re, true);
  88. return $re;
  89. }
  90. /**
  91. * 获取最新的版本信息
  92. * @return bool|string
  93. */
  94. public function getLatestVersion()
  95. {
  96. $url = sprintf($this->url, 'getLatestVersion');
  97. $post_data = [
  98. 'cert' => $this->cert
  99. ];
  100. $re = $this->doPost($url, $post_data);
  101. $re = json_decode($re, true);
  102. return $re;
  103. }
  104. /**
  105. * 文件对比
  106. * @param $data
  107. * @return bool|mixed|string
  108. */
  109. public function getTowDevFiles($data)
  110. {
  111. $url = sprintf($this->url, 'fileContrast');
  112. $post_data = [
  113. 'cert' => $this->cert,
  114. 'module_release' => SYS_RELEASE,
  115. 'module_mark' => SYS_VERSION,
  116. 'files' => json_encode($data, true),
  117. ];
  118. $re = $this->doPost($url, $post_data);
  119. $re = json_decode($re, true);
  120. return $re;
  121. }
  122. /**
  123. * 查询所有表
  124. */
  125. public function getDatabaseList()
  126. {
  127. $databaseList = Db::query("SHOW TABLE STATUS");
  128. return $databaseList;
  129. }
  130. /**
  131. * post 服务器请求
  132. */
  133. private function doPost($post_url, $post_data)
  134. {
  135. $ch = curl_init();
  136. curl_setopt($ch, CURLOPT_URL, $post_url);
  137. curl_setopt($ch, CURLOPT_HEADER, 0);
  138. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  139. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  140. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  141. if ($post_data != '' && !empty($post_data)) {
  142. curl_setopt($ch, CURLOPT_POST, 1);
  143. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  144. }
  145. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  146. $result = curl_exec($ch);
  147. curl_close($ch);
  148. return $result;
  149. }
  150. }