完整登录流程测试";
// 1. 模拟登录
echo "
1. 执行登录
";
// 包含ThinkPHP框架
define('APP_PATH', './Application/');
define('RUNTIME_PATH', './Runtime/');
require './ThinkPHP/ThinkPHP.php';
try {
// 实例化登录控制器
$loginController = new \Retail\Controller\LoginController();
// 模拟POST数据
$_POST['username'] = '13888888888';
$_POST['password'] = 'test123';
// 捕获登录响应
ob_start();
$loginController->doLogin_v1();
$login_output = ob_get_clean();
echo "登录响应: " . $login_output . "
";
// 解析登录响应
$login_data = json_decode($login_output, true);
if ($login_data && $login_data['status'] == 1 && isset($login_data['list']) && !empty($login_data['list'])) {
$user = $login_data['list'][0];
echo "选择用户: " . $user['name'] . " (ID: " . $user['id'] . ")
";
// 2. 设置用户session
echo "2. 设置用户Session
";
// 模拟doUserLogin方法的逻辑
if ($user['user_type'] == 0) {
$user['login_type'] = 3; // 假设是商户
} else {
$user['login_type'] = $user['user_type'];
}
// 设置jurisdiction_user session
$_SESSION['jurisdiction_user'] = $user;
echo "已设置 jurisdiction_user session
";
// 根据用户类型设置其他session
switch ($user['login_type']) {
case 1:
// 合伙人
$_SESSION['admin_userinfo'] = array('id' => $user['system_user_id']);
echo "已设置合伙人相关session
";
break;
case 3:
// 商户
$_SESSION['merchant_userinfo'] = array('id' => $user['system_user_id']);
$_SESSION['identity'] = 1;
echo "已设置商户相关session
";
break;
case 4:
// 店长
$_SESSION['store_userinfo'] = array('id' => $user['system_user_id']);
$_SESSION['storeid'] = isset($user['storeid']) ? $user['storeid'] : 1;
$_SESSION['identity'] = 2;
echo "已设置店长相关session
";
break;
}
echo "Session设置完成
";
// 3. 测试storeSet接口
echo "3. 测试storeSet接口
";
// 清空之前的POST数据
$_POST = array();
// 设置storeSet的POST数据
$_POST['store_name'] = '测试门店名称';
$_POST['store_address'] = '测试门店地址';
$_POST['store_phone'] = '13800138000';
echo "POST数据: ";
echo "" . print_r($_POST, true) . "
";
// 检查session状态
echo "Session状态:
";
echo "jurisdiction_user: " . (isset($_SESSION['jurisdiction_user']) ? 'EXISTS' : 'NOT SET') . "
";
if (isset($_SESSION['jurisdiction_user'])) {
echo "用户ID: " . $_SESSION['jurisdiction_user']['id'] . "
";
echo "用户类型: " . $_SESSION['jurisdiction_user']['user_type'] . "
";
}
echo "
";
// 实例化XcxController并调用storeSet
$xcxController = new \Retail\Controller\XcxController();
echo "调用storeSet方法...
";
// 捕获输出
ob_start();
$xcxController->storeSet();
$storeset_output = ob_get_clean();
echo "storeSet方法输出: " . $storeset_output . "
";
// 如果输出为空,说明方法执行成功但没有返回内容
if (empty($storeset_output)) {
echo "storeSet方法执行成功(无输出内容)
";
}
} else {
echo "登录失败或无用户数据
";
}
} catch (Exception $e) {
echo "执行出错: " . $e->getMessage() . "
";
echo "错误文件: " . $e->getFile() . ":" . $e->getLine() . "
";
}
echo "4. Session信息
";
echo "" . print_r($_SESSION, true) . "
";
?>