laraval6.0 GatewayWorker 交互通信

laravel 6.0 GatewayWorker 通讯

开发前准备

GatewayClient 官网:https://www.workerman.net/

当前使用的是宝塔操作

下载 GatewayWorker 及操作方式

前端demo

测试效果

项目中安装GatewayClient

php 复制代码
composer require workerman/gatewayclient

绑定用户 和 消息推送

php 复制代码
<?php


namespace App\Http\Controllers\Common;

use App\Exceptions\Exception\ErrorException;
use GatewayClient\Gateway;

require_once '../vendor/workerman/gatewayclient/Gateway.php';

class Push
{

    public function __construct()
    {
        //注意:127.0.0.1:1238 的1238端口不是随意填写的 是在GatewayWorker/yourApp/start_gateway.php 里面
        //$gateway->registerAddress = '127.0.0.1:1238'; 配置的
        Gateway::$registerAddress = '127.0.0.1:1238';
    }


    /**
     * Notes:  绑定用户
     * Author: Seven
     * Method: getUserBinding
     * Date: 2023/11/29: 17:27
     * @param $client_id
     * @param $users_id
     */
    public function getUserBinding($param)
    {
        if(empty($param['client_id'])) throw new ErrorException('缺少 client_id');
        if(empty($param['users_id'])) throw new ErrorException('缺少 users_id');
        Gateway::bindUid($param['client_id'],$param['users_id']);
        dd($param['client_id']);
    }


    /**
     * Notes:  推送信息
     * Author: Seven
     * Method: getSendPush
     * Date: 2023/11/29: 17:42
     * @param $users_id
     * @param $content
     */
    public function getSendPush($users_id,$type,$content){
        $data = [
            'type'=>$type,
            'msg'=>$content,
        ];
        Gateway::sendToUid($users_id,json_encode($data));
    }


}

查看结果

调用推送的接口

到这里说明已经交互成功

相关推荐
hao_wujing15 分钟前
攻击模型的恶意行为检测
网络·数据库·php
背太阳的牧羊人5 小时前
backend 服务尝试连接 qdrant 容器,但失败了,返回 502 Bad Gateway 问题排查
docker·gateway·qdrant
Yungoal16 小时前
php & apache构建 Web 服务器
服务器·php·apache
浩浩测试一下16 小时前
Authpf(OpenBSD)认证防火墙到ssh连接到SSH端口转发技术栈 与渗透网络安全的关联 (RED Team Technique )
网络·网络协议·tcp/ip·安全·网络安全·php
孤寂大仙v17 小时前
【计算机网络】网络层IP协议与子网划分详解:从主机通信到网络设计的底层逻辑
tcp/ip·计算机网络·php
vortex521 小时前
浅谈 Linux 防火墙:从原理到实践
linux·网络·php
come112341 天前
Claude 写 PHP 项目的完整小白教程
开发语言·php
曼彻斯特的海边1 天前
RequestRateLimiterGatewayFilterFactory
spring cloud·gateway·限流
·云扬·1 天前
【PmHub面试篇】Gateway全局过滤器统计接口调用耗时面试要点解析
面试·职场和发展·gateway
devil_mf1 天前
gateway 网关 路由新增 (已亲测)
gateway