【问题标题】:push notification using ionic and php with clear example使用 ionic 和 php 推送通知,并带有清晰的示例
【发布时间】:2016-12-10 23:26:10
【问题描述】:

我是 ionic 框架的新手。

我需要在我的移动应用程序中使用 ionic 和 google GCM(后端为 PHP)实现推送通知。

我花了很多时间,因此我只会出错。所以,我需要一个清晰的 php 示例。

【问题讨论】:

标签: php ionic-framework


【解决方案1】:

前端见Here

对于后端,请获取您的 API_ACCESS_KEY 并向 GCM 发送 curl 请求。见下面代码

// API_ACCESS_KEY you can get it from your google account 
define( 'API_ACCESS_KEY', 'AIzaSyA_XXXXXXXvXXXXxxxxxxXXXX');
    $msg = array
    (
    'message' => 'YOUR MESSAGE',
    'title' => 'YOUR TITLE',
    'vibrate' => 1,
    'sound' => 1

    // you can also add images, additionalData
    );
     // registration ids are registered device ids
     $registrationIds =['ID1',ID2];
    $fields = array
    (
    'registration_ids' => $registrationIds,
    'data' => $msg
    );
    $headers = array
    (
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
    );
    $ch = curl_init();
    curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
    curl_setopt( $ch,CURLOPT_POST, true );
    curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
    curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
    $result = curl_exec($ch );
    curl_close( $ch );

【讨论】:

  • 我需要更多前端细节...离子前端无法正常工作..设备令牌每秒都在变化
猜你喜欢
  • 2015-08-19
  • 2017-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-27
  • 1970-01-01
相关资源
最近更新 更多