MidJourneyService.php 2.4 KB
<?php
/**
 * @remark :
 * @name   :MidJourneyService.php
 * @author :lyh
 * @method :post
 * @time   :2025/8/2 10:48
 */

namespace App\Services;

use Illuminate\Support\Facades\Http;

class MidJourneyService
{
    /**
     * 请求域名
     * @var string
     */
    public $url = 'https://api.cmer.com';

    public $header = [
        'apikey' => 'UkzZljFv83Z2qBi5YR1o3f2otAVWtug6',
        'X-CmerApi-Host' => 'aiccmj.p.cmer.com',
    ];

    /**
     * @remark :提交生成图片
     * @name   :imagine
     * @author :lyh
     * @method :post
     * @time   :2025/8/2 10:50
     */
    public function imagine($content, string $refer_img = ''){
        try {
            $data = ['prompt' => $content];
            //回调地址
            $data['callback_url'] = route('api.ImageCallBack');
            $result = Http::withHeaders($this->header)->withoutVerifying()->post($this->url.'/v1/api/trigger/imagine', $data);
            $json = $result->json();
        }catch (\Throwable $e){
            dump($e->getMessage());
            $json = [];
        }
        return $json ?: [];
    }

    /**
     * 扩展图片
     * @param $index
     * @param $msg_id
     * @param $msg_hash
     * @param $trigger_id
     * @return array|mixed
     */
    public function upscale($index, $msg_id, $msg_hash, $trigger_id){
        try {
            $result = Http::withHeaders($this->header)->withoutVerifying()->post($this->url.'/v1/api/trigger/upscale', [
                "index" => $index,
                "msg_id" => $msg_id,
                "msg_hash" => $msg_hash,
                "trigger_id" => $trigger_id
            ]);
            $json = $result->json();
        }catch (\Throwable $e){
            $json = [];
        }
        return $json;
    }

    /**
     * 优化图片
     * @param $index
     * @param $msg_id
     * @param $msg_hash
     * @param $trigger_id
     * @return array|mixed
     */
    public function variation($index, $msg_id, $msg_hash, $trigger_id){
        try {
            $result = Http::withHeaders($this->header)->withoutVerifying()->post($this->url.'/v1/api/trigger/variation', [
                "index" => $index,
                "msg_id" => $msg_id,
                "msg_hash" => $msg_hash,
                "trigger_id" => $trigger_id
            ]);
            $json = $result->json();
        }catch (\Throwable $e){
            $json = [];
        }
        return $json;
    }
}