| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <?php
- namespace app\service\api;
- use app\service\ConfServiceFacade;
- use laytp\traits\Error;
- use think\facade\Cache;
- use think\facade\Config;
- use think\facade\Request;
- class Ins
- {
- use Error;
- /**
- * phpmailer对象
- */
- protected $client;
- protected $key;
- /**
- * 构造函数
- */
- public function __construct()
- {
- $conf = ConfServiceFacade::groupGet('system.ai');
- $this->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;
- }
- }
|