首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何用PHP发送一个大图片的信号推送通知

如何用PHP发送一个大图片的信号推送通知
EN

Stack Overflow用户
提问于 2018-03-14 14:37:37
回答 4查看 6.4K关注 0票数 4

代码只发送标题和消息,但不会收到图标。我是第一次接触signal API。下面是我的代码:

代码语言:javascript
复制
<?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);
?>
EN

Stack Overflow用户

发布于 2018-06-07 23:48:29

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

代码语言:javascript
复制
$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',
            );

要进一步阅读,请访问:doc appearance of onesignal

结果:

票数 2
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49271173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档