发布于 2014-03-04 18:32:14
找到了一种非常简单的方法来做到这一点。
将下面的php脚本粘贴到框中。在php脚本set API_ACCESS_KEY中,设置用coma分隔的设备ids。
按F9键或单击Run。
玩得开心;)
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );
$registrationIds = array("YOUR DEVICE IDS WILL GO HERE" );
// 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
);
$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;
?>
对于FCM,google url是:https://fcm.googleapis.com/fcm/send
对于FCM v1,谷歌url为:https://fcm.googleapis.com/v1/projects/YOUR_GOOGLE_CONSOLE_PROJECT_ID/messages:send
注意:在google开发者控制台创建API访问密钥时,ip地址必须使用0.0.0.0/0。(用于测试目的)。
如果收到来自GCM服务器的无效注册响应,请交叉检查您的设备令牌的有效性。您可以使用以下url检查设备令牌的有效性:
https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=YOUR_DEVICE_TOKEN
一些响应码:
以下是服务端可能收到的一些响应码的说明。
{ "message_id": "XXXX" } - success
{ "message_id": "XXXX", "registration_id": "XXXX" } - success, device registration id has been changed mainly due to app re-install
{ "error": "Unavailable" } - Server not available, resend the message
{ "error": "InvalidRegistration" } - Invalid device registration Id
{ "error": "NotRegistered"} - Application was uninstalled from the device
发布于 2015-06-11 18:46:07
POSTMAN : google chrome扩展
使用邮递员代替服务器发送消息。邮递员设置如下:
Request Type: POST
URL: https://android.googleapis.com/gcm/send
Header
Authorization : key=your key //Google API KEY
Content-Type : application/json
JSON (raw) :
{
"registration_ids":["yours"],
"data": {
"Hello" : "World"
}
}
在成功的时候,你会得到
Response :
{
"multicast_id": 6506103988515583000,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1432811719975865%54f79db3f9fd7ecd"
}
]
}
发布于 2016-03-08 23:07:42
Pushwatch是一个免费的在线GCM和APNS推送通知测试器,这是我自己用Django/Python开发的,因为我发现自己在多个项目中也遇到了类似的情况。它可以发送GCM
和APNS
通知,还支持额外参数的JSON消息。以下是指向测试人员的链接。
如果您在使用它时有任何问题或遇到问题,请让我知道。
https://stackoverflow.com/questions/22168819
复制相似问题