- FCM 토큰 관리 페이지 (목록, 활성화/비활성화, 삭제) - 테스트 발송 페이지 (대상 필터, 미리보기, 발송) - 발송 이력 페이지 (필터링, 결과 확인) - FcmSender 서비스 (HTTP v1, 배치 처리) - fcm_send_logs 테이블 마이그레이션 - google/auth 패키지 추가
113 lines
2.2 KiB
PHP
113 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Fcm;
|
|
|
|
class FcmBatchResult
|
|
{
|
|
/** @var array<string, FcmResponse> */
|
|
private array $responses = [];
|
|
|
|
private int $successCount = 0;
|
|
|
|
private int $failureCount = 0;
|
|
|
|
/** @var array<string> 무효 토큰 목록 */
|
|
private array $invalidTokens = [];
|
|
|
|
/**
|
|
* 응답 추가
|
|
*/
|
|
public function addResponse(string $token, FcmResponse $response): void
|
|
{
|
|
$this->responses[$token] = $response;
|
|
|
|
if ($response->success) {
|
|
$this->successCount++;
|
|
} else {
|
|
$this->failureCount++;
|
|
|
|
if ($response->isInvalidToken()) {
|
|
$this->invalidTokens[] = $token;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 전체 발송 수
|
|
*/
|
|
public function getTotal(): int
|
|
{
|
|
return count($this->responses);
|
|
}
|
|
|
|
/**
|
|
* 성공 수
|
|
*/
|
|
public function getSuccessCount(): int
|
|
{
|
|
return $this->successCount;
|
|
}
|
|
|
|
/**
|
|
* 실패 수
|
|
*/
|
|
public function getFailureCount(): int
|
|
{
|
|
return $this->failureCount;
|
|
}
|
|
|
|
/**
|
|
* 무효 토큰 목록 (비활성화 필요)
|
|
*
|
|
* @return array<string>
|
|
*/
|
|
public function getInvalidTokens(): array
|
|
{
|
|
return $this->invalidTokens;
|
|
}
|
|
|
|
/**
|
|
* 모든 응답
|
|
*
|
|
* @return array<string, FcmResponse>
|
|
*/
|
|
public function getResponses(): array
|
|
{
|
|
return $this->responses;
|
|
}
|
|
|
|
/**
|
|
* 특정 토큰의 응답
|
|
*/
|
|
public function getResponse(string $token): ?FcmResponse
|
|
{
|
|
return $this->responses[$token] ?? null;
|
|
}
|
|
|
|
/**
|
|
* 성공률 (%)
|
|
*/
|
|
public function getSuccessRate(): float
|
|
{
|
|
if ($this->getTotal() === 0) {
|
|
return 0.0;
|
|
}
|
|
|
|
return round(($this->successCount / $this->getTotal()) * 100, 2);
|
|
}
|
|
|
|
/**
|
|
* 요약 정보
|
|
*/
|
|
public function toSummary(): array
|
|
{
|
|
return [
|
|
'total' => $this->getTotal(),
|
|
'success' => $this->successCount,
|
|
'failure' => $this->failureCount,
|
|
'invalid_tokens' => count($this->invalidTokens),
|
|
'success_rate' => $this->getSuccessRate(),
|
|
];
|
|
}
|
|
}
|