key = $conf['ins_api_key']; $this->sk = $conf['ins_api_sk']; if(!$this->key){ $this->setError('接口参数未正确配置'); } } /** * 4 * @param $image //图片链接 */ public function chatgpt4($post=[]) { $API_URL = 'https://api.wike.cc/api/senseai/chatgpt4'; $post['key'] = $this->key; $res = $this->send($API_URL, $post, 'GET', true, $this->sk); return $res; } /** * 4 * @param $image //图片链接 */ public function gpt4($post=[]) { $API_URL = 'https://api.wike.cc/api/gpt4/set'; $post['key'] = $this->key; $res = $this->send($API_URL, $post, 'GET', true, $this->sk); return $res; } /** * AI绘画通用动漫生成 * @param $image //图片链接 */ public function getproxy($type) { $API_URL = 'https://api.wike.cc/api/gpt/getproxy'; $post['key'] = $this->key; $post['type'] = $type; $res = $this->send($API_URL, $post, 'GET', true, $this->sk); return $res; } /** * 4 * @param $image //图片链接 */ public function sd($post=[]) { $API_URL = 'https://api.wike.cc/api/painting/sd'; $notify = IS_R==1?request()->domain() . SURL . '/api.gallery/notify':request()->domain() . SURL . '/index.php/api.gallery/notify?uuid='.$post['uuid']; $post['webhook']=$notify; $post['key'] = $this->key; // $post['prompt'] = '1 girl'; $res = $this->send($API_URL, $post, 'POST', true, $this->sk); // print_r($res); return $res; } /** * 4 * @param $image //图片链接 */ public function opensd($post=[]) { $API_URL = 'https://api.wike.cc/api/painting/opensd'; $post['key'] = $this->key; $res = $this->send($API_URL, $post, 'POST', true, $this->sk); // print_r($res); return $res; } /** * 4 * @param $image //图片链接 */ public function opensdDetail($id) { $API_URL = 'https://api.wike.cc/api/painting/result'; $post['key'] = $this->key; $post['id'] = $id; $res = $this->send($API_URL, $post, 'GET', true, $this->sk); // print_r($res); return $res; } /** * 4 * @param $image //图片链接 */ public function super_resolution($post=[]) { $API_URL = 'https://api.wike.cc/api/painting/super_resolution'; $notify = IS_R==1?request()->domain() . SURL . '/api.gallery/notify':request()->domain() . SURL . '/index.php/api.gallery/notify?uuid='.$post['uuid']; $post['webhook']=$notify; $post['key'] = $this->key; $res = $this->send($API_URL, $post, 'GET', true, $this->sk); // print_r($res); return $res; } /** * 4 * @param $image //图片链接 */ public function model($engine ='sd') { $API_URL = 'https://api.wike.cc/api/painting/model'; $post['key'] = $this->key; $post['engine'] = $engine; $res = $this->send($API_URL, $post, 'GET', true, $this->sk); // print_r($res); return $res; } /** * 4 * @param $image //图片链接 */ public function sd_result($id) { $API_URL = 'https://api.wike.cc/api/painting/sd_result'; $post['key'] = $this->key; $post['id'] = $id; $res = $this->send($API_URL, $post, 'GET', true, $this->sk); // print_r($res); return $res; } /** * 4 * @param $image //图片链接 */ public function mj($post=[]) { $API_URL = 'https://api.wike.cc/api/painting/mj'; $notify = IS_R==1?request()->domain() . SURL . '/api.gallery/mjNotify?uuid='.$post['uuid']:request()->domain() . SURL . '/index.php/api.gallery/mjNotify?uuid='.$post['uuid']; $post['key'] = $this->key; $post['callback'] = $notify; $res = $this->send($API_URL, $post, 'POST', true, $this->sk); return $res; } /** * 4 * @param $image //图片链接 */ public function zsy($post=[]) { $API_URL = 'https://api.wike.cc/api/painting/zsy'; $notify = IS_R==1?request()->domain() . SURL . '/api.gallery/mjNotify?uuid='.$post['uuid']:request()->domain() . SURL . '/index.php/api.gallery/mjNotify?uuid='.$post['uuid']; $post['key'] = $this->key; $post['callback'] = $notify; // print_r($post); $res = $this->send($API_URL, $post, 'POST', true, $this->sk); return $res; } /** * 4 * @param $image //图片链接 */ public function getAccount() { $API_URL = 'https://api.wike.cc/api/account/get'; $post['key'] = $this->key; $res = $this->send($API_URL, $post, 'GET', true, $this->sk); return $res; } public static function send($API_URL, $get_post_data, $type, $ifsign, $sk) { $get_post_data = http_build_query($get_post_data); if ($ifsign) { $sign = md5($get_post_data . $sk); // print_r($sign); $res = self::send_curl($API_URL, $type, $get_post_data, $sign); } else { $res = self::send_curl($API_URL, $type, $get_post_data, null); } return $res; } //封装好的CURL请求函数,支持POST|GET public static function send_curl($API_URL, $type, $get_post_data, $sign) { $ch = curl_init(); if ($type == 'POST') { curl_setopt($ch, CURLOPT_URL, $API_URL); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $get_post_data); } elseif ($type == 'GET') { curl_setopt($ch, CURLOPT_URL, $API_URL . '?' . $get_post_data); } if ($sign) { curl_setopt($ch, CURLOPT_HTTPHEADER, ['sign:' . $sign]); } curl_setopt($ch, CURLOPT_REFERER, $API_URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 300); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $resdata = curl_exec($ch); curl_close($ch); return $resdata; } public function decrypt($str, $key){ $str = $this->bind_key(base64_decode($str), $key); $strLen = strlen($str); $tmp = ''; for($i=0; $i<$strLen; $i++){ $tmp .= $str[$i] ^ $str[++$i]; } return $tmp; } public function bind_key($str, $key){ $encrypt_key = md5($key); $tmp = ''; $strLen = strlen($str); for($i=0, $j=0; $i<$strLen; $i++, $j++){ $j = $j == 32 ? 0 : $j; $tmp .= $str[$i] ^ $encrypt_key[$j]; } return $tmp; } }