PHP使用GOEASY实现WEB实时推送

时间:2022-12-23 03:37:03
   /**
* 订单提醒
*/
public function sendOrderNotice(){
//请求地址
$uri = "http://goeasy.io/goeasy/publish";
// 参数数组
$data = [
'appkey' => "你的APPkey",
'channel' => "demo",
'content' =>"您有新的订单"
];
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $uri );//地址
curl_setopt ( $ch, CURLOPT_POST, 1 );//请求方式为post
curl_setopt ( $ch, CURLOPT_HEADER, 0 );//不打印header信息
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );//返回结果转成字符串
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );//post传输的数据。
$return = curl_exec ( $ch );
curl_close ( $ch );
print_r($return);
}

PHP发送消息提醒

成功则返回:

PHP使用GOEASY实现WEB实时推送

<script type="text/javascript" src="http://cdn.goeasy.io/goeasy.js"></script>
<script type="text/javascript">
var goeasy = new GoEasy({
appkey: '你的appkey'
});
goeasy.subscribe({
channel: 'demo',
onMessage: function(message){
alert('Receive:'+message.content);
}
});
</script>

JS接受消息

PHP使用GOEASY实现WEB实时推送