使用Ionic框架作为前端和php作为后端在Android应用程序开发中工作。 有人可以建议你的观点我们如何实现这一点。 我准备好了示例应用程序(按照以下步骤)1。使用以下注释创建示例应用程序
ionic start devdactic-android-push cd devdactic-android-push ionic add ionic-platform-web-client ionic plugin add phonegap-plugin-push ionic io init2.更新了app.js,如下所示$ ionicPlatform.ready(function(){
$ionicPlatform.ready(function() { var push = new Ionic.Push({ "debug": true }); push.register(function(token) { console.log("Device token:",token.token); }); }); });运行以下命令获取设备令牌
离子服务
我可以在cosole中获取设备令牌
我需要获得真正的Android手机的设备令牌,所以准备好apk文件
离子平台添加android离子构建android
在手机中安装生成的apk从控制台获取真实设备的设备令牌(使用chrome检查器检查android app控制台)
在谷歌云平台创建了一个项目,所以我有项目编号(GCM控制台)和设备令牌
project id - 257581368411设备令牌 - DEV-e51b469d-9024-4d88-a0a9-1147f45b13f4
如何使用上述值从PHP脚本发送通知?
以下是我的系统信息:
Cordova CLI: 6.1.1 Ionic Version: 1.2.4 Ionic CLI Version: 1.7.14 Ionic App Lib Version: 0.7.0 OS: Windows 7 SP1 Node Version: v5.0.0working in android app development using Ionic framework as frontend and php as a backend. can someone suggest your points how can we achieve this. am ready with sample app (followed the below steps) 1. created sample app using below comments
ionic start devdactic-android-push cd devdactic-android-push ionic add ionic-platform-web-client ionic plugin add phonegap-plugin-push ionic io init2. updated app.js as below $ionicPlatform.ready(function() {
$ionicPlatform.ready(function() { var push = new Ionic.Push({ "debug": true }); push.register(function(token) { console.log("Device token:",token.token); }); }); });run the below commend to get the device token
Ionic serve
I could get the device token in cosole
I need to get device token of real android phone so prepared the apk file
ionic platform add android ionic build android
Install the generated apk in phonegot the device token of real device from console( used the chrome inspector to check android app console)
created one project in google cloud platform so i have both project number(GCM console) and device token
project id - 257581368411 Device Token - DEV-e51b469d-9024-4d88-a0a9-1147f45b13f4
how to send notification from PHP script using above values?
and below is my system information:
Cordova CLI: 6.1.1 Ionic Version: 1.2.4 Ionic CLI Version: 1.7.14 Ionic App Lib Version: 0.7.0 OS: Windows 7 SP1 Node Version: v5.0.0最满意答案
您可以使用以下脚本发送推送通知
资料来源: https : //gist.github.com/prime31/5675017
// API access key from Google API's Console define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' ); $registrationIds = array( $_GET['id'] ); // prep the bundle $msg = array ( 'message' => 'here is a message. message', 'title' => 'This is a title. title', 'subtitle' => 'This is a subtitle. subtitle', 'tickerText' => 'Ticker text here...Ticker text here...Ticker text here', 'vibrate' =&t; 1, 'sound' => 1, 'largeIcon' => 'large_icon', 'smallIcon' => 'small_icon' ); $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 ); echo $result;You can use the script below to send push notifications
Source: https://gist.github.com/prime31/5675017
// API access key from Google API's Console define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' ); $registrationIds = array( $_GET['id'] ); // prep the bundle $msg = array ( 'message' => 'here is a message. message', 'title' => 'This is a title. title', 'subtitle' => 'This is a subtitle. subtitle', 'tickerText' => 'Ticker text here...Ticker text here...Ticker text here', 'vibrate' => 1, 'sound' => 1, 'largeIcon' => 'large_icon', 'smallIcon' => 'small_icon' ); $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 ); echo $result;更多推荐
发布评论