Ejemplo n.º 1
0
 public function testSend()
 {
     $Message = new PayloadMessage();
     $Message->setType(56);
     $Client = new Client();
     try {
         $Client->send($Message);
         $this->fail();
     } catch (GCMFormatException $Ex) {
     }
 }
Ejemplo n.º 2
0
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * GCM message sending example
 * @author alxmsl
 * @date 5/28/13
 */
include '../vendor/autoload.php';
use alxmsl\Google\GCM\Client;
use alxmsl\Google\GCM\Message\PayloadData;
use alxmsl\Google\GCM\Message\PayloadMessage;
// Create new payload class
final class NewPayloadData extends PayloadData
{
    protected function getDataFields()
    {
        return array('test' => 'test_01');
    }
}
// Create payload instance
$Data = new NewPayloadData();
// Create and initialize message instance
$Message = new PayloadMessage();
$Message->setRegistrationIds('DeV1CeT0kEN')->setType(PayloadMessage::TYPE_JSON)->setData($Data);
// Create GCM client
$Client = new Client();
$Client->getRequest()->setConnectTimeout(60);
$Client->setAuthorizationKey('aUTH0R1Z4t1oNKEy');
// ...and send the message
$Response = $Client->send($Message);
var_dump($Response);
Ejemplo n.º 3
0
    $data = json_decode($value, true);
});
$Command->appendParameter(new Option('id', 'i', 'device registration id', Option::TYPE_STRING, true), function ($name, $value) use(&$id) {
    $id = $value;
});
$Command->appendParameter(new Option('key', 'k', 'authorization key', Option::TYPE_STRING, true), function ($name, $value) use(&$key) {
    $key = $value;
});
try {
    $Command->parse(true);
    // Create payload instance
    $Data = new CustomPayloadData($data);
    // Create and initialize message instance
    $Message = new PayloadMessage();
    $Message->setRegistrationIds($id)->setType(PayloadMessage::TYPE_JSON)->setData($Data);
    // Create GCM client
    $Client = new Client();
    $Client->getRequest()->setTimeout(5);
    $Client->getRequest()->setConnectTimeout(60)->setSslVersion(6);
    $Client->setAuthorizationKey($key);
    // ...and send the message
    $Response = $Client->send($Message);
    printf(<<<'EOD'
    success: %s
    failure: %s

EOD
, $Response->getSuccessCount(), $Response->getFailureCount());
} catch (RequiredOptionException $Ex) {
    $Command->displayHelp();
}