gpt4 book ai didi

php - 如何使用 GCM 在 android 中将大小图像作为推送通知发送

转载 作者:搜寻专家 更新时间:2023-11-01 08:35:11 24 4
gpt4 key购买 nike

我已经编写了一个 php 代码来使用 GCM 服务器向 android 移动设备发送推送通知。它工作正常。现在我想发送大小图像作为推送通知。我该怎么做 这是我的代码。

<?php
// 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' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png',
'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;
?>

最佳答案

我建议您使用 OneSignal

我正在使用这个,你会从中得到更多,你的大图和小图问题可以从这里解决,而且完全免费。希望对你有帮助

关于php - 如何使用 GCM 在 android 中将大小图像作为推送通知发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37314042/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com