Websocket.php 866 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace addons\shopro\library;
  3. use fast\Http;
  4. use addons\shopro\library\chat\traits\Helper;
  5. use GuzzleHttp\Client;
  6. class Websocket
  7. {
  8. use Helper;
  9. protected $config = null;
  10. protected $base_uri = null;
  11. public function __construct()
  12. {
  13. $this->config = $this->getConfig('system');
  14. $inside_host = $this->config['inside_host'] ?? '127.0.0.1';
  15. $inside_port = $this->config['inside_port'] ?? '9191';
  16. $this->base_uri = 'http://' . $inside_host . ':' . $inside_port;
  17. }
  18. public function notification($data)
  19. {
  20. $client = new Client();
  21. $response = $client->post($this->base_uri . '/notification', [
  22. 'form_params' => $data
  23. ]);
  24. // 获取结果
  25. $result = $response->getBody()->getContents();
  26. return $result == 'ok' ? true : $result;
  27. }
  28. }