嗨,我有Parse错误:语法错误,意外'公共'(T_PUBLIC),第9行

时间:2017-07-31 23:21:18

标签: php android

当我尝试运行此脚本时,我遇到了Parse错误:语法错误,意外的'public'(T_PUBLIC)。

<?php
/*  
Parameter Example
    $data = array('post_id'=>'12345','post_title'=>'A Blog post');
    $target = 'single token id or topic name';
    or
    $target = array('token1','token2','...'); // up to 1000 in one request
*/
public function sendMessage($data,$target){
    //FCM api URL
    $url = 'https://fcm.googleapis.com/fcm/send';
    //api_key available in Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key
    $server_key = AAAABF8gcMk:APA91bFd2Uiq1GZL2VmyqPoqSv_KOyvHNiKTLOGdYxKhTMUzjlhXosrqRPvOzcnxh4Y-BKPyLxjCYQ0dTmQPApIv87uL_sTbrOOenO2wQuAsBQO605UuCX_uL5kKSlCd4hnRibdTm;


    $fields = array();
    $fields['data'] = $data;
    if(is_array($target)){
        $fields['registration_ids'] = $target;
    }else{
        $fields['to'] = $target;
    }
    //header with content_type api key
    $headers = array(
        'Content-Type:application/json',
      'Authorization:key='.$server_key
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('FCM Send Error: ' . curl_error($ch));
    }
    curl_close($ch);
    return $result;
}
$message = array(
          "id"=>$guide->getId(),
          "title"=>$guide->getTitle(),
          "time"=>$view['time']->diff($guide->getCreated()),
        "category"=>$guide->getCategory()?$guide->getCategory()->getTitle(): null,
            "image"=> $this['imagine']->filter($view['assets']->getUrl($guide->getMedia()->getLink()), 'api_img'),
        );
$key=$this->container->getParameter('fire_base_key');
$message_status = send_notification($tokens, $message,$key);
echo $message_status;
header("Location: ".$view['router']->path('app_guides_view',array("id"=>$guide->getId())));
die();

 ?>

0 个答案:

没有答案