323 lines
12 KiB
PHP
323 lines
12 KiB
PHP
<?php
|
||
/**
|
||
* PHP8升级后完整系统功能验证脚本
|
||
* 用于验证所有核心业务模块在PHP8下的工作状态
|
||
*/
|
||
|
||
error_reporting(E_ALL);
|
||
ini_set('display_errors', 1);
|
||
|
||
echo "<!DOCTYPE html><html><head><meta charset='UTF-8'><title>PHP8系统功能验证</title>";
|
||
echo "<style>
|
||
body{font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5;}
|
||
.container{max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);}
|
||
.test-section{margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px;}
|
||
.success{color: #28a745; font-weight: bold;}
|
||
.error{color: #dc3545; font-weight: bold;}
|
||
.warning{color: #ffc107; font-weight: bold;}
|
||
.info{color: #17a2b8; font-weight: bold;}
|
||
.test-item{margin: 10px 0; padding: 8px; background: #f8f9fa; border-left: 4px solid #007cba;}
|
||
table{width: 100%; border-collapse: collapse; margin: 10px 0;}
|
||
th,td{border: 1px solid #ddd; padding: 8px; text-align: left;}
|
||
th{background-color: #f2f2f2;}
|
||
.status-ok{background: #d4edda; color: #155724;}
|
||
.status-error{background: #f8d7da; color: #721c24;}
|
||
.status-warning{background: #fff3cd; color: #856404;}
|
||
</style>";
|
||
echo "</head><body>";
|
||
|
||
echo "<div class='container'>";
|
||
echo "<h1>🚀 PHP8系统功能验证报告</h1>";
|
||
echo "<p><strong>验证时间:</strong> " . date('Y-m-d H:i:s') . "</p>";
|
||
echo "<p><strong>PHP版本:</strong> " . PHP_VERSION . "</p>";
|
||
|
||
// 验证结果统计
|
||
$totalTests = 0;
|
||
$passedTests = 0;
|
||
$failedTests = 0;
|
||
$warningTests = 0;
|
||
|
||
function runTest($testName, $testFunction, &$total, &$passed, &$failed, &$warnings) {
|
||
$total++;
|
||
echo "<div class='test-item'>";
|
||
echo "<h4>🔄 $testName</h4>";
|
||
|
||
try {
|
||
$result = $testFunction();
|
||
if ($result['status'] === 'success') {
|
||
echo "<div class='success'>✅ 测试通过</div>";
|
||
$passed++;
|
||
} elseif ($result['status'] === 'warning') {
|
||
echo "<div class='warning'>⚠️ 警告</div>";
|
||
$warnings++;
|
||
} else {
|
||
echo "<div class='error'>❌ 测试失败</div>";
|
||
$failed++;
|
||
}
|
||
echo "<div>" . $result['message'] . "</div>";
|
||
} catch (Exception $e) {
|
||
echo "<div class='error'>❌ 测试异常: " . $e->getMessage() . "</div>";
|
||
$failed++;
|
||
}
|
||
|
||
echo "</div>";
|
||
}
|
||
|
||
// 1. PHP8基础环境验证
|
||
echo "<div class='test-section'>";
|
||
echo "<h2>🔧 PHP8基础环境验证</h2>";
|
||
|
||
runTest("PHP版本检查", function() {
|
||
$version = PHP_VERSION;
|
||
if (version_compare($version, '8.0', '>=')) {
|
||
return ['status' => 'success', 'message' => "PHP版本: $version ✅"];
|
||
} else {
|
||
return ['status' => 'error', 'message' => "PHP版本过低: $version"];
|
||
}
|
||
}, $totalTests, $passedTests, $failedTests, $warningTests);
|
||
|
||
runTest("必要扩展检查", function() {
|
||
$required = ['curl', 'openssl', 'pdo', 'pdo_mysql', 'json', 'mbstring'];
|
||
$missing = [];
|
||
foreach ($required as $ext) {
|
||
if (!extension_loaded($ext)) {
|
||
$missing[] = $ext;
|
||
}
|
||
}
|
||
if (empty($missing)) {
|
||
return ['status' => 'success', 'message' => '所有必要扩展已加载'];
|
||
} else {
|
||
return ['status' => 'error', 'message' => '缺少扩展: ' . implode(', ', $missing)];
|
||
}
|
||
}, $totalTests, $passedTests, $failedTests, $warningTests);
|
||
|
||
runTest("弃用功能检查", function() {
|
||
$deprecated = [];
|
||
if (function_exists('each')) $deprecated[] = 'each()';
|
||
if (function_exists('create_function')) $deprecated[] = 'create_function()';
|
||
if (extension_loaded('mcrypt')) $deprecated[] = 'mcrypt扩展';
|
||
|
||
if (empty($deprecated)) {
|
||
return ['status' => 'success', 'message' => '没有检测到已弃用的功能'];
|
||
} else {
|
||
return ['status' => 'warning', 'message' => '检测到弃用功能: ' . implode(', ', $deprecated) . '(如果已替换则正常)'];
|
||
}
|
||
}, $totalTests, $passedTests, $failedTests, $warningTests);
|
||
|
||
echo "</div>";
|
||
|
||
// 2. 文件加载和语法验证
|
||
echo "<div class='test-section'>";
|
||
echo "<h2>📁 核心文件语法验证</h2>";
|
||
|
||
$coreFiles = [
|
||
'source/apis/transfer.php' => '加密解密核心文件',
|
||
'framework/function/global.func.php' => '微信AES加密函数',
|
||
'lib/phprs/Router.php' => 'API路由系统',
|
||
'framework/function/communication.func.php' => 'HTTP通信库',
|
||
'source/apis/login.php' => '登录API文件',
|
||
'source/public/index.php' => '入口文件'
|
||
];
|
||
|
||
foreach ($coreFiles as $file => $description) {
|
||
runTest("$description ($file)", function() use ($file) {
|
||
$fullPath = __DIR__ . '/' . $file;
|
||
if (!file_exists($fullPath)) {
|
||
return ['status' => 'error', 'message' => "文件不存在: $fullPath"];
|
||
}
|
||
|
||
// 语法检查
|
||
$output = [];
|
||
$returnCode = 0;
|
||
exec("php -l \"$fullPath\" 2>&1", $output, $returnCode);
|
||
|
||
if ($returnCode === 0) {
|
||
return ['status' => 'success', 'message' => '语法检查通过'];
|
||
} else {
|
||
return ['status' => 'error', 'message' => '语法错误: ' . implode(', ', $output)];
|
||
}
|
||
}, $totalTests, $passedTests, $failedTests, $warningTests);
|
||
}
|
||
|
||
echo "</div>";
|
||
|
||
// 3. 加密功能验证
|
||
echo "<div class='test-section'>";
|
||
echo "<h2>🔐 加密解密功能验证</h2>";
|
||
|
||
runTest("Transfer类加载", function() {
|
||
$transferFile = __DIR__ . '/source/apis/transfer.php';
|
||
if (!file_exists($transferFile)) {
|
||
return ['status' => 'error', 'message' => 'transfer.php文件不存在'];
|
||
}
|
||
|
||
// 简单的类存在性检查
|
||
if (strpos(file_get_contents($transferFile), 'class Transfer') !== false) {
|
||
return ['status' => 'success', 'message' => 'Transfer类定义存在'];
|
||
} else {
|
||
return ['status' => 'error', 'message' => 'Transfer类定义未找到'];
|
||
}
|
||
}, $totalTests, $passedTests, $failedTests, $warningTests);
|
||
|
||
runTest("OpenSSL加密功能", function() {
|
||
if (!extension_loaded('openssl')) {
|
||
return ['status' => 'error', 'message' => 'OpenSSL扩展未加载'];
|
||
}
|
||
|
||
// 测试基本的OpenSSL加密
|
||
$data = 'test data';
|
||
$key = 'test key';
|
||
$encrypted = openssl_encrypt($data, 'aes-128-ecb', $key, OPENSSL_RAW_DATA);
|
||
|
||
if ($encrypted !== false) {
|
||
return ['status' => 'success', 'message' => 'OpenSSL加密功能正常'];
|
||
} else {
|
||
return ['status' => 'error', 'message' => 'OpenSSL加密测试失败'];
|
||
}
|
||
}, $totalTests, $passedTests, $failedTests, $warningTests);
|
||
|
||
echo "</div>";
|
||
|
||
// 4. CURL通信验证
|
||
echo "<div class='test-section'>";
|
||
echo "<h2>🌐 HTTP通信功能验证</h2>";
|
||
|
||
runTest("CURL扩展", function() {
|
||
if (!extension_loaded('curl')) {
|
||
return ['status' => 'error', 'message' => 'CURL扩展未加载'];
|
||
}
|
||
|
||
// 检查CURLOPT_SAFE_UPLOAD是否还会引起问题
|
||
$ch = curl_init();
|
||
if (!$ch) {
|
||
return ['status' => 'error', 'message' => 'CURL初始化失败'];
|
||
}
|
||
|
||
try {
|
||
// 这是我们修复的关键点
|
||
if (version_compare(phpversion(), '8.0') < 0 && defined('CURLOPT_SAFE_UPLOAD')) {
|
||
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
|
||
}
|
||
curl_close($ch);
|
||
return ['status' => 'success', 'message' => 'CURL CURLOPT_SAFE_UPLOAD修复有效'];
|
||
} catch (Exception $e) {
|
||
curl_close($ch);
|
||
return ['status' => 'error', 'message' => 'CURLOPT_SAFE_UPLOAD仍有问题: ' . $e->getMessage()];
|
||
}
|
||
}, $totalTests, $passedTests, $failedTests, $warningTests);
|
||
|
||
runTest("HTTP请求测试", function() {
|
||
$ch = curl_init();
|
||
curl_setopt($ch, CURLOPT_URL, "https://httpbin.org/get");
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||
|
||
$response = curl_exec($ch);
|
||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||
curl_close($ch);
|
||
|
||
if ($response !== false && $httpCode == 200) {
|
||
return ['status' => 'success', 'message' => "HTTP请求成功,状态码: $httpCode"];
|
||
} else {
|
||
return ['status' => 'warning', 'message' => "HTTP请求失败,状态码: $httpCode(可能是网络问题)"];
|
||
}
|
||
}, $totalTests, $passedTests, $failedTests, $warningTests);
|
||
|
||
echo "</div>";
|
||
|
||
// 5. 数据库连接验证
|
||
echo "<div class='test-section'>";
|
||
echo "<h2>🗄️ 数据库连接验证</h2>";
|
||
|
||
runTest("PDO MySQL连接", function() {
|
||
try {
|
||
$pdo = new PDO(
|
||
"mysql:host=rm-bp1btyuwq77591x0jpo.mysql.rds.aliyuncs.com:3306;dbname=youlehudong;charset=utf8",
|
||
"games",
|
||
"Games0791!!",
|
||
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_TIMEOUT => 5]
|
||
);
|
||
return ['status' => 'success', 'message' => '数据库连接成功'];
|
||
} catch (Exception $e) {
|
||
return ['status' => 'error', 'message' => '数据库连接失败: ' . $e->getMessage()];
|
||
}
|
||
}, $totalTests, $passedTests, $failedTests, $warningTests);
|
||
|
||
echo "</div>";
|
||
|
||
// 6. Session功能验证
|
||
echo "<div class='test-section'>";
|
||
echo "<h2>🍪 Session功能验证</h2>";
|
||
|
||
runTest("Session基本功能", function() {
|
||
if (session_status() === PHP_SESSION_NONE) {
|
||
if (!session_start()) {
|
||
return ['status' => 'error', 'message' => 'Session启动失败'];
|
||
}
|
||
}
|
||
|
||
// 测试session读写
|
||
$_SESSION['test_key'] = 'test_value_' . time();
|
||
if (isset($_SESSION['test_key'])) {
|
||
return ['status' => 'success', 'message' => 'Session读写正常'];
|
||
} else {
|
||
return ['status' => 'error', 'message' => 'Session读写失败'];
|
||
}
|
||
}, $totalTests, $passedTests, $failedTests, $warningTests);
|
||
|
||
echo "</div>";
|
||
|
||
// 7. 测试结果汇总
|
||
echo "<div class='test-section'>";
|
||
echo "<h2>📊 测试结果汇总</h2>";
|
||
|
||
echo "<table>";
|
||
echo "<tr><th>测试项目</th><th>结果</th><th>数量</th><th>百分比</th></tr>";
|
||
echo "<tr class='status-ok'><td>✅ 通过测试</td><td>成功</td><td>$passedTests</td><td>" . round(($passedTests/$totalTests)*100, 1) . "%</td></tr>";
|
||
echo "<tr class='status-warning'><td>⚠️ 警告</td><td>需注意</td><td>$warningTests</td><td>" . round(($warningTests/$totalTests)*100, 1) . "%</td></tr>";
|
||
echo "<tr class='status-error'><td>❌ 失败测试</td><td>需修复</td><td>$failedTests</td><td>" . round(($failedTests/$totalTests)*100, 1) . "%</td></tr>";
|
||
echo "<tr><td><strong>总计</strong></td><td>-</td><td><strong>$totalTests</strong></td><td><strong>100%</strong></td></tr>";
|
||
echo "</table>";
|
||
|
||
// 综合评估
|
||
echo "<h3>📋 综合评估</h3>";
|
||
if ($failedTests === 0) {
|
||
if ($warningTests === 0) {
|
||
echo "<div class='success'>🎉 系统完全就绪!所有测试均通过,可以进行生产环境部署。</div>";
|
||
} else {
|
||
echo "<div class='warning'>⚠️ 系统基本就绪,但有 $warningTests 个警告项需要关注。</div>";
|
||
}
|
||
} else {
|
||
echo "<div class='error'>❌ 系统未就绪,有 $failedTests 个测试失败,需要立即修复。</div>";
|
||
}
|
||
|
||
echo "<h3>📈 下一步建议</h3>";
|
||
echo "<ul>";
|
||
if ($failedTests > 0) {
|
||
echo "<li>🚨 <strong>立即修复失败项</strong>:优先解决标记为失败的测试项</li>";
|
||
}
|
||
if ($warningTests > 0) {
|
||
echo "<li>⚠️ <strong>检查警告项</strong>:确认警告项是否影响业务功能</li>";
|
||
}
|
||
echo "<li>🔄 <strong>业务功能测试</strong>:进行具体的业务流程测试(支付、登录等)</li>";
|
||
echo "<li>📊 <strong>性能测试</strong>:对比PHP8与原系统的性能表现</li>";
|
||
echo "<li>🚀 <strong>准备部署</strong>:配置生产环境部署方案</li>";
|
||
echo "</ul>";
|
||
|
||
echo "</div>";
|
||
|
||
echo "<div style='margin-top: 20px; padding: 15px; background: #e9ecef; border-radius: 5px;'>";
|
||
echo "<h3>🔗 相关工具链接</h3>";
|
||
echo "<p>";
|
||
echo "<a href='debug_weixin.php' target='_blank' style='margin-right: 15px;'>微信登录调试</a>";
|
||
echo "<a href='check_session_config.php' target='_blank' style='margin-right: 15px;'>Session配置检查</a>";
|
||
echo "<a href='test_session_persistence.php' target='_blank' style='margin-right: 15px;'>Session持久化测试</a>";
|
||
echo "</p>";
|
||
echo "<p><strong>验证完成时间:</strong> " . date('Y-m-d H:i:s') . "</p>";
|
||
echo "</div>";
|
||
|
||
echo "</div>";
|
||
echo "</body></html>";
|
||
?>
|