| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 | <?phpnamespace app\service\api;use app\service\ConfServiceFacade;use laytp\traits\Error;use think\facade\Cache;use think\facade\Config;use think\facade\Request;class Sdapi{  use Error;  /**     * phpmailer对象     */     protected $client;     protected $key;     protected $host;    /**     * 构造函数     */    public function __construct()    {        $conf  = ConfServiceFacade::groupGet('system.ai');        $this->key = $conf['ins_api_key'];        $this->sk = $conf['ins_api_sk'];        $this->host = 'https://stablediffusionapi.com/api/v3/';        if(!$this->key){            $this->setError('接口参数未正确配置');        }    }    /**     * 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/json");        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, json_encode($param));        $sContent = curl_exec($oCurl);        $sContent = json_decode($sContent,true);        $aStatus = curl_getinfo($oCurl);        curl_close($oCurl);        return $sContent;        if ($sContent["status"] == 200) {            return $sContent;        } else {            return false;        }    }}
 |