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));
    }


}

查看结果

调用推送的接口

到这里说明已经交互成功

相关推荐
AI+程序员在路上20 小时前
网桥及IP转发在嵌入式linux eth0与wlan0连接使用方法
linux·tcp/ip·php
微爱帮监所写信寄信1 天前
微爱帮监狱寄信写信系统后台PHP框架优化实战手册
android·开发语言·人工智能·网络协议·微信·https·php
白帽子黑客罗哥1 天前
网络安全防护技术与实战策略:从基础防御到前沿应对
安全·web安全·php
快点好好学习吧1 天前
PHP程序员到底为什么要学习正则表达式?使用场景是什么?底层原理是什么?
学习·正则表达式·php
Smartdaili China1 天前
如何在桌面和移动设备上修复YouTube错误400
开发语言·php·error·youtube·移动·住宅ip·错误400
yyf198905251 天前
用PHP实现论坛功能
php
毕设源码-赖学姐1 天前
【开题答辩全过程】以 基于PHP的国学诗词网站与推荐系统的设计与实现为例,包含答辩的问题和答案
开发语言·php
oMcLin1 天前
如何在 Ubuntu 24.04 上安装 LAMP 堆栈(包括 PHP 8.3 和 MariaDB 11)
ubuntu·php·mariadb
运维闲章印时光1 天前
单位本部与分部网络已实现互联互通,网络访问通畅,数据传输正常
开发语言·网络·php
福尔摩斯张2 天前
Linux的pthread_self函数详解:多线程编程中的身份标识器(超详细)
linux·运维·服务器·网络·网络协议·tcp/ip·php