Ejemplo n.º 1
0
<?php

include "pusher.php";
$push = new Pusher();
$push->set_ios('Password', 'path/to/cert.pem');
$push->set_ios_devices('deviceToken');
$push->set_android("apitoken");
$push->set_android_devices("deviceToken");
$push->set_message("Notification with custom data");
$push->set_title("Custom data");
$push->set_number(1);
$push->set_sound("default");
$push->set_custom('{"x":157,"y":100}');
$push->push();
print_r($push->get_errors());
 public function newNoti()
 {
     //获取客户端发送的json
     $arr = json_decode($GLOBALS['HTTP_RAW_POST_DATA']);
     $uid = 111;
     //用户名为学号,也是数据库中的ID
     //$id=$arr->id;//文章ID号(为14位年月日时分秒)
     $title = "123";
     //$arr->title;//$arr->noti->title;//文章标题
     //$uid=$arr->username;//创建该文章的用户ID
     // $date=$arr->date;//创建文章的年月日时分秒
     //$tid=$arr->tid;//
     $bodyofhtml = "<p>111</p>";
     //$arr->content;//$arr->noti->content;//文章的内容(保存为html)
     $grade = "研一;研二;研三";
     //$arr->noti->viewlevel;//可查看该文章的年级
     //对时间进行处理;
     // $datetime= date("YmdHis",strtotime($date));//获取当前时间
     $datesql = date("Y-m-d", strtotime('now'));
     //
     $Model = new Model();
     //从数据库中获取一个整数型的uuid,并设置为文章的ID号
     $sql = "select uuid_short();";
     $res = $Model->query($sql);
     $id = $res[0]['uuid_short()'];
     $sql = "insert into __PREFIX__article(id,title,uid,date,body,grade)\r\n        values ({$id},'{$title}',{$uid},'{$datesql}','{$bodyofhtml}','{$grade}')";
     if ($Model->execute($sql)) {
         $suc = 1;
     } else {
         $suc = 0;
     }
     $datesql = date("Y-m-d", strtotime($datesql));
     $jsonsend = array("title" => $title, "date" => $datesql, "jwt" => $json->jwt);
     $json = json_encode($jsonsend);
     //向数据库中增加表
     $this::insertNotiuser($id);
     $config = array('from' => '123', 'to' => '', 'content' => $title, 'viewlevel' => '1', 'action' => '1');
     vendor("messagePush-master.Pusher");
     vendor("messagePush-master.MessageBuilder");
     $result = \Pusher::push((new \MessageBuilder($config))->build());
 }