true, CURLOPT_INFILE => $fileContent instanceof CURLFile ? null : tmpfile_from_string($fileContent), CURLOPT_INFILESIZE => strlen($fileContent), CURLOPT_HTTPHEADER => [ 'Authorization: OSS ' . $accessKeyId . ':' . $sign, 'Date: ' . $date, 'Content-MD5: ' . base64_encode(md5($fileContent, true)), 'Content-Type: ' . $contentType, ], CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_SSL_VERIFYPEER => false, ]); if ($fileContent instanceof CURLFile) { $fp = fopen($fileContent->getFilename(), 'rb'); curl_setopt($ch, CURLOPT_INFILE, $fp); curl_setopt($ch, CURLOPT_INFILESIZE, $fileContent->getSize()); } $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode === 200) { return $url; } return 'UploadFailed: HTTP ' . $httpCode . ' ' . substr($response, 0, 500); } // 辅助:从字符串创建临时文件流(PUT 上传需要) function tmpfile_from_string($content) { $fp = fopen('php://temp', 'rb+'); fwrite($fp, $content); rewind($fp); return $fp; } // 简单 mime 检测 function mime_content_type_auto($content) { $finfo = new finfo(FILEINFO_MIME_TYPE); return $finfo->buffer($content) ?: 'application/octet-stream'; } // ==================== 万象模型定义 ==================== $models = [ 'text2image' => [ 'title' => '文生图', 'endpoint' => 'aigc/text2image/image-synthesis', 'models' => [ 'wanx2.1-t2i-plus' => '万象2.1 文生图增强版', 'wanx2.1-t2i-turbo' => '万象2.1 文生图极速版', 'wanx-v1' => '万象1.0 文生图' ], 'params' => [ 'prompt' => ['label' => '正向提示词', 'type' => 'textarea', 'required' => true], 'negative_prompt' => ['label' => '负向提示词', 'type' => 'textarea', 'required' => false], 'size' => ['label' => '尺寸', 'type' => 'select', 'options' => ['1024*1024', '720*1280', '1280*720'], 'default' => '1024*1024'], 'n' => ['label' => '生成数量', 'type' => 'number', 'default' => 1, 'min' => 1, 'max' => 4] ] ], 'image_generation' => [ 'title' => '图像编辑/生成', 'endpoint' => 'aigc/image-generation/generation', 'models' => [ 'wanx-style-cosplay-v1' => '人像风格重绘', 'wanx-background-generation-v2' => '背景生成', 'wanx-anytext-v1' => 'AnyText 图文融合', 'wanx-sketch-to-image-lite' => '涂鸦作画' ], 'params' => [ 'model' => ['label' => '功能模型', 'type' => 'select', 'dynamic' => true], 'ref_image' => ['label' => '参考图URL', 'type' => 'text', 'required' => false, 'hint' => '可上传或填写URL'], 'prompt' => ['label' => '提示词', 'type' => 'textarea', 'required' => false], 'style_index' => ['label' => '风格指数 (仅人像)', 'type' => 'select', 'options' => ['1','2','3','4','5'], 'required' => false], 'text_content' => ['label' => '要写入的文字 (仅AnyText)', 'type' => 'text', 'required' => false], 'text_position' => ['label' => '文字位置 (仅AnyText)', 'type' => 'select', 'options' => ['center','top','bottom'], 'required' => false] ] ], 'video_generation' => [ 'title' => '视频生成', 'endpoint' => 'aigc/video-generation/generation', 'models' => [ 'wanx2.1-t2v-plus' => '文本生成视频增强版', 'wanx2.1-t2v-turbo' => '文本生成视频极速版' ], 'params' => [ 'prompt' => ['label' => '视频描述', 'type' => 'textarea', 'required' => true], 'duration' => ['label' => '时长(秒)', 'type' => 'number', 'default' => 5, 'min' => 2, 'max' => 10], 'size' => ['label' => '分辨率', 'type' => 'select', 'options' => ['1280*720', '720*1280'], 'default' => '1280*720'] ] ] ]; // ==================== 路由处理 ==================== $action = $_GET['action'] ?? ($_POST['action'] ?? ''); $password = $_SESSION['wanx_pass'] ?? ''; // 未配置则进入设置 if (!file_exists(CONFIG_FILE)) { $action = 'setup'; } // 统一验证主密码(setup 和 verify_pass 除外) if (!in_array($action, ['setup', 'save_config', 'verify_pass']) && empty($password)) { $action = 'auth'; // 需要先验证密码 } // 特殊 action:身份验证 if ($action === 'verify_pass') { $pass = $_POST['password'] ?? ''; $config = get_config($pass); if ($config !== null) { $_SESSION['wanx_pass'] = $pass; header('Location: ?action=panel'); exit; } else { $error = '主密码错误,请重试'; } } // 提交任务(ajax) if ($action === 'submit_task') { header('Content-Type: application/json'); if (empty($password)) { echo json_encode(['error' => '未解锁面板']); exit; } $config = get_config($password); if (!$config || empty($config['api_key'])) { echo json_encode(['error' => '配置无效或API Key缺失']); exit; } $apiKey = $config['api_key']; $category = $_POST['category'] ?? ''; $model = $_POST['model'] ?? ''; $catConfig = $models[$category] ?? null; if (!$catConfig) { echo json_encode(['error' => '无效功能分类']); exit; } $input = []; foreach ($catConfig['params'] as $param => $def) { if (isset($_POST[$param]) && $_POST[$param] !== '') { $input[$param] = $_POST[$param]; } } if (!empty($_POST['ref_image'])) { $input['reference_image'] = $_POST['ref_image']; } $payload = [ 'model' => $model, 'input' => $input, ]; if (isset($input['size'])) { $payload['parameters']['size'] = $input['size']; unset($payload['input']['size']); } if (isset($input['n'])) { $payload['parameters']['n'] = (int)$input['n']; unset($payload['input']['n']); } $endpoint = DASHSCOPE_BASE . $catConfig['endpoint']; $ch = curl_init($endpoint); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . $apiKey, 'Content-Type: application/json', 'X-DashScope-Async: enable' ], CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, ]); $result = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $data = json_decode($result, true); if ($httpCode === 200 && isset($data['output']['task_id'])) { $_SESSION['tasks'][] = [ 'task_id' => $data['output']['task_id'], 'category' => $category, 'endpoint' => $catConfig['endpoint'], 'time' => time() ]; echo json_encode(['task_id' => $data['output']['task_id']]); } else { echo json_encode(['error' => $data['message'] ?? '请求失败', 'raw' => $result]); } exit; } // 查询任务状态 if ($action === 'query_task') { header('Content-Type: application/json'); $config = get_config($password); $apiKey = $config['api_key'] ?? ''; if (!$apiKey) { echo json_encode(['error' => 'API Key缺失']); exit; } $taskId = $_GET['task_id'] ?? ''; $endpoint = $_GET['endpoint'] ?? ''; $url = DASHSCOPE_BASE . $endpoint . '/' . $taskId; $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey], CURLOPT_RETURNTRANSFER => true, ]); $result = curl_exec($ch); curl_close($ch); echo $result; exit; } // 上传参考图到 OSS(返回 OSS URL) if ($action === 'upload_ref_image') { header('Content-Type: application/json'); $config = get_config($password); $oss = $config['oss'] ?? []; if (!$oss) { echo json_encode(['error' => 'OSS 未配置']); exit; } if (empty($_FILES['file'])) { echo json_encode(['error' => '未选择文件']); exit; } $file = $_FILES['file']; $ext = pathinfo($file['name'], PATHINFO_EXTENSION) ?: 'png'; $object = ($oss['dir'] ?? '') . date('Ymd/His_') . uniqid() . '.' . $ext; $content = file_get_contents($file['tmp_name']); $url = oss_upload($oss['bucket'], $oss['endpoint'], $oss['access_key_id'], $oss['access_key_secret'], $object, $content); if (strpos($url, 'UploadFailed') === false) { echo json_encode(['url' => $url]); } else { echo json_encode(['error' => '上传到 OSS 失败: ' . $url]); } exit; } // 将临时 URL 的资源转存到 OSS(用于生成结果) if ($action === 'save_to_oss') { header('Content-Type: application/json'); $config = get_config($password); $oss = $config['oss'] ?? []; if (!$oss) { echo json_encode(['error' => 'OSS 未配置']); exit; } $tempUrl = $_POST['url'] ?? ''; if (!$tempUrl) { echo json_encode(['error' => '缺少临时URL']); exit; } // 下载临时资源 $ch = curl_init($tempUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $content = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); curl_close($ch); if ($httpCode !== 200 || empty($content)) { echo json_encode(['error' => '下载临时资源失败 HTTP' . $httpCode]); exit; } $ext = ''; if (preg_match('/image\/(\w+)/', $contentType, $m)) { $ext = $m[1]; } elseif (preg_match('/video\/(\w+)/', $contentType, $m)) { $ext = $m[1] === 'quicktime' ? 'mov' : $m[1]; } if (!$ext) $ext = 'bin'; $object = ($oss['dir'] ?? '') . 'results/' . date('Ymd/His_') . uniqid() . '.' . $ext; $url = oss_upload($oss['bucket'], $oss['endpoint'], $oss['access_key_id'], $oss['access_key_secret'], $object, $content); if (strpos($url, 'UploadFailed') === false) { echo json_encode(['url' => $url]); } else { echo json_encode(['error' => '转存 OSS 失败: ' . $url]); } exit; } // ==================== 页面渲染 ==================== ?> 通义万象 · 全功能加密面板 + OSS

🎨 通义万象 · 全功能加密面板 OSS 自动存储

首次配置 - 加密存储所有密钥
🔐 安全主密码
此密码用于加密下方所有敏感信息,请务必牢记。
🧠 百炼 API Key
☁️ 阿里云 OSS 配置(用于存储图片视频)
$_POST['oss_bucket'] ?? '', 'endpoint' => $_POST['oss_endpoint'] ?? '', 'access_key_id' => $_POST['oss_key_id'] ?? '', 'access_key_secret' => $_POST['oss_key_secret'] ?? '', 'dir' => rtrim($_POST['oss_dir'] ?? '', '/') . '/' ]; if (strlen($mp) >= 6 && $apiKey && $oss['bucket'] && $oss['endpoint'] && $oss['access_key_id'] && $oss['access_key_secret']) { $config = ['api_key' => $apiKey, 'oss' => $oss]; save_config($config, $mp); $_SESSION['wanx_pass'] = $mp; echo '
✅ 配置已加密存储,正在跳转...
'; echo ''; } else { echo '
❌ 请完整填写所有信息并确保密码长度≥6
'; } ?>
🔐 输入主密码解锁面板
🚀 万象功能选择 已加密 · OSS 已连接
📋 任务记录

暂无任务