0

我有用于 Onesingal 通知的 php api,以便在我批准我的应用程序上的帖子时向用户发送通知,它运行良好,直到我在华为 Onesingal Dashboard 上添加新平台,然后当我尝试从应用程序发送通知时它没有发送!我在仪表板中注意到华为需要标题才能发送通知!并且标题已经在我的 api 上!但我想不通!通知图片在此处输入图像描述

    <?php
$title = $_REQUEST["title"];
$sendnotification = $_REQUEST["sendall"];


//here it sends to the post owner that his post is approved

//if ($_SERVER['REQUEST_METHOD'] == 'POST'){

    if($isApproved=="1")
    {
        $ph=$phone;
        $arr =  $mysqli->query("select * from users where phone='$ph'")->fetch_array(MYSQLI_ASSOC);
        $player_id = $arr["token"];
        if(!empty($player_id)) {
            $content = array(
               "en" => "Your post is approved"
            );
              $heading = array(
                "en" => "Your post is approved"
            );

            $fields = array(
                'app_id' => "xxxxxx-xxxxxx-xxxx-xxxx-xxxxxxxxx",
                'include_player_ids' => array($player_id),
                'contents' => $content
            );

            $fields = json_encode($fields);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
                'Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxx'));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            curl_setopt($ch, CURLOPT_HEADER, FALSE);
            curl_setopt($ch, CURLOPT_POST, TRUE);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            $one2 = curl_exec($ch);
            curl_close($ch);

        }

    }
    

// here it sends notification fo all users with the post title

    if ($isApproved=="1"&& $sendnotification=="1")
    {      
              $content = array(
                "en" => $title
            );
              $heading = array(
                "en" => $title
            );
            $fields = array(
                'app_id' => "xxxxxx-xxxxxx-xxxx-xxxx-xxxxxxxxx",
                'included_segments' => array('All'),
                'contents' => $content
            );
            $fields = json_encode($fields);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
                'Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            curl_setopt($ch, CURLOPT_HEADER, FALSE);
            curl_setopt($ch, CURLOPT_POST, TRUE);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            $one2 = curl_exec($ch);
            curl_close($ch);
            echo $one2;
    }
//}
    

echo json_encode($se);
?>
4

0 回答 0