簡體   English   中英

如何使用 PHP 發送帶有大圖像的信號推送通知

[英]How to send one signal push notification with large image using PHP

代碼僅發送標題和消息,但未收到圖標。 我是一個信號 API 的新手。 這是我的代碼:

<?php 
    $fields = array(
        'app_id' => 'my app id',
        'include_player_ids' => ['player_id'],
        'contents' => array("en" =>"test message"),
        'headings' => array("en"=>"test heading"),
        'largeIcon' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png',
    );
    
    $fields = json_encode($fields);
    //print("\nJSON sent:\n");
    //print($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 M2ZNDYtMjA4ZGM2ZmE5ZGFj'
    ));
    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);
                                           
    $response = curl_exec($ch);
    curl_close($ch);
    print_r($response);
?>

您只需添加:"chrome_web_image" => "image url";

$fields = array(
            'app_id' => 'my app id',
            'include_player_ids' => ['player_id'],
            'contents' => array("en" =>"test message"),
            'headings' => array("en"=>"test heading"),
            'chrome_web_image' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png',
            );

要進一步閱讀,請轉到: onesignal 的文檔外觀

結果: 圖像結果

他們的圖標鍵應該是large_icon而不是largeIcon

檢查API 以獲取更多詳細信息

您可以使用ios_attachments參數,它必須在數組中。

我是這樣做的:

$iCon = array(  
    "ios_attachments" => 'https://Your.Image.png'
);
 
$fields = array(     
    // OneSignal - Personal ID
    'app_id' => "Your_OneSignal_ID",
    'included_segments' => array('All'),'data' => array("foo" => "bar"),
        
    // Submitting Title && Message && iCon
    'headings' => $headings,
    'contents' => $content,
    'ios_attachments' => $iCon,
);
 $fields = array(
        'app_id' => $app_id,
        'headings' => array("en"=>$data['title']),
        'contents' => ["en" => $data['description']] ,
        'big_picture' => $data['file'],
        'large_icon' => $data['file'],
        'url' =>  $data['launch_url']
    );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM