error('未配置绘画接口参数'); } if(!empty($config['yjai_engine'])){ $this->engine = $config['yjai_engine']; }else{ $this->engine = 'stable_diffusion'; } $this->AK = $conf['api_key_yj']; $this->SK = $conf['api_secret_yj']; $this->timestamp = time(); } // 开始绘画 public function put_task($prompt){ $url = self::API_URL."put_task"; $data = array( 'apikey'=>$this->AK, 'timestamp'=>$this->timestamp, 'prompt'=>$prompt, 'engine'=>$this->engine, 'ratio'=>0, 'style'=>'', 'guidence_scale'=>7.5 ); $n = $this->http_post($url,$data); return $n; } // 获取任务详情 public function show_task($uuid){ $url = self::API_URL."show_task_detail"; $data = array( 'apikey'=>$this->AK, 'timestamp'=>$this->timestamp, 'uuid'=>$uuid, ); $n = $this->http_post($url,$data); return $n; } // 获取完成的任务 public function show_complete_tasks($uuid){ $url = self::API_URL."show_complete_tasks"; $data = array( 'apikey'=>$this->AK, 'timestamp'=>$this->timestamp ); $n = $this->http_post($url,$data); return $n; } // 获取用户信息 public function getUserInfo(){ // return $this->getsign(); $url = self::API_URL."getUserInfo"; $data = array( 'apikey'=>$this->AK, 'timestamp'=>$this->timestamp, ); $n = $this->http_post($url,$data); return $n; } private function getsign($data=array()) { $arr = array_merge(array('apisecret'=>$this->SK),$data); ksort($arr); foreach ($arr as $key => $val) { $param[] = $key . "=" .($val); } $sparam = join("&", $param); // return $sparam; $s = md5($sparam); return $s; } /** * POST 请求 * @param string $url * @param array $param * @param boolean $post_file 是否文件上传 * @return string content */ private function http_post($url, $param, $jsonpost = false, $post_file = false) { $oCurl = curl_init(); if (stripos($url, "https://") !== FALSE) { curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1 } $httpHeaders = array("Content-Type:application/x-www-form-urlencoded","sign:".$this->getsign($param)); // return array($this->getsign($param),$param); if ($jsonpost) { $strPOST = str_replace('\/', '/', json_encode($param)); } elseif (is_string($param) || $post_file) { $strPOST = $param; } else { $aPOST = array(); foreach ($param as $key => $val) { $aPOST[] = $key . "=" .($val); } $strPOST = join("&", $aPOST); } curl_setopt($oCurl, CURLOPT_URL, $url); curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($oCurl, CURLOPT_POST, true); curl_setopt($oCurl, CURLOPT_HTTPHEADER, $httpHeaders); curl_setopt($oCurl, CURLOPT_POSTFIELDS, $strPOST); $sContent = curl_exec($oCurl); $sContent = json_decode($sContent,true); return $sContent; $aStatus = curl_getinfo($oCurl); curl_close($oCurl); if ($sContent["status"] == 200) { return $sContent; } else { return false; } } public function getError() { return $this->error; } }