PHP文件给出空值

时间:2018-06-29 04:32:41

标签: php firebase sqlsrv

创建一个PHP文件Announcement.php。在此文件中,从查询中获取数据,并将此数据设置为Push.php。数据填充到Firebase.php并显示结果数据并发送到firebse后,将通知推送到Android。

结果:

Request:
{"data":{"title":null,"message":null,"announce":null,"clickevent":null,"timestamp":"2018-06-29 4:21:40"}}

Response:
"{\"multicast_id\":9114195360294387726,\"success\":0,\"failure\":1,\"canonical_ids\":0,\"results\":[{\"error\":\"NotRegistered\"}]}"

在Request中,所有键值均为Null。在announcement.php中,提取数据未设置为Push.php中的push类。为什么我不知道该数据值未发送到push类?

Announcement.php

<?php
error_reporting( E_ALL ); 
ini_set('display_errors', 1);
require_once __DIR__ . '/firebase.php';
        require_once __DIR__ . '/push.php';

        $firebase = new Firebase();
        $push = new Push();


     $json = '';
     $response = '';

if($_SERVER['REQUEST_METHOD']=='GET'){
    // $full_name = $_POST['full_name'];
    // $contact_number = $_POST['contact_number'];



    $reg = $_GET['reg'];
    $fdate = $_GET['fdate'];
    $tdate = date('Y-m-d G:i:s');
    //$tdate = date("2018-01-20");

    print_r($tdate);

    $date2 = strtotime("+1 day", strtotime($fdate));
    $fdate1 =  date("Y-m-d", $date2);

    //print_r($fdate1);

     require_once('Demo.php');


    $sql = "select max(AnnounceDate) as  announcedate from AnnouncementTable";

    $stmt1 = sqlsrv_query($conn,$sql);  
    $result = array(); 

    $result["announcement"] = array();

    $result["success"] = 1;

    $row = sqlsrv_fetch_array($stmt1,SQLSRV_FETCH_ASSOC);

    $date1 = $row["announcedate"]->format('Y-m-d');
    $marks = array();

    $marks["announcedate"] = $row["announcedate"]->format('Y-m-d');

    array_push($result["announcement"], $marks);


    echo json_encode($result);

    print_r($date1);


    if ($date1 != $fdate){

  echo  $check = "select * from
                        AnnouncementTable 
                        where  
                        AnnounceDate between '$fdate1' and '$tdate'";

    $check1 = "select token from Std_Reg where RegNo='$reg'";

         $stmt = sqlsrv_query($conn,$check);

          $stmt1 = sqlsrv_query($conn,$check1);

        if(sqlsrv_has_rows($stmt) > 0){


         while ($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC)){



                     $notiTitle = "Eurasian Infotech";
                     $clickEvent ="Announcement";
                     $notiMessage = $row["Title"];
                     $notiDescription = $row["Description"];
                     $notiDate = $row["CreationDate"];



                     $push->setTitle($notiTitle);
                     $push->setMessage($notiMessage);
                     $push->setClickevent($clickEvent);
                     $push->setAnnounce($notiDescription);
                     $push->setDate($notiDate);




                        //sendNotification($notiTitle, $notiMessage,$reg,$date1); 
            echo "sucessfully added";
                 }
                        $row = sqlsrv_fetch_array($stmt1,SQLSRV_FETCH_ASSOC);

                         $regId = $row['token'];

                         $json = $push->getPush();
                         $response = $firebase->send($regId,$json);


            }else{
            echo "error in sending request";
            }
        }else{
            echo "Sent Notification";
            }

    }else{
    echo 'error';
}



?>

 <div class="container">
            <div class="fl_window">

                <br/>
                <?php if ($json != '') { ?>
                    <label><b>Request:</b></label>
                    <div class="json_preview">
                        <pre><?php echo json_encode($json) ?></pre>
                    </div>
                <?php } ?>
                <br/>
                <?php if ($response != '') { ?>
                    <label><b>Response:</b></label>
                    <div class="json_preview">
                        <pre><?php echo json_encode($response) ?></pre>
                    </div>
                <?php } ?>

            </div>

push.php

<?php

class Push{


    private $title;
    private $message;
    //private $date;
    private $announce;
    private $clickevent;

    function _construct(){

    }


    public function setTitle($title){

    }

    public function setMessage($message){

    }

    //public function setDate($date){

    //}

    public function setAnnounce($announce){

    }

    public function setClickevent($clickevent){

    }

    public function getPush(){

        $res = array();
        $res['data']['title'] = $this->title;
        $res['data']['message'] = $this->message;
//      $res['data']['date'] = $this->date('Y-m-d');
        $res['data']['announce'] = $this->announce;
        $res['data']['clickevent'] = $this->clickevent;
        $res['data']['timestamp'] = date('Y-m-d G:i:s');
        return $res;
    }
}


?>

0 个答案:

没有答案