|
|
@@ -28,10 +28,8 @@ class WorkOrder extends Api
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
public function textToImage()
|
|
|
{
|
|
|
-
|
|
|
$outputDirRaw = 'uploads/operate/ai/Preview/undefined_BRdP4/3';
|
|
|
$img_name = '42131321';
|
|
|
$rootPath = str_replace('\\', '/', ROOT_PATH);
|
|
|
@@ -125,18 +123,14 @@ class WorkOrder extends Api
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
public function getImageSeed($taskId)
|
|
|
{
|
|
|
// 配置参数
|
|
|
$apiUrl = 'https://chatapi.onechats.ai/mj/task/' . $taskId . '/fetch';
|
|
|
$apiKey = 'sk-iURfrAgzAjhZ4PpPLwzmWIAhM7zKfrkwDvyxk4RVBQ4ouJNK';
|
|
|
-
|
|
|
try {
|
|
|
// 初始化cURL
|
|
|
$ch = curl_init();
|
|
|
-
|
|
|
// 设置cURL选项
|
|
|
curl_setopt_array($ch, [
|
|
|
CURLOPT_URL => $apiUrl,
|
|
|
@@ -156,15 +150,12 @@ class WorkOrder extends Api
|
|
|
// 执行请求
|
|
|
$response = curl_exec($ch);
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
-
|
|
|
// 错误处理
|
|
|
if (curl_errno($ch)) {
|
|
|
throw new Exception('cURL请求失败: ' . curl_error($ch));
|
|
|
}
|
|
|
-
|
|
|
// 关闭连接
|
|
|
curl_close($ch);
|
|
|
-
|
|
|
// 验证HTTP状态码
|
|
|
if ($httpCode < 200 || $httpCode >= 300) {
|
|
|
throw new Exception('API返回错误状态码: ' . $httpCode);
|
|
|
@@ -175,20 +166,17 @@ class WorkOrder extends Api
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
throw new Exception('JSON解析失败: ' . json_last_error_msg());
|
|
|
}
|
|
|
-
|
|
|
// 返回结构化数据
|
|
|
return [
|
|
|
'success' => true,
|
|
|
'http_code' => $httpCode,
|
|
|
'data' => $responseData
|
|
|
];
|
|
|
-
|
|
|
} catch (Exception $e) {
|
|
|
// 确保关闭cURL连接
|
|
|
if (isset($ch) && is_resource($ch)) {
|
|
|
curl_close($ch);
|
|
|
}
|
|
|
-
|
|
|
return [
|
|
|
'success' => false,
|
|
|
'error' => $e->getMessage(),
|
|
|
@@ -197,120 +185,6 @@ class WorkOrder extends Api
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// public function textToImage()
|
|
|
-// {
|
|
|
-// $outputDirRaw = 'uploads/operate/ai/Preview/undefined_BRdP4/3';
|
|
|
-// $img_name = '16';
|
|
|
-// $rootPath = str_replace('\\', '/', ROOT_PATH);
|
|
|
-// $outputDir = rtrim($rootPath . 'public/' . $outputDirRaw, '/') . '/';
|
|
|
-// $dateDir = date('Y-m-d') . '/';
|
|
|
-// $fullBaseDir = $outputDir . $dateDir;
|
|
|
-//
|
|
|
-// // 确保目录存在
|
|
|
-// if (!is_dir($fullBaseDir . '2048x2048/')) {
|
|
|
-// mkdir($fullBaseDir . '2048x2048/', 0755, true);
|
|
|
-// }
|
|
|
-//
|
|
|
-// $taskId = '1755154312186851';
|
|
|
-// //API配置
|
|
|
-// $config = [
|
|
|
-// 'fetch_url' => 'https://chatapi.onechats.ai/mj/task/',
|
|
|
-// 'api_key' => 'sk-iURfrAgzAjhZ4PpPLwzmWIAhM7zKfrkwDvyxk4RVBQ4ouJNK'
|
|
|
-// ];
|
|
|
-//
|
|
|
-// // 1. 获取主任务信息
|
|
|
-// $fetchUrl = $config['fetch_url'].$taskId.'/fetch';
|
|
|
-// $fetchResponse = $this->sendApiRequest($fetchUrl, [], $config['api_key'], 'GET');
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($fetchResponse);
|
|
|
-// echo "<pre>";
|
|
|
-// $fetchData = json_decode($fetchResponse, true);
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($fetchData);
|
|
|
-// echo "<pre>";
|
|
|
-// if (empty($fetchData['buttons'])) {
|
|
|
-// throw new Exception('无法获取变体按钮信息');
|
|
|
-// }
|
|
|
-//
|
|
|
-// echo "<pre>";
|
|
|
-// print_r(777777777);
|
|
|
-// echo "<pre>";
|
|
|
-//
|
|
|
-// //选择要获取的变体(这里选择第一个变体U1)
|
|
|
-// //customId MJ::JOB::upsample::1::47df46a8-b0bb-4b31-a578-09f69c73a2ed
|
|
|
-// $customId = $fetchData['buttons'][0]['customId'];
|
|
|
-//
|
|
|
-// $upscaleUrl = "https://chatapi.onechats.ai/mj/submit/action";
|
|
|
-// $postData = [
|
|
|
-// 'customId' => $customId,
|
|
|
-// // 可能需要额外参数,如 taskId
|
|
|
-// 'taskId' => $taskId,
|
|
|
-// ];
|
|
|
-// $response = $this->sendApiRequest($upscaleUrl, $postData, $config['api_key'], 'POST');
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($response);
|
|
|
-// echo "<pre>";
|
|
|
-// $responseData = json_decode($response, true);
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($responseData);
|
|
|
-// echo "<pre>";
|
|
|
-//
|
|
|
-//
|
|
|
-// echo "<pre>";
|
|
|
-// print_r(21312312321321321);
|
|
|
-// echo "<pre>";
|
|
|
-// // 3. 调用API获取单个变体图片
|
|
|
-// $upscaleUrl = $config['fetch_url'].$customId.'/image-seed';
|
|
|
-// $upscaleResponse = $this->sendApiRequest($upscaleUrl, [], $config['api_key'], 'GET');
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($upscaleResponse);
|
|
|
-// echo "<pre>";
|
|
|
-// $upscaleData = json_decode($upscaleResponse, true);
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($upscaleData);
|
|
|
-// echo "<pre>";
|
|
|
-// die;
|
|
|
-// if (empty($upscaleData['imageUrl'])) {
|
|
|
-// throw new Exception('获取变体图片失败: '.($upscaleData['message'] ?? '未知错误'));
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 4. 处理返回的图片URL
|
|
|
-// $imageUrl = is_array($upscaleData['imageUrl']) ? $upscaleData['imageUrl'][0] : $upscaleData['imageUrl'];
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($imageUrl.'3333');
|
|
|
-// echo "<pre>";
|
|
|
-// // 保存文件路径定义
|
|
|
-// $img_name = mb_substr(preg_replace('/[^\x{4e00}-\x{9fa5}A-Za-z0-9_\- ]/u', '', $img_name), 0, 30);
|
|
|
-// $filename = $img_name . '.png';
|
|
|
-// $path512 = $fullBaseDir . '2048x2048/' . $filename;
|
|
|
-//
|
|
|
-// // 下载并保存图片
|
|
|
-// $imageContent = file_get_contents($imageUrl);
|
|
|
-// if ($imageContent === false) {
|
|
|
-// throw new Exception('下载图片失败');
|
|
|
-// }
|
|
|
-//
|
|
|
-// $saveResult = file_put_contents($path512, $imageContent);
|
|
|
-// if ($saveResult === false) {
|
|
|
-// throw new Exception('保存图片失败');
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 数据库更新
|
|
|
-// Db::name('text_to_image')->where('id', '552')->update([
|
|
|
-// 'new_image_url' => str_replace($rootPath . 'public/', '', $path512),
|
|
|
-// 'img_name' => $img_name,
|
|
|
-// 'model' => 'MID_JOURNEY',
|
|
|
-// 'status' => trim($img_name) === '' ? 0 : 1,
|
|
|
-// 'status_name' => "文生图",
|
|
|
-// 'size' => "2048",
|
|
|
-// 'quality' => 'standard',
|
|
|
-// 'style' => 'vivid',
|
|
|
-// 'error_msg' => '',
|
|
|
-// 'update_time' => date('Y-m-d H:i:s')
|
|
|
-// ]);
|
|
|
-//
|
|
|
-// return "成功";
|
|
|
-// }
|
|
|
|
|
|
private function sendPostRequest($url, $data, $apiKey)
|
|
|
{
|
|
|
@@ -327,12 +201,10 @@ class WorkOrder extends Api
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // 延长超时时间
|
|
|
-
|
|
|
$response = curl_exec($ch);
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
$error = curl_error($ch);
|
|
|
curl_close($ch);
|
|
|
-
|
|
|
return [
|
|
|
'response' => $response,
|
|
|
'http_code' => $httpCode,
|
|
|
@@ -355,7 +227,6 @@ class WorkOrder extends Api
|
|
|
'default_prompt' => '一个猫',
|
|
|
'wait_time' => 3 // 等待生成完成的秒数
|
|
|
];
|
|
|
-
|
|
|
try {
|
|
|
// 1. 准备请求数据
|
|
|
$prompt = $config['default_prompt'];
|
|
|
@@ -378,32 +249,24 @@ class WorkOrder extends Api
|
|
|
// 2. 提交生成请求
|
|
|
$generateResponse = $this->sendApiRequest($config['api_url'], $postData, $config['api_key']);
|
|
|
$generateData = json_decode($generateResponse, true);
|
|
|
-
|
|
|
if (empty($generateData['result'])) {
|
|
|
throw new Exception('生成失败: '.($generateData['message'] ?? '未知错误'));
|
|
|
}
|
|
|
-
|
|
|
$taskId = $generateData['result'];
|
|
|
-
|
|
|
// 3. 等待图片生成完成
|
|
|
sleep($config['wait_time']);
|
|
|
-
|
|
|
// 4. 获取生成结果
|
|
|
$fetchUrl = $config['fetch_url'].$taskId.'/fetch';
|
|
|
$fetchResponse = $this->sendApiRequest($fetchUrl, [], $config['api_key'], 'GET');
|
|
|
$fetchData = json_decode($fetchResponse, true);
|
|
|
-
|
|
|
if (empty($fetchData['imageUrl'])) {
|
|
|
throw new Exception('获取图片失败: '.($fetchData['message'] ?? '未知错误'));
|
|
|
}
|
|
|
-
|
|
|
// 5. 处理返回的图片数组(取第一张)
|
|
|
$imageUrls = is_array($fetchData['imageUrl']) ? $fetchData['imageUrl'] : [$fetchData['imageUrl']];
|
|
|
$firstImageUrl = $imageUrls[0];
|
|
|
-
|
|
|
// 6. 保存图片到本地
|
|
|
$savePath = $this->saveImage($firstImageUrl);
|
|
|
-
|
|
|
// 7. 返回结果
|
|
|
return [
|
|
|
'code' => 200,
|
|
|
@@ -414,7 +277,6 @@ class WorkOrder extends Api
|
|
|
'task_id' => $taskId
|
|
|
]
|
|
|
];
|
|
|
-
|
|
|
} catch (Exception $e) {
|
|
|
// 错误处理
|
|
|
return [
|
|
|
@@ -520,298 +382,6 @@ class WorkOrder extends Api
|
|
|
return $localPath;
|
|
|
}
|
|
|
|
|
|
-// public function txttowimg($params = [])
|
|
|
-// {
|
|
|
-// $config = [
|
|
|
-// 'api_url' => 'https://chatapi.onechats.ai/mj/submit/imagine',
|
|
|
-// 'api_key' => 'sk-iURfrAgzAjhZ4PpPLwzmWIAhM7zKfrkwDvyxk4RVBQ4ouJNK',
|
|
|
-// 'default_prompt' => '一个猫',
|
|
|
-// ];
|
|
|
-//
|
|
|
-// // 使用传入的prompt或默认值
|
|
|
-// $prompt = $params['prompt'] ?? $config['default_prompt'];
|
|
|
-//
|
|
|
-// // 构建请求数据
|
|
|
-// $postData = [
|
|
|
-// 'botType' => 'MID_JOURNEY',
|
|
|
-// 'prompt' => $prompt,
|
|
|
-// 'base64Array' => [],
|
|
|
-// 'accountFilter' => [
|
|
|
-// 'channelId' => $params['channelId'] ?? "",
|
|
|
-// 'instanceId' => $params['instanceId'] ?? "",
|
|
|
-// 'modes' => $params['modes'] ?? [],
|
|
|
-// 'remark' => $params['remark'] ?? "",
|
|
|
-// 'remix' => $params['remix'] ?? true,
|
|
|
-// 'remixAutoConsidered' => $params['remixAutoConsidered'] ?? true
|
|
|
-// ],
|
|
|
-// 'notifyHook' => $params['notifyHook'] ?? "",
|
|
|
-// 'state' => $params['state'] ?? ""
|
|
|
-// ];
|
|
|
-//
|
|
|
-// $arr = $this->sendPostRequest($config['api_url'], $postData, $config['api_key']);
|
|
|
-// $response = json_decode($arr['response'], true);
|
|
|
-// $imageid = $response['result'];
|
|
|
-// if (!$imageid) {
|
|
|
-// throw new Exception('未找到图像id');
|
|
|
-// }
|
|
|
-// $imageUrl = $this->getImageSeed('1755151823075229');
|
|
|
-// // 保存到本地
|
|
|
-// $savePath = $this->saveImageToLocal($imageUrl['data']['imageUrl']);
|
|
|
-//
|
|
|
-// return json([
|
|
|
-// 'code' => 200,
|
|
|
-// 'msg' => '图像生成并保存成功',
|
|
|
-// 'data' => [
|
|
|
-// 'local_path' => $savePath,
|
|
|
-// 'web_url' => request()->domain() . $savePath
|
|
|
-// ]
|
|
|
-// ]);
|
|
|
-// }
|
|
|
-//
|
|
|
-// private function sendPostRequest($url, $data, $apiKey)
|
|
|
-// {
|
|
|
-// $ch = curl_init();
|
|
|
-// curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
-// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
-// curl_setopt($ch, CURLOPT_POST, true);
|
|
|
-// curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
|
-// 'Authorization: Bearer ' . $apiKey,
|
|
|
-// 'Accept: application/json',
|
|
|
-// 'Content-Type: application/json'
|
|
|
-// ]);
|
|
|
-// curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
|
|
-// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
-// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
-// curl_setopt($ch, CURLOPT_TIMEOUT, 60);
|
|
|
-//
|
|
|
-// $response = curl_exec($ch);
|
|
|
-// $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
-// $error = curl_error($ch);
|
|
|
-// curl_close($ch);
|
|
|
-//
|
|
|
-// return [
|
|
|
-// 'response' => $response,
|
|
|
-// 'http_code' => $httpCode,
|
|
|
-// 'error' => $error
|
|
|
-// ];
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 获取任务图片地址
|
|
|
-// * @param $taskId
|
|
|
-// * @return array
|
|
|
-// */
|
|
|
-// public function getImageSeed($taskId)
|
|
|
-// {
|
|
|
-// // 配置参数
|
|
|
-// $apiUrl = 'https://chatapi.onechats.ai/mj/task/' . $taskId . '/fetch';
|
|
|
-// $apiKey = 'sk-iURfrAgzAjhZ4PpPLwzmWIAhM7zKfrkwDvyxk4RVBQ4ouJNK';
|
|
|
-//
|
|
|
-// try {
|
|
|
-// // 初始化cURL
|
|
|
-// $ch = curl_init();
|
|
|
-//
|
|
|
-// // 设置cURL选项
|
|
|
-// curl_setopt_array($ch, [
|
|
|
-// CURLOPT_URL => $apiUrl,
|
|
|
-// CURLOPT_RETURNTRANSFER => true,
|
|
|
-// CURLOPT_CUSTOMREQUEST => 'GET', // 明确指定GET方法
|
|
|
-// CURLOPT_HTTPHEADER => [
|
|
|
-// 'Authorization: Bearer ' . $apiKey,
|
|
|
-// 'Accept: application/json',
|
|
|
-// 'Content-Type: application/json'
|
|
|
-// ],
|
|
|
-// CURLOPT_SSL_VERIFYPEER => false,
|
|
|
-// CURLOPT_SSL_VERIFYHOST => false,
|
|
|
-// CURLOPT_TIMEOUT => 60,
|
|
|
-// CURLOPT_FAILONERROR => true // 添加失败时返回错误
|
|
|
-// ]);
|
|
|
-//
|
|
|
-// // 执行请求
|
|
|
-// $response = curl_exec($ch);
|
|
|
-// $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
-//
|
|
|
-// // 错误处理
|
|
|
-// if (curl_errno($ch)) {
|
|
|
-// throw new Exception('cURL请求失败: ' . curl_error($ch));
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 关闭连接
|
|
|
-// curl_close($ch);
|
|
|
-//
|
|
|
-// // 验证HTTP状态码
|
|
|
-// if ($httpCode < 200 || $httpCode >= 300) {
|
|
|
-// throw new Exception('API返回错误状态码: ' . $httpCode);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 解析JSON响应
|
|
|
-// $responseData = json_decode($response, true);
|
|
|
-// if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
-// throw new Exception('JSON解析失败: ' . json_last_error_msg());
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 返回结构化数据
|
|
|
-// return [
|
|
|
-// 'success' => true,
|
|
|
-// 'http_code' => $httpCode,
|
|
|
-// 'data' => $responseData
|
|
|
-// ];
|
|
|
-//
|
|
|
-// } catch (Exception $e) {
|
|
|
-// // 确保关闭cURL连接
|
|
|
-// if (isset($ch) && is_resource($ch)) {
|
|
|
-// curl_close($ch);
|
|
|
-// }
|
|
|
-//
|
|
|
-// return [
|
|
|
-// 'success' => false,
|
|
|
-// 'error' => $e->getMessage(),
|
|
|
-// 'http_code' => $httpCode ?? 0
|
|
|
-// ];
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// private function saveImageToLocal($imageUrl)
|
|
|
-// {
|
|
|
-// // 创建存储目录
|
|
|
-// $saveDir = ROOT_PATH . 'public' . DS . 'uploads' . DS . 'midjourney' . DS . date('Ymd');
|
|
|
-// if (!is_dir($saveDir)) {
|
|
|
-// mkdir($saveDir, 0755, true);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 生成唯一文件名
|
|
|
-// $filename = uniqid() . '.png';
|
|
|
-// $localPath = DS . 'uploads' . DS . 'midjourney' . DS . date('Ymd') . DS . $filename;
|
|
|
-// $fullPath = $saveDir . DS . $filename;
|
|
|
-//
|
|
|
-// // 下载图像
|
|
|
-// $imageData = $this->downloadImage($imageUrl);
|
|
|
-//
|
|
|
-// // 保存到文件
|
|
|
-// if (!file_put_contents($fullPath, $imageData)) {
|
|
|
-// throw new Exception('图像保存失败');
|
|
|
-// }
|
|
|
-//
|
|
|
-// return $localPath;
|
|
|
-// }
|
|
|
-//
|
|
|
-// private function downloadImage($url)
|
|
|
-// {
|
|
|
-// $ch = curl_init($url);
|
|
|
-// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
-// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
-// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
-// curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
|
|
|
-//
|
|
|
-// $imageData = curl_exec($ch);
|
|
|
-// $error = curl_error($ch);
|
|
|
-// curl_close($ch);
|
|
|
-//
|
|
|
-// if (!$imageData) {
|
|
|
-// throw new Exception('图像下载失败: ' . $error);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 基本图像类型验证
|
|
|
-// if (!in_array(getimagesizefromstring($imageData)['mime'] ?? '', ['image/png', 'image/jpeg'])) {
|
|
|
-// throw new Exception('下载内容不是有效图像');
|
|
|
-// }
|
|
|
-//
|
|
|
-// return $imageData;
|
|
|
-// }
|
|
|
-
|
|
|
-// public function txttowimg()
|
|
|
-// {
|
|
|
-// $config = [
|
|
|
-// 'api_url' => 'https://chatapi.onechats.ai/mj/submit/imagine',
|
|
|
-// 'api_key' => 'sk-iURfrAgzAjhZ4PpPLwzmWIAhM7zKfrkwDvyxk4RVBQ4ouJNK',
|
|
|
-// 'prompt' => '一个猫',
|
|
|
-// ];
|
|
|
-//
|
|
|
-// $postData = [
|
|
|
-// 'botType' => 'MID_JOURNEY',
|
|
|
-// 'prompt' => $config['prompt'],
|
|
|
-// 'base64Array' => [],
|
|
|
-// 'accountFilter' => [
|
|
|
-// 'channelId' => "",
|
|
|
-// 'instanceId' => "",
|
|
|
-// 'modes' => [],
|
|
|
-// 'remark' => "",
|
|
|
-// 'remix' => true,
|
|
|
-// 'remixAutoConsidered' => true
|
|
|
-// ],
|
|
|
-// 'notifyHook' => "",
|
|
|
-// 'state' => ""
|
|
|
-// ];
|
|
|
-//
|
|
|
-// $headers = [
|
|
|
-// 'Authorization: Bearer ' . $config['api_key'],
|
|
|
-// 'Accept: application/json',
|
|
|
-// 'Content-Type: application/json'
|
|
|
-// ];
|
|
|
-//
|
|
|
-// $ch = curl_init();
|
|
|
-// curl_setopt($ch, CURLOPT_URL, $config['api_url']);
|
|
|
-// curl_setopt($ch, CURLOPT_POST, true);
|
|
|
-// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
-// curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
|
|
|
-// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
-//
|
|
|
-// $response = curl_exec($ch);
|
|
|
-// $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
-//
|
|
|
-// if (curl_errno($ch)) {
|
|
|
-// $error = curl_error($ch);
|
|
|
-// curl_close($ch);
|
|
|
-// throw new Exception("cURL Error: " . $error);
|
|
|
-// }
|
|
|
-//
|
|
|
-// curl_close($ch);
|
|
|
-//
|
|
|
-// if ($httpCode >= 400) {
|
|
|
-// throw new Exception("API Error: HTTP " . $httpCode . " - " . $response);
|
|
|
-// }
|
|
|
-//
|
|
|
-// return json_decode($response, true);
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// public function txttowimg()
|
|
|
-// {
|
|
|
-// $prompt = 'Cat'; // 或使用 '生成一个猫' 如果要中文
|
|
|
-// $apiUrl = 'https://chatapi.onechats.ai/mj/submit/imagine';
|
|
|
-// $apiKey = "sk-iURfrAgzAjhZ4PpPLwzmWIAhM7zKfrkwDvyxk4RVBQ4ouJNK";
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
/**
|