添加华为后Onesignal通知api停止发送

问题描述 投票:0回答:1

我有用于 Onesingal 通知的 php api,当我批准在我的应用程序上发布帖子时,它可以完美地工作,直到我在 Onesingal 仪表板上添加新平台(华为),然后当我尝试从应用程序发送通知时,它确实工作'发送! 我在仪表板中注意到华为需要标题才能发送通知!标题已经在我的 api 上了!但我不明白! 通知图片enter image description here

    <?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);
?>
php api push-notification onesignal huawei-push-notification
1个回答
0
投票

在内容后添加: 'headings' => $content

示例:

 $fields = array(
        'app_id' => "",
        'data' => array("foo" => "bar"),
        'contents' => $content,
        'headings' => $content
    );
© www.soinside.com 2019 - 2024. All rights reserved.