本文整理汇总了PHP中GCM::get方法的典型用法代码示例。如果您正苦于以下问题:PHP GCM::get方法的具体用法?PHP GCM::get怎么用?PHP GCM::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GCM
的用法示例。
在下文中一共展示了GCM::get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendNotification
public function sendNotification($message_id, $message, $users)
{
$this->init();
try {
foreach ($users as $user) {
$user_id = $user->id;
$registatoin_ids = array($user->gcm_regid);
$json = GCM::get()->send_notification($registatoin_ids, $message);
if (!$json) {
return -400;
//Curl failed
}
$ret = json_decode($json, true);
if ($ret['success']) {
$state = 1;
//success
$this->success_count++;
$state_text = $ret['results'][0]['message_id'];
} elseif ($ret['failure']) {
$state = 2;
//failed
$this->fail_count++;
$state_text = $ret['results'][0]['error'];
} else {
$state = 2;
//failed
$this->fail_count++;
$state_text = strpos($json, 'Unauthorized') ? 'Unauthorized API key' : 'Undefined';
}
// $state_text = isset($ret['results'][0]['error']) ? $ret['results'][0]['error'] : $ret['results'][0]['message_id'];
$message_state = new MessageState();
$message_state->message_id = $message_id;
$message_state->user_id = $user_id;
$message_state->state = $state;
$message_state->state_text = $state_text;
$message_state->save();
}
return 101;
} catch (Exception $e) {
return -100;
}
}