goWs.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/5/29 22:25
  5. */
  6. namespace common\components;
  7. use linslin\yii2\curl;
  8. use Yii;
  9. class goWs
  10. {
  11. public static function bindUid($uid,$clientId)
  12. {
  13. $path = '/bind?uid='.$uid.'&clientId='.$clientId;
  14. Yii::info("bindUid path: ".$path);
  15. self::request($path);
  16. }
  17. public static function sendToUid($uid,$msg){
  18. $path = '/send';
  19. $param = [
  20. 'uid'=>$uid,
  21. 'msg'=>$msg
  22. ];
  23. Yii::info("sendToUid path: ".$path);
  24. self::request($path,'post',$param);
  25. }
  26. public static function request($path,$method='get',$params = [])
  27. {
  28. //暂时先写死
  29. $url = 'http://127.0.0.1:7777';
  30. $url = $url.$path;
  31. $curl = new curl\Curl();
  32. $curl->setOptions([
  33. CURLOPT_TIMEOUT => 2,
  34. CURLOPT_CONNECTTIMEOUT => 2,
  35. ]);
  36. if($method=='get'){
  37. $curl->get($url);
  38. }else{
  39. //post
  40. $curl->setOption(CURLOPT_POSTFIELDS, http_build_query($params))->post($url);
  41. }
  42. }
  43. }