在我的Web应用程序中添加onesignal推送

时间:2019-01-07 12:19:47

标签: rest onesignal

我正在为android应用程序设置一个新的管理面板来管理内容。此应用程序正在使用一个信号推送通知。现在我想添加一个简单的表单(标题,消息和发送按钮)以将通知从我的Web应用程序直接发送到android应用程序。只是发送通知。

我尝试了很多代码,其中大多数都很复杂。我希望它对雇员使用非常简单,因为我不希望他通过一个信号网站从那里发送通知。 this is what i want

下面的代码有一些问题: 1-没有仅标题字段的消息(尝试添加,但无法) 2-没有图标和图像字段可在其上上传。 3次,我打开one.php(脚本页面),它向我显示此错误: 注意:未定义的索引:第12行的C:\ xamp \ htdocs \ onesignal \ one.php中的mytext 邮件已发送。

`

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<form action="one.php" method="post">
   <p>Your Message: <input type="text" name="mytext" /></p>

  <input type="submit" value="send" />
</form>
<?php
    $mytext = "";
    function sendMessage(){
        $content = array(
            "en" => $_POST['mytext']


        );
    $fields = array(
      'app_id' => "4cfb3aXXXXXXXXXXXXXXXXX",
      'included_segments' => array('All'),
      'data' => array("foo" => "bar"),
      'contents' => $content
    );

    $fields = json_encode($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',
                           'Authorization: Basic YmIzZmIzY2YtYTRXXXXXXXXXXXXX'));
    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("\nmessage sent");
?> 

我希望表单是带有发送按钮(发送)的文本字段和消息字段,此按钮具有将标题和消息发送给注册用户并与onesignal集成的功能。

0 个答案:

没有答案