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


}

查看结果

调用推送的接口

到这里说明已经交互成功

相关推荐
niucloud-admin2 小时前
PHP SAAS 框架常见问题——配置问题——腾讯地图配置
php
北漂Zachary3 小时前
PHP3.0:改变Web开发的里程碑
android·php·laravel
实在智能RPA3 小时前
Agent 如何处理流程中的异常情况?——2026企业级智能体稳定性架构深度拆解
开发语言·人工智能·ai·架构·php
aq55356003 小时前
PHP vs C++ vs 易语言:编程语言终极对比
开发语言·c++·php
niucloud-admin4 小时前
PHP SAAS 框架常见问题——配置问题——绑定手机号时提示“failed to verify SmsSdkAppld“
php
农村小镇哥5 小时前
PDO介绍+PDO增删改查+PDO事物处理+DPO封装类
php
niucloud-admin6 小时前
PHP SAAS 框架常见问题——配置问题——接口请求错误,请检查参数配置或伪静态配置
php
SPC的存折7 小时前
在Alpine 搭建 WordPress
linux·运维·服务器·数据库·php
黑牛儿7 小时前
AI Agent\+PHP实现智能接口限流,避开算力成本陷阱(结合今日AI热点)
开发语言·人工智能·php
北漂Zachary8 小时前
PHP vs C++ vs 易语言:三大语言对比解析
开发语言·c++·php