Php 使用laravel推送通知向Android发送推送通知
laravel 5的laravel推送通知插件: 在my routes.php中,我有: 路由::get('/test_gcm','TestGCMController@index'); TestGCM控制器:Php 使用laravel推送通知向Android发送推送通知,php,android,laravel,notifications,google-cloud-messaging,Php,Android,Laravel,Notifications,Google Cloud Messaging,laravel 5的laravel推送通知插件: 在my routes.php中,我有: 路由::get('/test_gcm','TestGCMController@index'); TestGCM控制器: namespace App\Http\Controllers; use Illuminate\Http\Request; use Davibennun\LaravelPushNotification\Facades\PushNotification; use App\Http\Requ
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Davibennun\LaravelPushNotification\Facades\PushNotification;
use App\Http\Requests;
class TestGCMController extends Controller
{
public function index()
{
// Change it when device launching sometimes
$deviceToken = "12345";
$return = PushNotification::app('appNameAndroid')
->to($deviceToken)
->send('Hello World, i`m a push message');
var_dump($return);
}
}
所以当我访问site.com/test\u gcm时
var_转储返回:
我不确定这是成功还是失败。图像中没有任何指示
android应用程序来自本教程:,我可以获得GCM令牌,因此该应用程序不工作,但我在emulator中没有收到来自android手机的任何通知。您可以使用以下代码在手机用户上发送推送通知,希望它能帮助您:
function sendPushNotification($fcm_token, $title, $message, $id="") {
$push_notification_key = Config::get('settings.PUSH_NOTIFICATION_KEY');
$url = "https://fcm.googleapis.com/fcm/send";
$header = array("authorization: key=" . $push_notification_key . "",
"content-type: application/json"
);
$postdata = '{
"to" : "' . $fcm_token . '",
"notification" : {
"title":"' . $title . '",
"text" : "' . $message . '"
},
"data" : {
"id" : "'.$id.'",
"title":"' . $title . '",
"description" : "' . $message . '",
"text" : "' . $message . '",
"is_read": 0
}
}';
$ch = curl_init();
$timeout = 120;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
// Get URL content
$result = curl_exec($ch);
// close handle to release resources
curl_close($ch);
return $result;
}
推送通知键应该从哪里来?推送通知键是我们的项目id,请查看我的评论