首页 > 解决方案 > 为什么 Onesignal 通知不会导致应用程序打开?

问题描述

我正在使用我的网络应用程序通过 API 在 onesignal 中创建通知。

它工作正常并且正在接收通知,但是当用户单击推送通知时,它不会打开应用程序,只是转到手机主屏幕。

任何人都可以在我的代码中看到错误吗?全部在 PHP 中。

<?PHP
function sendMessage(){
    $content = array(
        "en" => 'testing push message to all active users'
        );

    $fields = array(
        'app_id' => "my app id ",
        'included_segments' => array('Active Users'),
        'data' => array("foo" => "bar"),
        'contents' => $content
    );

    $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 my rest APIkey'));
    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);

    return $response;
}

$response = sendMessage();
$return["allresponses"] = $response;
$return = json_encode( $return);

print("\n\nJSON received:\n");
print($return);
print("\n");  ?>

标签: phpweb-applicationspush-notificationonesignal

解决方案


推荐阅读