如何从一个信号发送推送通知,设备id's存储在数据库- cordova应用程序


how to send push notification from onesignal the device id's are stored in database - cordova app

我在我的cordova应用程序中使用来自onessignal平台的推送通知。我已经实现了从onessignal仪表板发送推送通知,但我想从我自己的搜索发送通知,当用户安装应用程序时,我已经存储了设备id,但不知道如何将通知发送到id存储在我的数据库中的设备

关于这方面的任何帮助将不胜感激。谢谢,如果有人有问题理解我的问题可以评论,我会尽我最大的能力解释。

为了处理这种情况,我也使用一个信号,但在我的应用程序启动时,我将我的id发送到我的后端,以确保当我需要它时它将被注册到我的db。只是一个经典的http post请求。

没有什么神奇的技巧可以做到这一点,你没有太多的选择,除了以某种方式将它保存到你的数据库。

您可以使用onessignal

提供的这个函数。
function sendMessage(){
    $content = array(
        "en" => 'YOUR_CUSTOM_MESSAGE'
        );
    $fields = array(
        'app_id' => "YOUR_APP_ID",
        'include_player_ids' => array("YOUR_TARGET_ID"),
        '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 NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj'));
    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");