Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 리눅스
- MS-SQL
- pandas
- IOS
- PER
- PyQt
- GIT
- 맛집
- MySQL
- port
- Excel
- 유니티
- sqlite
- PyQt5
- Linux
- 날짜
- swift
- node.js
- tensorflow
- Unity
- 함수
- javascript
- python
- 다이어트
- mssql
- ASP
- flutter
- ubuntu
- urllib
- 라즈베리파이
Archives
아미(아름다운미소)
HTTP v1 API를 사용하여 푸시 알림을 전송하는 샘플 코드 본문
pip install firebase-admin
import firebase_admin
from firebase_admin import credentials
from firebase_admin import messaging
# Firebase Admin SDK 초기화
cred = credentials.Certificate('./path/to/your/serviceAccountKey.json')
firebase_admin.initialize_app(cred)
def send_fcm_messages(device_tokens, title, body, image_url, company_name):
# 푸시 알림 메시지 생성
message = messaging.MulticastMessage(
notification=messaging.Notification(
title=title,
body=body
),
data={
'image': image_url, # 이미지 URL
'click_action': 'FLUTTER_NOTIFICATION_CLICK', # 클릭 시 동작 정의
'companyName': company_name # 회사명 추가
},
tokens=device_tokens, # 여러 개의 토큰을 리스트로 전달
)
# 메시지 전송
try:
response = messaging.send_multicast(message)
print('Successfully sent messages:', response)
except Exception as e:
print('Error sending messages:', e)
# 예제 사용
if __name__ == "__main__":
device_tokens = ['TOKEN_1', 'TOKEN_2', 'TOKEN_3'] # 실제 장치 토큰 리스트로 대체
image_url = 'https://example.com/path/to/your/image.jpg' # 실제 이미지 URL로 대체
company_name = '회사명' # 실제 회사명으로 대체
send_fcm_messages(device_tokens, "안녕하세요", "FCM HTTP v1 푸시 알림 테스트입니다.", image_url, company_name)'랭귀지 > python' 카테고리의 다른 글
| FCMNotifier class (0) | 2024.09.12 |
|---|---|
| HTTP v1 API를 사용하여 db연동 푸시 알림을 전송하는 샘플 코드 (1) | 2024.09.12 |
| 미체결 날짜형식을 현재시간과 비교해서 1분 경과시 주문취소 (0) | 2024.08.25 |
| flask restapi mysql 예제 (0) | 2024.06.22 |
| python mysql dbhelper (0) | 2024.06.22 |
Comments