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


}

查看结果

调用推送的接口

到这里说明已经交互成功

相关推荐
m0_738120721 天前
sqli-labs过关解析(17- 20附带源码解析)
数据库·sql·web安全·php·ctf·安全性测试
lucky67071 天前
Laravel 9.x LTS重磅升级:六大核心改进
java·php·laravel
Zhu_S W1 天前
Java图论基础:有向图与无向图详解
开发语言·php
lucky67071 天前
Laravel5.x核心特性全解析
mysql·php·laravel
lucky67071 天前
Laravel 10.X 新特性全解析
php·laravel
cheems95271 天前
【网络原理】网络编程基础:TCP Echo Server 的底层逻辑与实现
网络·tcp/ip·php
globaldomain2 天前
立海世纪:优质品牌域名对企业的潜在价值
开发语言·php·主机·网站·域名注册
苏天夏2 天前
让 Typecho 拥抱 WebAuthn 无密码时代
安全·网络安全·php·开源软件
wangjialelele2 天前
万字整理计算机网络知识点
linux·c语言·网络·c++·计算机网络·php
天一生水water2 天前
LangChain的智能体教程
开发语言·人工智能·langchain·php·智慧油田