APA91bFY
628a3f4a28bb994bb7c9a4143950d240c6d5a1dab8621e9ed61a2109a074f832
function fnSendAndroid($tokens, $text, $config) { $sender = new CodeMonkeysRu\GCM\Sender($config['androidTokenAuth']); $message = new CodeMonkeysRu\GCM\Message($tokens, array("message" => $text)); try { $response = $sender->send($message); if ($response->getFailureCount() > 0) { $invalidRegistrationIds = $response->getInvalidRegistrationIds(); foreach($invalidRegistrationIds as $invalidRegistrationId) { //Remove $invalidRegistrationId from DB // APS91bFY-2CYrriS-Dt6y9_dGHhkPVwy7njqFpfgpzGYlDT4l0SQeqKr-lc1OM0a2DQ33S3EKwy2YJn-upKxOT6rNwgk350xUM3g8VX65rkGocOQX80Ta34pwXo6fyn-usoaGUAm4lzsqbCL-gkzHZZXRX39kUQfnA fnDeleteToken($invalidRegistrationId); } } if ($response->getSuccessCount()) { echo ' ' . $response->getSuccessCount() . ' '; } } catch (CodeMonkeysRu\GCM\Exception $e) { switch ($e->getCode()) { case CodeMonkeysRu\GCM\Exception::ILLEGAL_API_KEY: case CodeMonkeysRu\GCM\Exception::AUTHENTICATION_ERROR: case CodeMonkeysRu\GCM\Exception::MALFORMED_REQUEST: case CodeMonkeysRu\GCM\Exception::UNKNOWN_ERROR: case CodeMonkeysRu\GCM\Exception::MALFORMED_RESPONSE: fnLog(' ' . $e->getCode() . ' ' . $e->getMessage()); break; } } }
function feedback($config) { $feedback = new ApnsPHP_Feedback( ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION, $config['apn']['sert'] ); $feedback->setProviderCertificatePassphrase($config['apn']['passphrase']); $feedback->setRootCertificationAuthority($config['apn']['RootCertificat']); $feedback->connect(); $aDeviceTokens = $feedback->receive(); if (!empty($aDeviceTokens)) { foreach ($aDeviceTokens as $DeviceToken) { /** * * [timestamp] => 1406040206 * [tokenLength] => 32 * [deviceToken] => 738d005a11bca268e2f1bffbfed88a456e261020b9277883cde14d9c8f47cde0 */ //'DELETE LOW_PRIORITY FROM tokens WHERE token=:token'; fnLog('Feedback - ' . $DeviceToken[deviceToken]); } } $feedback->disconnect(); }
function fnSendIos($tokens, $text, $config) { $push = new ApnsPHP_Push( ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION, $config['apn']['sert']); // Set the Provider Certificate passphrase $push->setProviderCertificatePassphrase($config['apn']['passphrase']); $push->setRootCertificationAuthority($config['apn']['RootCertificat']); $message = new ApnsPHP_Message(); $listTokens = array(); foreach ($tokens as $token) { $message->addRecipient($token); $listTokens[] = $token; } $push->connect(); $message->setText($text); $push->add($message); $push->send(); $push->disconnect(); $aErrorQueue = $push->getErrors(); if (!empty($aErrorQueue)) { fnLog(' ios - ' . print_r($aErrorQueue, true)); if (is_array($aErrorQueue)) { foreach($aErrorQueue as $error) { if (isset($error['ERRORS']) && is_array($error['ERRORS'])) { foreach ($error['ERRORS'] as $m) { if (isset($m['statusMessage']) && $m['statusMessage'] == 'Invalid token') { $arrayID = $m['identifier'] - 1; if (isset($listTokens[$arrayID])) { //DELETE LOW_PRIORITY FROM tokens WHERE token=:token' fnLog(' ' . $listTokens[$arrayID]); } } } } } } } }
Source: https://habr.com/ru/post/231727/
All Articles