Ins.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace app\service\api;
  3. use app\service\ConfServiceFacade;
  4. use laytp\traits\Error;
  5. use think\facade\Cache;
  6. use think\facade\Config;
  7. use think\facade\Request;
  8. class Ins
  9. {
  10. use Error;
  11. /**
  12. * phpmailer对象
  13. */
  14. protected $client;
  15. protected $key;
  16. /**
  17. * 构造函数
  18. */
  19. public function __construct()
  20. {
  21. $conf = ConfServiceFacade::groupGet('system.ai');
  22. $this->key = $conf['ins_api_key'];
  23. $this->sk = $conf['ins_api_sk'];
  24. if(!$this->key){
  25. $this->setError('接口参数未正确配置');
  26. }
  27. }
  28. /**
  29. * 4
  30. * @param $image //图片链接
  31. */
  32. public function chatgpt4($post=[]) {
  33. $API_URL = 'https://api.wike.cc/api/senseai/chatgpt4';
  34. $post['key'] = $this->key;
  35. $res = $this->send($API_URL, $post, 'GET', true, $this->sk);
  36. return $res;
  37. }
  38. /**
  39. * 4
  40. * @param $image //图片链接
  41. */
  42. public function gpt4($post=[]) {
  43. $API_URL = 'https://api.wike.cc/api/gpt4/set';
  44. $post['key'] = $this->key;
  45. $res = $this->send($API_URL, $post, 'GET', true, $this->sk);
  46. return $res;
  47. }
  48. /**
  49. * AI绘画通用动漫生成
  50. * @param $image //图片链接
  51. */
  52. public function getproxy($type) {
  53. $API_URL = 'https://api.wike.cc/api/gpt/getproxy';
  54. $post['key'] = $this->key;
  55. $post['type'] = $type;
  56. $res = $this->send($API_URL, $post, 'GET', true, $this->sk);
  57. return $res;
  58. }
  59. /**
  60. * 4
  61. * @param $image //图片链接
  62. */
  63. public function sd($post=[]) {
  64. $API_URL = 'https://api.wike.cc/api/painting/sd';
  65. $notify = IS_R==1?request()->domain() . SURL . '/api.gallery/notify':request()->domain() . SURL . '/index.php/api.gallery/notify?uuid='.$post['uuid'];
  66. $post['webhook']=$notify;
  67. $post['key'] = $this->key;
  68. // $post['prompt'] = '1 girl';
  69. $res = $this->send($API_URL, $post, 'POST', true, $this->sk);
  70. // print_r($res);
  71. return $res;
  72. }
  73. /**
  74. * 4
  75. * @param $image //图片链接
  76. */
  77. public function opensd($post=[]) {
  78. $API_URL = 'https://api.wike.cc/api/painting/opensd';
  79. $post['key'] = $this->key;
  80. $res = $this->send($API_URL, $post, 'POST', true, $this->sk);
  81. // print_r($res);
  82. return $res;
  83. }
  84. /**
  85. * 4
  86. * @param $image //图片链接
  87. */
  88. public function opensdDetail($id) {
  89. $API_URL = 'https://api.wike.cc/api/painting/result';
  90. $post['key'] = $this->key;
  91. $post['id'] = $id;
  92. $res = $this->send($API_URL, $post, 'GET', true, $this->sk);
  93. // print_r($res);
  94. return $res;
  95. }
  96. /**
  97. * 4
  98. * @param $image //图片链接
  99. */
  100. public function super_resolution($post=[]) {
  101. $API_URL = 'https://api.wike.cc/api/painting/super_resolution';
  102. $notify = IS_R==1?request()->domain() . SURL . '/api.gallery/notify':request()->domain() . SURL . '/index.php/api.gallery/notify?uuid='.$post['uuid'];
  103. $post['webhook']=$notify;
  104. $post['key'] = $this->key;
  105. $res = $this->send($API_URL, $post, 'GET', true, $this->sk);
  106. // print_r($res);
  107. return $res;
  108. }
  109. /**
  110. * 4
  111. * @param $image //图片链接
  112. */
  113. public function model($engine ='sd') {
  114. $API_URL = 'https://api.wike.cc/api/painting/model';
  115. $post['key'] = $this->key;
  116. $post['engine'] = $engine;
  117. $res = $this->send($API_URL, $post, 'GET', true, $this->sk);
  118. // print_r($res);
  119. return $res;
  120. }
  121. /**
  122. * 4
  123. * @param $image //图片链接
  124. */
  125. public function sd_result($id) {
  126. $API_URL = 'https://api.wike.cc/api/painting/sd_result';
  127. $post['key'] = $this->key;
  128. $post['id'] = $id;
  129. $res = $this->send($API_URL, $post, 'GET', true, $this->sk);
  130. // print_r($res);
  131. return $res;
  132. }
  133. /**
  134. * 4
  135. * @param $image //图片链接
  136. */
  137. public function mj($post=[]) {
  138. $API_URL = 'https://api.wike.cc/api/painting/mj';
  139. $notify = IS_R==1?request()->domain() . SURL . '/api.gallery/mjNotify?uuid='.$post['uuid']:request()->domain() . SURL . '/index.php/api.gallery/mjNotify?uuid='.$post['uuid'];
  140. $post['key'] = $this->key;
  141. $post['callback'] = $notify;
  142. $res = $this->send($API_URL, $post, 'POST', true, $this->sk);
  143. return $res;
  144. }
  145. /**
  146. * 4
  147. * @param $image //图片链接
  148. */
  149. public function zsy($post=[]) {
  150. $API_URL = 'https://api.wike.cc/api/painting/zsy';
  151. $notify = IS_R==1?request()->domain() . SURL . '/api.gallery/mjNotify?uuid='.$post['uuid']:request()->domain() . SURL . '/index.php/api.gallery/mjNotify?uuid='.$post['uuid'];
  152. $post['key'] = $this->key;
  153. $post['callback'] = $notify;
  154. // print_r($post);
  155. $res = $this->send($API_URL, $post, 'POST', true, $this->sk);
  156. return $res;
  157. }
  158. /**
  159. * 4
  160. * @param $image //图片链接
  161. */
  162. public function getAccount() {
  163. $API_URL = 'https://api.wike.cc/api/account/get';
  164. $post['key'] = $this->key;
  165. $res = $this->send($API_URL, $post, 'GET', true, $this->sk);
  166. return $res;
  167. }
  168. public static function send($API_URL, $get_post_data, $type, $ifsign, $sk)
  169. {
  170. $get_post_data = http_build_query($get_post_data);
  171. if ($ifsign) {
  172. $sign = md5($get_post_data . $sk);
  173. // print_r($sign);
  174. $res = self::send_curl($API_URL, $type, $get_post_data, $sign);
  175. } else {
  176. $res = self::send_curl($API_URL, $type, $get_post_data, null);
  177. }
  178. return $res;
  179. }
  180. //封装好的CURL请求函数,支持POST|GET
  181. public static function send_curl($API_URL, $type, $get_post_data, $sign)
  182. {
  183. $ch = curl_init();
  184. if ($type == 'POST') {
  185. curl_setopt($ch, CURLOPT_URL, $API_URL);
  186. curl_setopt($ch, CURLOPT_POST, true);
  187. curl_setopt($ch, CURLOPT_POSTFIELDS, $get_post_data);
  188. } elseif ($type == 'GET') {
  189. curl_setopt($ch, CURLOPT_URL, $API_URL . '?' . $get_post_data);
  190. }
  191. if ($sign) {
  192. curl_setopt($ch, CURLOPT_HTTPHEADER, ['sign:' . $sign]);
  193. }
  194. curl_setopt($ch, CURLOPT_REFERER, $API_URL);
  195. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  196. curl_setopt($ch, CURLOPT_TIMEOUT, 300);
  197. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  198. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  199. $resdata = curl_exec($ch);
  200. curl_close($ch);
  201. return $resdata;
  202. }
  203. public function decrypt($str, $key){
  204. $str = $this->bind_key(base64_decode($str), $key);
  205. $strLen = strlen($str);
  206. $tmp = '';
  207. for($i=0; $i<$strLen; $i++){
  208. $tmp .= $str[$i] ^ $str[++$i];
  209. }
  210. return $tmp;
  211. }
  212. public function bind_key($str, $key){
  213. $encrypt_key = md5($key);
  214. $tmp = '';
  215. $strLen = strlen($str);
  216. for($i=0, $j=0; $i<$strLen; $i++, $j++){
  217. $j = $j == 32 ? 0 : $j;
  218. $tmp .= $str[$i] ^ $encrypt_key[$j];
  219. }
  220. return $tmp;
  221. }
  222. }