| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- /**
- * User: admin
- * Date Time: 2021/5/29 22:25
- */
- namespace common\components;
- use linslin\yii2\curl;
- use Yii;
- class goWs
- {
- public static function bindUid($uid,$clientId)
- {
- $path = '/bind?uid='.$uid.'&clientId='.$clientId;
- Yii::info("bindUid path: ".$path);
- self::request($path);
- }
- public static function sendToUid($uid,$msg){
- $path = '/send';
- $param = [
- 'uid'=>$uid,
- 'msg'=>$msg
- ];
- Yii::info("sendToUid path: ".$path);
- self::request($path,'post',$param);
- }
- public static function request($path,$method='get',$params = [])
- {
- //暂时先写死
- $url = 'http://127.0.0.1:7777';
- $url = $url.$path;
- $curl = new curl\Curl();
- $curl->setOptions([
- CURLOPT_TIMEOUT => 2,
- CURLOPT_CONNECTTIMEOUT => 2,
- ]);
- if($method=='get'){
- $curl->get($url);
- }else{
- //post
- $curl->setOption(CURLOPT_POSTFIELDS, http_build_query($params))->post($url);
- }
- }
- }
|