39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
"""QR 코드 생성 API"""
|
|
|
|
import io
|
|
import qrcode
|
|
from fastapi import APIRouter, Response
|
|
from app.config import get_settings
|
|
|
|
settings = get_settings()
|
|
router = APIRouter(prefix="/qr", tags=["QR 코드"])
|
|
|
|
|
|
@router.get("/{charge_box_id}")
|
|
async def generate_qr(charge_box_id: str):
|
|
"""충전기용 QR 코드 이미지 생성
|
|
|
|
QR 내용: 충전 시작 페이지 URL (charge_box_id 포함)
|
|
사용자가 스캔하면 모바일 웹 결제 페이지로 이동.
|
|
"""
|
|
# 충전 시작 URL (프론트 배포 후 수정)
|
|
charge_url = f"https://s1.byunc.com/charge/{charge_box_id}"
|
|
|
|
qr = qrcode.QRCode(version=1, box_size=10, border=4)
|
|
qr.add_data(charge_url)
|
|
qr.make(fit=True)
|
|
|
|
img = qr.make_image(fill_color="black", back_color="white")
|
|
|
|
buf = io.BytesIO()
|
|
img.save(buf, format="PNG")
|
|
buf.seek(0)
|
|
|
|
return Response(
|
|
content=buf.getvalue(),
|
|
media_type="image/png",
|
|
headers={
|
|
"Content-Disposition": f'inline; filename="qr_{charge_box_id}.png"'
|
|
},
|
|
)
|