【问题标题】:OneSignal notification to a specific user using Cordova使用 Cordova 向特定用户发送 OneSignal 通知
【发布时间】:2017-07-09 19:00:08
【问题描述】:

我无法通过 PHP 中的 REST API 向特定用户发送通知。 我从 OneSignal 中的所有用户那里获取 Player ID 的值。

PHP 代码

<?php 

$content = array(
"en" => "messaggio test"
);

$fields = array(
'app_id' => "xxxxxxxx",
'included_segments' =>  array("All"),
'data' => array("foo" => "bar"),
'filters' => array(array('field' => 'tag', 'key' => 
'userId', 'relation' => '=', 'value' => 'xxxxxxxxxxx')),
'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 xxxxxxxxxxxxxxx'));
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);
?>

javascript 代码

    window.plugins.OneSignal
    .startInit("xxxxxxxxxxx")
    .handleNotificationOpened(notificationOpenedCallback)
    .endInit();

    window.plugins.OneSignal.setSubscription(true);

此代码可以很好地向所有设备发送通知,但不能向单个用户发送通知。

【问题讨论】:

    标签: javascript cordova onesignal


    【解决方案1】:

    window.plugins.OneSignal.getIds(function(ids) {
        var device_id = ids.userId;
    });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多