【发布时间】:2016-03-15 14:31:48
【问题描述】:
我使用 PHP 向我的客户发送通知。这是我的 PHP 代码
<?php
define( 'API_ACCESS_KEY', 'AIzaSyAYq7KpB5J7x3p3zYyna...' );
$registrationId = array( $_GET['id'] );
$msg = array
(
'message' => 'here is a message. message',
'title' => 'This is a title. title',
'subtitle' => 'This is a subtitle. subtitle'
);
$fields = array
(
'registration_ids' => $registrationId,
'notification' => $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;
当我使用我的注册 ID 执行脚本时,会有这样的通知,Notification
标题是 推送消息 身体是 讯息
如您所见,通知标题和消息正文不等于地雷。我该如何解决这个问题? 谢谢。
【问题讨论】:
标签: php curl push-notification google-cloud-messaging