FCM 요청 스키마 수정 및 배열 선언 가독성 개선

This commit is contained in:
Kijin Sung 2020-06-21 16:46:07 +09:00
parent df76fa45c5
commit f9521d4d93
2 changed files with 15 additions and 6 deletions

View file

@ -53,7 +53,10 @@ class FCM extends Base implements \Rhymix\Framework\Drivers\PushInterface
$url = 'https://fcm.googleapis.com/fcm/send';
$api_key = $this->_config['api_key'];
$headers = array('Authorization:key='.$api_key,'Content-Type: application/json');
$headers = array(
'Authorization' => 'key=' . $api_key,
'Content-Type' => 'application/json',
);
// Set notification
$notification = [];
@ -67,11 +70,17 @@ class FCM extends Base implements \Rhymix\Framework\Drivers\PushInterface
// Set android options
$options = [];
$options['priority'] = 'normal';
$options['notification']['click_action'] = 'RX_NOTIFICATION';
$options['click_action'] = 'RX_NOTIFICATION';
foreach($tokens as $i => $token)
{
$data = array('registration_ids' => $token, 'notification' => $notification, 'android' => $options, 'data' => $message->getData());
$data = json_encode(array(
'registration_ids' => [$token],
'notification' => $notification,
'android' => $options ?: new stdClass,
'data' => $message->getData() ?: new stdClass,
));
$result = \FileHandler::getRemoteResource($url, $data, 5, 'POST', 'application/json', $headers);
if($result)
{

View file

@ -125,9 +125,9 @@ class Push
*
* @return int|null
*/
public function getFrom(): ?int
public function getFrom(): int
{
return $this->from;
return intval($this->from);
}
/**
@ -339,7 +339,7 @@ class Push
foreach($output->data as $row)
{
$result[$row->device_type] = $row->device_token;
$result[$row->device_type][] = $row->device_token;
}
return $result;