當前位置: 妍妍網 > 碼農

首創!最全面全功能Midjourney Proxy代理SDK正式釋出!

2024-03-21碼農

midjourney-proxy

全功能Midjourney代理,支持Midjourney所有作圖功能,高效能、穩定,免費。

  • 支持 Imagine(畫圖)

  • 支持 Imagine 時支持添加圖片墊圖

  • 支持擴圖 Pan ⬅️ ➡️ ⬆️ ⬇️

  • 支持擴圖 ZoomOut 🔍

  • 支持自訂擴圖 Custom Zoom 🔍

  • 支持局部重繪 Vary (Region) 🖌

  • 支持 Make Square

  • 支持任務即時進度

  • 支持 Blend(圖片混合)

  • 支持 Describe(圖生文)

  • 支持帳號池

  • 支持禁用詞設定

  • 支持圖片cdn替換

  • 安裝

  • 首先需要安裝webman框架(如果已經安裝請忽略此步驟)

  • composer create-project workerman/webman

  • 進入webman目錄安裝 webman/midjourney

  • cd webman
    composer require webman/midjourney

    配置

    開啟 config/plugin/webman/midjourney/process.php 檔,配置如下

    <?php
    useWebman\Midjourney\TaskStore\File;
    return [
    'server' => [
    'handler' => Webman\Midjourney\Server:: class,
    'listen' => 'http://0.0.0.0:8686',
    'reloadable' => false,
    'constructor' => [
    'config' => [
    'accounts' => [
    [
    'enable' => true,
    'token' => '<獲取方式參見下面>',
    'guild_id' => '<獲取方式參見下面>',
    'channel_id' => '<獲取方式參見下面>',
    'useragent' => '<獲取方式參見下面>',
    'concurrency' => 3// 並行數,10刀/30刀使用者3並行 60刀/120刀使用者12並行
    'timeoutMinutes' => 10// 任務送出後10分鐘後沒有響應則認為超時
    ]
    ],
    'proxy' => [
    'server' => 'https://discord.com', // 國內需要代理,代理搭建參見下面
    'cdn' => 'https://cdn.discordapp.com', // 國內需要代理,代理搭建參見下面
    'gateway' => 'wss://gateway.discord.gg'// 國內需要代理,代理搭建參見下面
    'upload' => 'https://discord-attachments-uploads-prd.storage.googleapis.com'// 國內需要代理,代理搭建參見下面
    ],
    'store' => [
    'handler' => File:: class, // 任務儲存方式
    'expiredDates' => 30// 任務30天後過期
    File:: class => [
    'dataPath' => runtime_path() . '/data/midjourney'// 任務儲存目錄
    ]
    ],
    'settings' => [
    'debug' => false, // 偵錯模式會顯示更多資訊在終端
    'secret' => '', // 介面金鑰,不為空時需要在http頭 mj-api-secret 中傳遞
    'notifyUrl' => ''// webman ai計畫請留空
    'apiPrefix' => ''// 介面字首
    'tmpPath' => runtime_path() . '/tmp/midjourney'// 上傳檔臨時目錄
    ]
    ]
    ]
    ]
    ];

    獲取token、guild_id、channel_id useragent https://www.workerman.net/a/1654

    代理範例

    https服務nginx代理

    discord.com``cdn.discordapp.com``discord-attachments-uploads-prd.storage.googleapis.com 每個網域名稱都要設定一個代理,以discord.com為例代理配置類似如下:

    server {
    listen 80;
    server_name your_domain.com;
    proxy_buffer_size 64k;
    proxy_buffers 3264k;
    proxy_busy_buffers_size 128k;
    location ^~ / {
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_ssl_server_name on;
    proxy_pass https:/
    /discord.com;
    proxy_set_header Host discord.com;
    proxy_set_header Referer "";
    }
    }

    wss服務代理

    註意 gateway.discord.gg websocket 協定,代理方式與上面https代理有所不同。 gateway.discord.gg 代理類似如下:

    server {
    listen 80;
    server_name your_wss_domain.top;
    proxy_buffer_size 64k;
    proxy_buffers 3264k;
    proxy_busy_buffers_size 128k;
    location ^~ / {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_http_version 1.1;
    proxy_ssl_server_name on;
    proxy_pass https:/
    /gateway.discord.gg;
    proxy_set_header Host gateway.discord.gg;
    proxy_set_header Referer "";
    }
    }

    介面

    /image/imagine 畫圖

  • 參數 POST

  • {
    "prompt""a cat",
    "images": [url1, url2, ...], // 可選參數
    "notifyUrl""https://your-server.com/notify"// 可選參數
    }

  • 返回

  • {
    "code"0,
    "msg""ok",
    "taskId""1710816049856103374",
    "data": []
    }

    /image/action 圖片操作

  • 參數 POST

  • {
    "taskId""1710816049856103374",
    "customId""MJ::JOB::upsample::1::749b4d14-75ec-4f16-8765-b2b9a78125fb",
    "notifyUrl""https://your-server.com/notify"// 可選參數
    }

  • 返回

  • {
    "code"0,
    "msg""ok",
    "taskId""1710816302060986090",
    "data": []
    }

    /image/describe 圖生文

  • 參數 POST

  • {
    "images": [url],
    "notifyUrl""https://your-server.com/notify"// 可選參數
    }

  • 返回

  • {
    "code"0,
    "msg""ok",
    "taskId""1710816302060386071",
    "data": []
    }

    /image/blend 圖片混合

  • 參數 POST

  • {
    "images": [url1, url2],
    "notifyUrl""https://your-server.com/notify"// 可選參數
    }

  • 返回

  • {
    "code"0,
    "msg""ok",
    "taskId""1710816302060354172",
    "data": []
    }

    /task/status?taskId=1710816049856103374 任務狀態

  • 返回

  • {
    "code"0,
    "msg""success",
    "data": {
    "id""1710816049856103374",
    "action""IMAGINE",
    "status""FINISHED",
    "submitTime"1710903739,
    "startTime"1710903739,
    "finishTime"1710903844,
    "progress""100%",
    "imageUrl""https:\/\/your_cdn.com\/attachments\/1148151204884726471\/121984387748450658284\/a_cat._65e72369d-1db1-5be4-9566-71056a5b0caf.png?ex=660cc723&is=65fa5223&hm=0d9b721610b62101c7cb4c0f3bf4e364cdd69be3441b9c3b1c200d20b309d97e&",
    "imageRawUrl""https:\/\/cdn.discordapp.com\/attachments\/1148151204884726471\/121984387748450658284\/a_cat._65e72369d-1db1-5be4-9566-71056a5b0caf.png?ex=660cc723&is=65fa5223&hm=0d9b721610b62101c7cb4c0f3bf4e364cdd69be3441b9c3b1c200d20b309d97e&",
    "prompt""A cat. --v 6.0 --relax",
    "finalPrompt""A cat. --v 6.0 --relax",
    "params": [],
    "images": [],
    "description"null,
    "failReason"null,
    "discordId""1148151204875075657",
    "data": [],
    "buttons": [
    [
    {
    "type"2,
    " style"2,
    "label""U1",
    "custom_id""MJ::JOB::upsample::1::65e72369d-1db1-5be4-9566-71056a5b0caf"
    },
    {
    "type"2,
    " style"2,
    "label""U2",
    "custom_id""MJ::JOB::upsample::2::65e72369d-1db1-5be4-9566-71056a5b0caf"
    },
    {
    "type"2,
    " style"2,
    "label""U3",
    "custom_id""MJ::JOB::upsample::3::65e72369d-1db1-5be4-9566-71056a5b0caf"
    },
    {
    "type"2,
    " style"2,
    "label""U4",
    "custom_id""MJ::JOB::upsample::4::65e72369d-1db1-5be4-9566-71056a5b0caf"
    },
    {
    "type"2,
    " style"2,
    "emoji": {
    "name""🔄"
    },
    "custom_id""MJ::JOB::reroll::0::65e72369d-1db1-5be4-9566-71056a5b0caf::SOLO"
    }
    ],
    [
    {
    "type"2,
    " style"2,
    "label""V1",
    "custom_id""MJ::JOB::variation::1::65e72369d-1db1-5be4-9566-71056a5b0caf"
    },
    {
    "type"2,
    " style"2,
    "label""V2",
    "custom_id""MJ::JOB::variation::2::65e72369d-1db1-5be4-9566-71056a5b0caf"
    },
    {
    "type"2,
    " style"2,
    "label""V3",
    "custom_id""MJ::JOB::variation::3::65e72369d-1db1-5be4-9566-71056a5b0caf"
    },
    {
    "type"2,
    " style"2,
    "label""V4",
    "custom_id""MJ::JOB::variation::4::65e72369d-1db1-5be4-9566-71056a5b0caf"
    }
    ]
    ]
    }
    }

    欄位含義

  • id 任務ID

  • action 任務型別 (IMAGINE, UPSCALE, VARIATION 等參考下方 action 值說明)

  • status 任務狀態 (PENDING, STARTED, SUBMITTED, RUNNING, FINISHED, FAILED)

  • submitTime 任務建立時間

  • startTime 開始時間

  • finishTime 完成時間

  • progress 任務進度 0% - 100%,不管成功還是失敗,最終狀態為100%

  • imageUrl 圖片地址 cdn替換後的地址

  • imageRawUrl 圖片原始地址 國內無法存取

  • prompt 提示詞

  • finalPrompt MJ最終使用的提示詞

  • params 任務相關參數

  • images 任務相關圖片,格式為url陣列

  • description 圖生文的結果,只有describe任務有

  • failReason 任務失敗原因,只要此處值不為空代表任務失敗

  • discordId 任務所屬的discord id

  • data 任務自訂數據

  • buttons 任務操作按鈕,其中 custom_id 為 /image/action 介面的 customId 參數

  • action 值說明

  • IMAGINE 畫圖

  • UPSCALE 選圖

  • VARIATION 局部重繪

  • REROLL 重新生成

  • DESCRIBE 圖生文

  • BLEND 圖片混合

  • ZOOMOUT 擴圖

  • ZOOMOUT_CUSTOM 自訂擴圖

  • PANLEFT 擴圖左移

  • PANRIGHT 擴圖右移

  • PANUP 擴圖上移

  • PANDOWN 擴圖下移

  • MAKE_SQUARE 擴圖成正方形

  • PIC_READER 從圖片中提取文字後生成新圖

  • CANCEL_JOB 取消任務

  • UPSCALE_V5_2X v5 2倍高畫質圖

  • UPSCALE_V5_4X v5 4倍高畫質圖

  • UPSCALE_V6_2X_CREATIVE v6 2倍創意高畫質圖

  • UPSCALE_V6_2X_SUBTLE v6 2倍微調高畫質圖

  • VARIATION_STRONG 強烈變換

  • VARIATION_SUBTLE 微調變換

  • VARIATION_REGION 局部重繪

  • notifyUrl 通知格式

    如果有設定 notifyUrl 參數,當任務狀態變化時會向此地址發送 POST 請求,請求內容為任務狀態的 json 格式,格式與 /task/status 介面返回的 data 內容一致。

    {
    "id""1710816049856103374",
    "action""IMAGINE",
    "status""FINISHED",
    "submitTime"1710903739,
    "startTime"1710903739,
    "finishTime"1710903844,
    "progress""100%",
    "imageUrl""https:\/\/your_cdn.com\/attachments\/1148151204884726471\/121984387748450658284\/a_cat._65e72369d-1db1-5be4-9566-71056a5b0caf.png?ex=660cc723&is=65fa5223&hm=0d9b721610b62101c7cb4c0f3bf4e364cdd69be3441b9c3b1c200d20b309d97e&",
    "imageRawUrl""https:\/\/cdn.discordapp.com\/attachments\/1148151204884726471\/121984387748450658284\/a_cat._65e72369d-1db1-5be4-9566-71056a5b0caf.png?ex=660cc723&is=65fa5223&hm=0d9b721610b62101c7cb4c0f3bf4e364cdd69be3441b9c3b1c200d20b309d97e&",
    "prompt""A cat. --v 6.0 --relax",
    "finalPrompt""A cat. --v 6.0 --relax",
    "params": [],
    "images": [],
    "description"null,
    "failReason"null,
    "discordId""1148151204875075657",
    "data": [],
    "buttons": [
    ...
    ]
    }