【问题标题】:how to send push notification from onesignal the device id's are stored in database - cordova app如何从onesignal发送推送通知,设备ID存储在数据库中-cordova app
【发布时间】:2017-03-16 23:25:03
【问题描述】:

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

对此的任何帮助将不胜感激。谢谢,如果有人有问题理解我的问题可以发表评论,我会尽我所能解释。

【问题讨论】:

    标签: php android ios cordova push-notification


    【解决方案1】:

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

    没有什么魔术可以实现这一点,除了通过某种方式将其保存到您的数据库之外,您在这里没有太多选择。

    【讨论】:

      【解决方案2】:

      您可以使用OneSignal提供的这个功能

      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");
      

      【讨论】:

        猜你喜欢
        • 2017-10-29
        • 2018-11-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-07
        • 2021-07-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多