跳到主要内容

PHP发送 - PubSub (Websocket)

本节内容为PHP实现GoEasy Rest接口发送消息, 使用时,可参阅Rest接口的详细介绍

PHP

<?php
// 新加坡rest-host:rest-singapore.goeasy.io
$url = "https://rest-hz.goeasy.io/v2/pubsub/publish";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$headers = array(
"Accept: application/json",
"Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$data = <<<DATA
{
"appkey": "您的appkey",
"channel": "test_channel",
"content": "Hello, GoEasy!"
}
DATA;

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>

REST Host

杭州: rest-hz.goeasy.io
新加坡: rest-singapore.goeasy.io

本页目录: