WebSocket私信聊天(无群聊天)

//php 后端  
on('open', function (Swoole\WebSocket\Server $server, $request) {
    //$server->push($request->fd, '欢迎进入我们的聊天室~');
});

//接收客户端发送的信息
//$frame 是 Swoole\WebSocket\Frame 对象,包含了客户端发来的数据帧信息
//$frame->fd 代表客户端的唯一标识 客户id
//$frame->data  代表客户端发送的消息
$server->on('message', function (Swoole\WebSocket\Server $server, $frame) {

    //获取客户端发送的消息
    $type = json_decode($frame->data,true);
    if($type['type'] != 'active'){
        $result['data'] = $frame->data;
        $types = 1;
        $framedata = json_decode($frame->data,true);
        $openid  = $framedata['openid'];
        $endopenid  = $framedata['endopenid'];
        $imgtype  = $framedata['imgtype'];
        $url = 'http://www.xxx.com/';
        $wxapp = '/app/index.php?i=2&t=0&v=1.01&from=wxapp&c=entry&a=wxapp';
        // 会话列表创建会话接口
        $socket_add = '&do=chat_socket_add&m=gc_school&';
        //会话信息查询接口
        $socket_find = '&do=chat_socket_find&m=gc_school&';
        //用户openid 绑定会话 fd 接口
        $user_fid = '&do=chat_user_find&m=gc_school&';
        //存储消息记录
        $socket_log = '&do=socket_log&m=gc_school&';
        //重置fd为0
        $socket_isfd = '&do=socket_isfd&m=gc_school&';
        //查询对方的fd
        $user_endfind = '&do=chat_user_endfind&m=gc_school&';
        //查询用户信息
        $Socket_users = '&do=Socket_users&m=gc_school&';

        //如果不存在会话id 就去创建会话ID

// var_dump( f r a m e − > r e l a t i o n ) ; d i e ; i f ( frame->relation);die; if( frame>relation);die;if(framedata[‘relation’]){
u s e s s = ′ i d s = ′ . usess = 'ids='. usess=ids=.framedata[‘relation’];
//如果存在会话id就去查询会话id的信息
$relation_url = u r l . url. url.wxapp. s o c k e t f i n d . socket_find. socketfind.usess;
r e l a t i o n d a t a = f i l e g e t c o n t e n t s ( relationdata = file_get_contents( relationdata=filegetcontents(relation_url); // 查询会话信息
}else{
u s e s s = ′ o p e n i d = ′ . usess = 'openid='. usess=openid=.openid.‘&endopenid=’.$endopenid;
//拼接创建会话id信息并请求接口
$relation_url = u r l . url. url.wxapp. s o c k e t a d d . socket_add. socketadd.usess;
r e l a t i o n d a t a = f i l e g e t c o n t e n t s ( relationdata = file_get_contents(

你可能感兴趣的:(php,websocket,swoole)