Science.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 app\admin\controller\Controller;
  14. use app\common\library\helper;
  15. /**
  16. * 环境检测
  17. * Class Science
  18. * @package app\admin\controller\setting
  19. */
  20. class Science extends Controller
  21. {
  22. /**
  23. * 环境检测
  24. * @return array
  25. */
  26. public function info()
  27. {
  28. return $this->renderSuccess([
  29. 'scienceInfo' => [
  30. 'server' => $this->server(), // 服务器信息
  31. 'phpinfo' => $this->phpinfo(), // PHP环境要求
  32. 'writeable' => $this->writeable(), // 目录权限监测
  33. ]
  34. ]);
  35. }
  36. /**
  37. * 服务器信息
  38. * @return array
  39. */
  40. private function server()
  41. {
  42. return [
  43. [
  44. 'name' => '服务器操作系统',
  45. 'key' => 'system',
  46. 'value' => PHP_OS,
  47. 'status' => PHP_SHLIB_SUFFIX === 'dll' ? 'warning' : 'normal',
  48. 'remark' => '建议使用 Linux 系统以提升程序性能'
  49. ],
  50. [
  51. 'name' => 'Web服务器环境',
  52. 'key' => 'webserver',
  53. 'value' => $this->request->server('SERVER_SOFTWARE'),
  54. 'status' => PHP_SAPI === 'isapi' ? 'warning' : 'normal',
  55. 'remark' => '建议使用 Apache 或 Nginx 以提升程序性能'
  56. ],
  57. [
  58. 'name' => 'PHP版本',
  59. 'key' => 'php',
  60. 'value' => PHP_VERSION,
  61. 'status' => version_compare(PHP_VERSION, '7.1.0') === -1 ? 'danger' : 'normal',
  62. 'remark' => 'PHP版本必须为 7.1.0 以上'
  63. ],
  64. [
  65. 'name' => '文件上传限制',
  66. 'key' => 'upload_max',
  67. 'value' => @ini_get('file_uploads') ? ini_get('upload_max_filesize') : 'unknow',
  68. 'status' => 'normal',
  69. 'remark' => ''
  70. ],
  71. [
  72. 'name' => '程序运行目录',
  73. 'key' => 'web_path',
  74. 'value' => str_replace('\\', '/', web_path()),
  75. 'status' => 'normal',
  76. 'remark' => ''
  77. ],
  78. ];
  79. }
  80. /**
  81. * PHP环境要求
  82. * get_loaded_extensions()
  83. * @return array
  84. */
  85. private function phpinfo()
  86. {
  87. return [
  88. [
  89. 'name' => 'PHP版本',
  90. 'key' => 'php_version',
  91. 'value' => '7.1.0及以上',
  92. 'status' => version_compare(PHP_VERSION, '7.1.0') === -1 ? 'danger' : 'normal',
  93. 'remark' => 'PHP版本必须为 7.1.0及以上'
  94. ],
  95. [
  96. 'name' => 'CURL',
  97. 'key' => 'curl',
  98. 'value' => '支持',
  99. 'status' => extension_loaded('curl') && function_exists('curl_init') ? 'normal' : 'danger',
  100. 'remark' => '您的PHP环境不支持CURL, 系统无法正常运行'
  101. ],
  102. [
  103. 'name' => 'OpenSSL',
  104. 'key' => 'openssl',
  105. 'value' => '支持',
  106. 'status' => extension_loaded('openssl') ? 'normal' : 'danger',
  107. 'remark' => '没有启用OpenSSL, 将无法访问微信平台的接口'
  108. ],
  109. [
  110. 'name' => 'PDO',
  111. 'key' => 'pdo',
  112. 'value' => '支持',
  113. 'status' => extension_loaded('PDO') && extension_loaded('pdo_mysql') ? 'normal' : 'danger',
  114. 'remark' => '您的PHP环境不支持PDO, 系统无法正常运行'
  115. ],
  116. [
  117. 'name' => 'GD',
  118. 'key' => 'gd',
  119. 'value' => '支持',
  120. 'status' => extension_loaded('gd') ? 'normal' : 'danger',
  121. 'remark' => '您的PHP环境不支持GD, 系统无法正常生成图片'
  122. ],
  123. [
  124. 'name' => 'BCMath',
  125. 'key' => 'bcmath',
  126. 'value' => '支持',
  127. 'status' => extension_loaded('bcmath') ? 'normal' : 'danger',
  128. 'remark' => '您的PHP环境不支持BCMath, 系统无法正常运行'
  129. ],
  130. [
  131. 'name' => 'mbstring',
  132. 'key' => 'mbstring',
  133. 'value' => '支持',
  134. 'status' => extension_loaded('mbstring') ? 'normal' : 'danger',
  135. 'remark' => '您的PHP环境不支持mbstring, 系统无法正常运行'
  136. ],
  137. [
  138. 'name' => 'SimpleXML',
  139. 'key' => 'simplexML',
  140. 'value' => '支持',
  141. 'status' => extension_loaded('SimpleXML') ? 'normal' : 'danger',
  142. 'remark' => '您的PHP环境不支持SimpleXML, 系统无法解析xml 无法使用微信支付'
  143. ],
  144. ];
  145. }
  146. /**
  147. * 目录权限监测
  148. */
  149. private function writeable()
  150. {
  151. $paths = [
  152. 'uploads' => realpath(web_path()) . '/uploads/',
  153. 'temp' => realpath(web_path()) . '/temp/',
  154. 'wxpay_log' => realpath(base_path()) . '/common/library/wechat/logs/',
  155. 'wxpay_cert' => realpath(base_path()) . '/common/library/wechat/cert/',
  156. ];
  157. return [
  158. [
  159. 'name' => '文件上传目录',
  160. 'key' => 'uploads',
  161. 'value' => str_replace('\\', '/', $paths['uploads']),
  162. 'status' => helper::checkWriteable($paths['uploads']) ? 'normal' : 'danger',
  163. 'remark' => '目录不可写,系统将无法正常上传文件'
  164. ],
  165. [
  166. 'name' => '临时文件目录',
  167. 'key' => 'temp',
  168. 'value' => str_replace('\\', '/', $paths['temp']),
  169. 'status' => helper::checkWriteable($paths['temp']) ? 'normal' : 'danger',
  170. 'remark' => '目录不可写,系统将无法正常写入文件'
  171. ],
  172. // [
  173. // 'name' => '微信支付日志目录',
  174. // 'key' => 'wxpay_log',
  175. // 'value' => str_replace('\\', '/', $paths['wxpay_log']),
  176. // 'status' => helper::checkWriteable($paths['wxpay_log']) ? 'normal' : 'danger',
  177. // 'remark' => '目录不可写,系统将无法正常写入文件'
  178. // ],
  179. [
  180. 'name' => '微信支付证书目录',
  181. 'key' => 'wxpay_cert',
  182. 'value' => str_replace('\\', '/', $paths['wxpay_cert']),
  183. 'status' => helper::checkWriteable($paths['wxpay_cert']) ? 'normal' : 'danger',
  184. 'remark' => '目录不可写,系统将无法正常写入文件'
  185. ],
  186. ];
  187. }
  188. }