我正在兜圈子试图弄清楚这一点。让推送通知在 iOS 上工作正常,现在尝试对 android GCM 做同样的事情。我被困在如何公开允许我收集用户注册 ID 的服务上。在我的服务器上使用 java 真的很痛苦,所以只有 php 的解决方案会很有用。到目前为止,我的通知脚本看起来像这样:
require_once('config.php');
require_once 'Zend/Mobile/Push/Gcm.php';
require_once 'Zend/Mobile/Push/Message/Gcm.php';
$con = mysql_connect($CONFIG['db']['host'] , $CONFIG['db']['user'], $CONFIG['db']['pass']);
if (!$con) {
echo "DBConnectionError: Could not connect to database";
}
$db = mysql_select_db($CONFIG['db']['database'], $con);
if (!$db) {
echo "DBSelectError: Could not select database";
}
// optain list of devices to send pn to
$qt = "SELECT uid userid, apntoken "
. "FROM members "
. "WHERE apntoken IS NOT NULL "
. "AND uid IN ("
. "SELECT fuid userid "
. "FROM avail "
. "WHERE apnsent IS NOT TRUE "
. "UNION "
. "SELECT uid userid "
. "FROM availbinary "
. "WHERE apnsent IS NOT TRUE "
. ") ";
//send gcm message
$message = new Zend_Mobile_Push_Message_Gcm();
$message->setId(time());
$message->addToken($tokenRec['apntoken']);
$message->setData($alert);
$gcm = new Zend_Mobile_Push_Gcm();
$gcm->setApiKey('AIzaSyCxxxxxxxxxxxxxxxnFn5mGkM');
try {
$response = $gcm->send($message);
} catch (Zend_Mobile_Push_Exception $e) {
// all other exceptions only require action to be sent or implementation of exponential backoff.
die($e->getMessage());
}
任何想法将不胜感激。