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


}

查看结果

调用推送的接口

到这里说明已经交互成功

相关推荐
珍珠是蚌的眼泪3 小时前
微服务_入门2
网关·微服务·gateway·远程调用·feign
铁板鱿鱼1404 小时前
统一网关--gateway(仅供自己参考)
gateway
bug菌¹4 小时前
滚雪球学SpringCloud[4.2讲]: Zuul:Netflix API Gateway详解
spring·spring cloud·gateway
Book_熬夜!6 小时前
Python基础(九)——正则表达式
python·正则表达式·php
计算机学姐7 小时前
基于PHP的电脑线上销售系统
开发语言·vscode·后端·mysql·编辑器·php·phpstorm
BLEACH-heiqiyihu8 小时前
红帽9中nginx-源码编译php
运维·nginx·php
翔云API8 小时前
人证合一接口:智能化身份认证的最佳选择
大数据·开发语言·node.js·ocr·php
白总Server8 小时前
MongoDB解说
开发语言·数据库·后端·mongodb·golang·rust·php
fakaifa9 小时前
八戒农场小程序V2最新源码
小程序·uni-app·php·生活·开源软件
吱吱鼠叔10 小时前
MATLAB方程求解:1.线性方程组
开发语言·matlab·php