Tuling.php 852 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace App\Utils;
  3. use App\Models\User;
  4. use App\Services\Config;
  5. class Tuling
  6. {
  7. public static function chat($user, $text)
  8. {
  9. if (Config::get('enable_tuling') == 'true') {
  10. $data = array();
  11. $data['key'] = Config::get('tuling_apikey');
  12. $data['userid'] = $user;
  13. $data['info'] = $text;
  14. $param = json_encode($data);
  15. $sock = new HTTPSocket;
  16. $sock->connect("www.tuling123.com", 80);
  17. $sock->set_method('POST');
  18. $sock->add_header('Content-Type', 'application/json');
  19. $sock->query('/openapi/api', $param);
  20. $result = $sock->fetch_body();
  21. $result_array = json_decode($result, true);
  22. return $result_array['text'];
  23. }
  24. }
  25. }