AcaMate_API/Program/Models/Entities/PushPayload.cs

177 lines
6.5 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Back.Program.Models.Entities
{
/*
* iOS Payload 정의
* aps 딕셔너리 구성
* 1. alert : 실질적으로 사용자에게 노출되는 항목
* 1.1. title : 제목
* 1.2. subtitle : 부제목
* 1.3. body : 본문 내용
* 2. badge : 앱 아이콘에 표시할 숫자
* 3. sound : 소리인데 "default" 가능
* 4. content-available : 백그라운드 업데이트나 사일런트 푸시 송신시 사용한다.
* 1로 설정해 사용자가 직접 보지 않아도 앱이 업데이트 되게 할 수 있으며,
* UI에 알림이 표시되지 않고 데이터만 전달할 때 필요하다.
* 5. mutable-content : 값을 1로 설정해두면 Notification Service Extension을 통해 알림의 내용을 변경할 수 있다.
* 6. category : 사용자 인터렉션 구성시에 사용하는 식별자이다.
* 7. thread-id : 관련 알림들을 그룹화해 관리할 때 사용한다.
*/
/*
* FCM Payload
* https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?hl=ko&_gl=1*3awp3i*_up*MQ..*_ga*MTMyNDk4ODU5MC4xNzQxMTM1MzI3*_ga_CW55HF8NVT*MTc0MTEzNTMyNy4xLjAuMTc0MTEzNTM4My4wLjAuMA..#Notification
* {
"name": string,
"data": { // 입력 전용으로 임의의 가
string: string,
...
},
"notification": {
object (Notification)
},
"android": {
object (AndroidConfig)
},
"webpush": {
object (WebpushConfig)
},
"apns": {
object (ApnsConfig)
},
"fcm_options": {
object (FcmOptions)
},
// Union field target can be only one of the following:
"token": string,
"topic": string,
"condition": string
// End of list of possible types for union field target.
}
* 1. Notification 영역
* 1.1. title: 알림 제목
* 1.2. body: 알림 내용
* 1.3. image: 알림에 표시할 이미지 URL
* 1.4. sound: 알림 재생 시 사용할 사운드
* 1.5. click_action: 알림 클릭 시 실행할 액션(인텐트 액션 문자열)
* 1.6. tag: 동일 태그를 가진 알림끼리 대체 또는 그룹화할 때 사용
* 1.7. color: 알림 아이콘 배경색 (16진수 코드 등)
* 1.8. body_loc_key 및 body_loc_args: 본문에 사용할 지역화 키와 인자 배열
* 1.9. title_loc_key 및 title_loc_args: 제목에 사용할 지역화 키와 인자 배열
* 1.10. channel_id: Android Oreo 이상에서 알림 채널 식별자
* 1.11. ticker, sticky, event_time, notification_priority, visibility, notification_count, light_settings, vibrate_timings 등: 사용자 경험이나 알림의 동작 방식을 세밀하게 제어할 때 사용
* 2. Data 영역 : 임의의 키-값 쌍을 포함하고 UI에 표시되는 내용이 아닌 앱의 로직에 활용할 데이터를 보낼 때 사용한다.
* 3. 기타 전송 옵션
* 3.1. priority: 메시지 전송 우선순위 (“high” 또는 “normal”)
* 3.2. time_to_live (ttl): 메시지 유효 시간(초 단위)
* 3.3. collapse_key: 동일 collapse_key를 가진 메시지는 최신 하나로 교체됨
* 3.4. restricted_package_name: 메시지를 수신할 앱의 패키지 이름 (Android 전용)
*/
[Table("payload")]
public class DBPayload
{
public string bid { get; set; }
public string pid { get; set; }
public string title {get; set;}
public string? subtitle {get; set;}
public string body {get; set;}
public bool alert_yn {get; set;}
public string category {get; set;}
public string? content {get; set;}
}
[Table("push_cabinet")]
public class PushCabinet
{
[Key]
public int id { get; set; }
public string uid { get; set; }
public string pid { get; set; }
public string bid { get; set; }
public DateTime send_date { get; set; }
public bool check_yn { get; set; }
public string? content {get; set;}
}
public class PushRequest
{
public string bid { get; set; }
public List<string> uids { get; set; }
public string pid { get; set; }
public string? content { get; set; }
}
public class Payload
{
public Aps aps { get; set; }
public string pid { get; set; }
public string bid { get; set; }
public string content { get; set; }
// public string customKey { get; set; } 이런식으로 추가도 가능
public string ToJson()
{
return System.Text.Json.JsonSerializer.Serialize(this);
}
}
public class Aps
{
public Aps()
{
sound = "default";
content_available = 1;
}
[Required(ErrorMessage = "필수 입력 누락 (alert)")]
public Alert alert { get; set; }
[Required(ErrorMessage = "필수 입력 누락 (badge")]
public int badge { get; set; } // 앱 아이콘 표시 배지 숫자 설정
public string sound { get; set; } // 사운드 파일 이름 default = "default"
public int content_available { get; set; } // 백그라운드 알림 활성화: 필수 (1)
public string? category { get; set; } // 알림에 대한 특정 액션을 정의
}
public class Alert
{
[Required(ErrorMessage = "필수 입력 누락 (title")]
public string title { get; set; } // 제목
[Required(ErrorMessage = "필수 입력 누락 (body)")]
public string body { get; set; } // 내용
public string? subtitle { get; set; } // 부제목 (선택)
}
/// <summary>
/// 푸시 등록하기 위한 apns 여러 데이터 목록
/// </summary>
public class PushFileSetting
{
public string uri { get; set; }
public string p12Path { get; set; }
public string p12PWPath { get; set; }
public string apnsTopic { get; set; }
}
public class PushData
{
public string pushToken { get; set; }
public Payload payload { get; set; }
}
public class CreatePush
{
public string bid { get; set; }
public string title { get; set; }
public string? subtitle { get; set; }
public string body { get; set; }
public bool alert_yn { get; set; } = true;
public string category { get; set; }
public string? content { get; set; }
}
}