Science.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\admin\controller\setting;
  13. use think\response\Json;
  14. use app\admin\controller\Controller;
  15. use app\common\library\helper;
  16. /**
  17. * 环境检测
  18. * Class Science
  19. * @package app\admin\controller\setting
  20. */
  21. class Science extends Controller
  22. {
  23. /**
  24. * 环境检测
  25. * @return Json
  26. */
  27. public function info(): Json
  28. {
  29. return $this->renderSuccess([
  30. 'scienceInfo' => [
  31. 'server' => $this->server(), // 服务器信息
  32. 'phpinfo' => $this->phpinfo(), // PHP环境要求
  33. 'writeable' => $this->writeable(), // 目录权限监测
  34. ]
  35. ]);
  36. }
  37. /**
  38. * 服务器信息
  39. * @return array
  40. */
  41. private function server(): array
  42. {
  43. return [
  44. [
  45. 'name' => '服务器操作系统',
  46. 'key' => 'system',
  47. 'value' => PHP_OS,
  48. 'status' => PHP_SHLIB_SUFFIX === 'dll' ? 'warning' : 'normal',
  49. 'remark' => '建议使用 Linux 系统以提升程序性能'
  50. ],
  51. [
  52. 'name' => 'Web服务器环境',
  53. 'key' => 'webserver',
  54. 'value' => $this->request->server('SERVER_SOFTWARE'),
  55. 'status' => PHP_SAPI === 'isapi' ? 'warning' : 'normal',
  56. 'remark' => '建议使用 Apache 或 Nginx 以提升程序性能'
  57. ],
  58. [
  59. 'name' => 'PHP版本',
  60. 'key' => 'php',
  61. 'value' => PHP_VERSION,
  62. 'status' => version_compare(PHP_VERSION, '7.2.0') === -1 ? 'danger' : 'normal',
  63. 'remark' => 'PHP版本必须为 7.2.0 以上'
  64. ],
  65. [
  66. 'name' => 'PHP运行位数',
  67. 'key' => 'system',
  68. 'value' => (PHP_INT_SIZE === 4 ? '32' : '64') . '位',
  69. 'status' => PHP_INT_SIZE === 4 ? 'warning' : 'normal',
  70. 'remark' => '建议使用 64位 PHP以提升程序性能'
  71. ],
  72. // [
  73. // 'name' => '文件上传功能',
  74. // 'key' => 'file_uploads',
  75. // 'value' => !ini_get('file_uploads') ? '关闭' : '开启',
  76. // 'status' => !ini_get('file_uploads') ? 'danger' : 'normal',
  77. // 'remark' => '文件上传必须开启 file_uploads'
  78. // ],
  79. [
  80. 'name' => '文件上传最大值',
  81. 'key' => 'upload_max_filesize',
  82. 'value' => ini_get('upload_max_filesize'),
  83. 'status' => $this->compareBytes(ini_get('upload_max_filesize'), '10m') ? 'danger' : 'normal',
  84. 'remark' => '不能小于10MB;请修改php.ini中upload_max_filesize'
  85. ],
  86. [
  87. 'name' => 'POST数据最大值',
  88. 'key' => 'post_max_size',
  89. 'value' => ini_get('post_max_size'),
  90. 'status' => $this->compareBytes(ini_get('post_max_size'), '12m') ? 'danger' : 'normal',
  91. 'remark' => '不能小于12MB;请修改php.ini中post_max_size'
  92. ],
  93. [
  94. 'name' => '程序运行目录',
  95. 'key' => 'web_path',
  96. 'value' => str_replace('\\', '/', web_path()),
  97. 'status' => 'normal',
  98. 'remark' => ''
  99. ],
  100. ];
  101. }
  102. /**
  103. * PHP环境要求
  104. * get_loaded_extensions()
  105. * @return array
  106. */
  107. private function phpinfo(): array
  108. {
  109. return [
  110. [
  111. 'name' => 'PHP版本',
  112. 'key' => 'php_version',
  113. 'value' => '7.2.0及以上',
  114. 'status' => version_compare(PHP_VERSION, '7.2.0') === -1 ? 'danger' : 'normal',
  115. 'remark' => 'PHP版本必须为 7.2.0及以上'
  116. ],
  117. [
  118. 'name' => 'Mysqlnd',
  119. 'key' => 'mysqlnd',
  120. 'value' => '支持',
  121. 'status' => extension_loaded('mysqlnd') ? 'normal' : 'danger',
  122. 'remark' => '您的PHP环境不支持mysqlnd, 系统无法正常运行'
  123. ],
  124. [
  125. 'name' => 'CURL',
  126. 'key' => 'curl',
  127. 'value' => '支持',
  128. 'status' => extension_loaded('curl') && function_exists('curl_init') ? 'normal' : 'danger',
  129. 'remark' => '您的PHP环境不支持CURL, 系统无法正常运行'
  130. ],
  131. [
  132. 'name' => 'OpenSSL',
  133. 'key' => 'openssl',
  134. 'value' => '支持',
  135. 'status' => extension_loaded('openssl') ? 'normal' : 'danger',
  136. 'remark' => '没有启用OpenSSL, 将无法访问微信平台的接口'
  137. ],
  138. [
  139. 'name' => 'PDO',
  140. 'key' => 'pdo',
  141. 'value' => '支持',
  142. 'status' => extension_loaded('PDO') && extension_loaded('pdo_mysql') ? 'normal' : 'danger',
  143. 'remark' => '您的PHP环境不支持PDO, 系统无法正常运行'
  144. ],
  145. [
  146. 'name' => 'GD',
  147. 'key' => 'gd',
  148. 'value' => '支持',
  149. 'status' => extension_loaded('gd') ? 'normal' : 'danger',
  150. 'remark' => '您的PHP环境不支持GD, 系统无法正常生成图片'
  151. ],
  152. [
  153. 'name' => 'BCMath',
  154. 'key' => 'bcmath',
  155. 'value' => '支持',
  156. 'status' => extension_loaded('bcmath') ? 'normal' : 'danger',
  157. 'remark' => '您的PHP环境不支持BCMath, 系统无法正常运行'
  158. ],
  159. [
  160. 'name' => 'mbstring',
  161. 'key' => 'mbstring',
  162. 'value' => '支持',
  163. 'status' => extension_loaded('mbstring') ? 'normal' : 'danger',
  164. 'remark' => '您的PHP环境不支持mbstring, 系统无法正常运行'
  165. ],
  166. [
  167. 'name' => 'SimpleXML',
  168. 'key' => 'simplexML',
  169. 'value' => '支持',
  170. 'status' => extension_loaded('SimpleXML') ? 'normal' : 'danger',
  171. 'remark' => '您的PHP环境不支持SimpleXML, 系统无法解析xml 无法使用微信支付'
  172. ],
  173. ];
  174. }
  175. /**
  176. * 目录权限监测
  177. */
  178. private function writeable(): array
  179. {
  180. $paths = [
  181. 'uploads' => realpath(web_path()) . '/uploads/',
  182. 'temp' => realpath(web_path()) . '/temp/',
  183. 'wxpay_log' => realpath(base_path()) . '/common/library/wechat/logs/',
  184. 'wxpay_cert' => realpath(base_path()) . '/common/library/wechat/cert/',
  185. ];
  186. return [
  187. [
  188. 'name' => '文件上传目录',
  189. 'key' => 'uploads',
  190. 'value' => str_replace('\\', '/', $paths['uploads']),
  191. 'status' => helper::checkWriteable($paths['uploads']) ? 'normal' : 'danger',
  192. 'remark' => '目录不可写,系统将无法正常上传文件'
  193. ],
  194. [
  195. 'name' => '临时文件目录',
  196. 'key' => 'temp',
  197. 'value' => str_replace('\\', '/', $paths['temp']),
  198. 'status' => helper::checkWriteable($paths['temp']) ? 'normal' : 'danger',
  199. 'remark' => '目录不可写,系统将无法正常写入文件'
  200. ],
  201. // [
  202. // 'name' => '微信支付日志目录',
  203. // 'key' => 'wxpay_log',
  204. // 'value' => str_replace('\\', '/', $paths['wxpay_log']),
  205. // 'status' => helper::checkWriteable($paths['wxpay_log']) ? 'normal' : 'danger',
  206. // 'remark' => '目录不可写,系统将无法正常写入文件'
  207. // ],
  208. [
  209. 'name' => '微信支付证书目录',
  210. 'key' => 'wxpay_cert',
  211. 'value' => str_replace('\\', '/', $paths['wxpay_cert']),
  212. 'status' => helper::checkWriteable($paths['wxpay_cert']) ? 'normal' : 'danger',
  213. 'remark' => '目录不可写,系统将无法正常写入文件'
  214. ],
  215. ];
  216. }
  217. /**
  218. * 比较数据大小
  219. * @param string $size1
  220. * @param string $size2
  221. * @return bool
  222. */
  223. private function compareBytes(string $size1, string $size2): bool
  224. {
  225. $size1 = helper::convertToBytes($size1);
  226. $size2 = helper::convertToBytes($size2);
  227. return $size1 < $size2;
  228. }
  229. }