121 lines
3.7 KiB
PHP
121 lines
3.7 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
namespace app\api\model;
|
|||
|
|
|
|||
|
|
class WebSocketPush
|
|||
|
|
{
|
|||
|
|
public $websocket_api_address;
|
|||
|
|
public $websocket_api_key;
|
|||
|
|
/*
|
|||
|
|
200 通用数据
|
|||
|
|
|
|||
|
|
房间PK
|
|||
|
|
220 推送PK当前结果数据
|
|||
|
|
|
|||
|
|
300
|
|||
|
|
用户进入房间推送消息
|
|||
|
|
301
|
|||
|
|
房间麦位信息
|
|||
|
|
302
|
|||
|
|
房间赠送礼物推送数据
|
|||
|
|
303
|
|||
|
|
开宝箱房间播报数据
|
|||
|
|
304
|
|||
|
|
开宝箱全服播报数据
|
|||
|
|
400
|
|||
|
|
房间相亲数据
|
|||
|
|
*/
|
|||
|
|
public function __construct()
|
|||
|
|
{
|
|||
|
|
$config = model('admin/Config')->get_system_config();
|
|||
|
|
$this->websocket_api_address = $config['websocket_api_address'];
|
|||
|
|
$this->websocket_api_key = $config['websocket_api_key'];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//发送消息给个人
|
|||
|
|
public function send_to_one($uid, $content)
|
|||
|
|
{
|
|||
|
|
$post_data = [];
|
|||
|
|
$post_data['action'] = 'send_to_one';
|
|||
|
|
$post_data['key'] = $this->websocket_api_key;
|
|||
|
|
if (is_array($content)) {
|
|||
|
|
$post_data['content'] = json_encode($content);
|
|||
|
|
} else {
|
|||
|
|
$post_data['content'] = $content;
|
|||
|
|
}
|
|||
|
|
$post_data['uid'] = $uid;
|
|||
|
|
$content = $this->myCurl($this->websocket_api_address, $post_data);
|
|||
|
|
return $content;
|
|||
|
|
}
|
|||
|
|
//发送消息到指定房间
|
|||
|
|
public function send_to_group($rid, $content)
|
|||
|
|
{
|
|||
|
|
$post_data = [];
|
|||
|
|
$post_data['action'] = 'send_to_group';
|
|||
|
|
$post_data['key'] = $this->websocket_api_key;
|
|||
|
|
if (is_array($content)) {
|
|||
|
|
$post_data['content'] = json_encode($content);
|
|||
|
|
} else {
|
|||
|
|
$post_data['content'] = $content;
|
|||
|
|
}
|
|||
|
|
$post_data['hid'] = $rid;
|
|||
|
|
$content = $this->myCurl($this->websocket_api_address, $post_data);
|
|||
|
|
return $content;
|
|||
|
|
}
|
|||
|
|
//发送群体消息
|
|||
|
|
public function send_to_all($content)
|
|||
|
|
{
|
|||
|
|
$post_data = [];
|
|||
|
|
$post_data['action'] = 'send_to_all';
|
|||
|
|
$post_data['key'] = $this->websocket_api_key;
|
|||
|
|
if (is_array($content)) {
|
|||
|
|
$post_data['content'] = json_encode($content);
|
|||
|
|
} else {
|
|||
|
|
$post_data['content'] = $content;
|
|||
|
|
}
|
|||
|
|
// dump($post_data);
|
|||
|
|
$content = $this->myCurl($this->websocket_api_address, $post_data);
|
|||
|
|
return $content;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public function getallclients()
|
|||
|
|
{
|
|||
|
|
$post_data = [];
|
|||
|
|
$post_data['action'] = 'getallclients';
|
|||
|
|
$post_data['key'] = $this->websocket_api_key;
|
|||
|
|
$content = $this->myCurl($this->websocket_api_address, $post_data);
|
|||
|
|
return $content;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies
|
|||
|
|
public function myCurl($url, $post_data = array(), $header = array(), $cookie = "")
|
|||
|
|
{
|
|||
|
|
// $url = 'http://paysystem.local.com/index/apip/cc';
|
|||
|
|
// dump($url);
|
|||
|
|
$ch = curl_init();
|
|||
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|||
|
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
|||
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果把这行注释掉的话,就会直接输出
|
|||
|
|
$curl_header = array();
|
|||
|
|
if (!empty($header)) {
|
|||
|
|
foreach ($header as $k => $v) {
|
|||
|
|
$curl_header[] = "$k:$v";
|
|||
|
|
}
|
|||
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_header);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!empty($post_data)) {
|
|||
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
|
|||
|
|
}
|
|||
|
|
if (!empty($cookie)) {
|
|||
|
|
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
|
|||
|
|
}
|
|||
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|||
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|||
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
|||
|
|
$result = curl_exec($ch);
|
|||
|
|
curl_close($ch);
|
|||
|
|
return $result;
|
|||
|
|
}
|
|||
|
|
}
|