diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 1a18adf..f6f92a7 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -147,7 +147,7 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n $params = array( 'app_id' => $this->appId, 'contents' => $contents, - 'include_player_ids' => is_array($userId) ? $userId : array($userId) + 'include_player_ids' => $this->transformUserId($userId) ); if (isset($url)) { @@ -171,7 +171,7 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n "en" => $headings ); } - + if(isset($subtitle)){ $params['subtitle'] = array( "en" => $subtitle @@ -199,7 +199,7 @@ public function sendNotificationToExternalUser($message, $userId, $url = null, $ $params = array( 'app_id' => $this->appId, 'contents' => $contents, - 'include_external_user_ids' => is_array($userId) ? $userId : array($userId) + 'include_external_user_ids' => $this->transformUserId($userId) ); if (isset($url)) { @@ -264,7 +264,7 @@ public function sendNotificationUsingTags($message, $tags, $url = null, $data = "en" => $headings ); } - + if(isset($subtitle)){ $params['subtitle'] = array( "en" => $subtitle @@ -306,7 +306,7 @@ public function sendNotificationToAll($message, $url = null, $data = null, $butt "en" => $headings ); } - + if(isset($subtitle)){ $params['subtitle'] = array( "en" => $subtitle @@ -348,7 +348,7 @@ public function sendNotificationToSegment($message, $segment, $url = null, $data "en" => $headings ); } - + if(isset($subtitle)){ $params['subtitle'] = array( "en" => $subtitle @@ -415,7 +415,7 @@ public function getNotifications($app_id = null, $limit = null, $offset = null) $this->usesJSON(); $endpoint = self::ENDPOINT_NOTIFICATIONS; - + if(!$app_id) { $app_id = $this->appId; } @@ -531,4 +531,19 @@ public function delete($endPoint) { } return $this->client->delete(self::API_URL . $endPoint, $this->headers); } + + /** + * Transformed user_id as array string. + * + * @param mixed $userId + * @return array + */ + private function transformUserId($userId) + { + $array = is_array($userId) ? $userId : array($userId); + + return array_map(function ($item) { + return (string)$item; + }, $array); + } }