转自网络仅供个人学习之用
后台发送消息时顺便调用这个方法,意思就是拼接一个地址,然后把发送给谁还有发送的内容拼接到这个地址上,用curl模仿浏览器打开这个地址即可
/** * 订单提醒 */ 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发送消息提醒
成功则返回:
前端js代码:
<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接受消息