在PHP服务端使用gatewayclient的 Gateway::sendToUid($uid, $message);不起作用

crazehe

是不是gatewayclient没有安装对还是怎么回事,这些接口都不能正常使用,这是怎么回事

header("content-type:text/html;charset=utf-8");
require_once 'GatewayClient/Gateway.php';
use GatewayClient\Gateway;
Gateway::$registerAddress = '127.0.0.1:1236';
$uid = $_POST['user_id'];
//$msg = $_POST['msg'];
$msg = '{"type":"say_to_one","to_client_id":100,"content":"hello"}';
$req_data = json_decode($msg, true);
Gateway::sendToUid($uid, $req_data);
$data['uid'] = $uid;
$data['code'] = 100;
echo json_encode($data);

1604 2 0
2个回答

blogdaren

1、不好使的话就先研究官方的注意事项: https://github.com/walkor/gatewayclient
2、另 void Gateway::sendToUid(mixed $uid, string $message); 第二个参数要求是string

  • crazehe 2021-08-03

    我是直接下载源码的 ,按照文档引入使用,,第二个参数也换了很多格式,就是不起作用
    是不是服务器还要有什么配置?

阿罗

第二个参数应该是字符串,你发的是数组。
还有$data也未定义。
另外sendToUid要求有调用bindUid,并且uid在线,否则肯定收不到。
最好用sendToAll接口试下,避免你binduid有问题。

  • crazehe 2021-08-03

    找到问题了 是端口问题,下载的源文件端口设置居然不一致

  • blogdaren 2021-08-03

    @8180: 为什么要一致呢? 不同的人部署时监听的服务端口五花八门、源码里自然设定的就是一个默认连接端口、而且提供了自由配置功能、合情合理。

年代过于久远,无法发表回答
🔝