Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Feat: 대기등록, 운영 종료 문자 추가 #96

Merged
merged 2 commits into from
Oct 6, 2024

Conversation

jiyoon607
Copy link
Contributor

@jiyoon607 jiyoon607 commented Oct 6, 2024

🔥 Pull requests

👷 작업한 내용

대기등록, 운영 종료 문자 발송 추가하였습니다.
3분 10분 레디스 사용하는 부분만 테스트를 못해봤습니다.
확인 부탁드립니다.

🚨 참고 사항

문자 발송 부분 주석처리 풀었기 때문에 올바른 데이터 들어가면 이제 바로 문자 발송됩니다.

📸 스크린샷

🖥️ 주요 코드 설명

  • 쏼라쏼라
from rest_framework import status
from utils.responses import custom_response
from django.conf import settings
import requests, re

SSODAA_BASE_URL = settings.SSODAA_BASE_URL
SEND_PHONE = settings.SEND_PHONE

# 문자 발송하기
def sendsms(dest_phone, msg_body):
    # 데이터 형식 검증
    phone_pattern = re.compile(r'^\d{10,11}$')  # 10자리 또는 11자리 숫자만
    if not phone_pattern.match(dest_phone):
        return {
            "message": "Invalid destination phone number.",
        }

    if not isinstance(msg_body, str):
        return {
            "message": "Invalid message content.",
        }
    

    headers = {
        'x-api-key': settings.SMS_API_KEY,
        'Content-Type': 'application/json; charset=utf-8'
    }

    data = {
        "token_key": settings.SMS_TOKEN_KEY,
        "msg_type": 'sms',
        "dest_phone": dest_phone,
        "send_phone": SEND_PHONE,
        "msg_body": msg_body,
    }
    
    try:
        url = f"{SSODAA_BASE_URL}/sms/send/sms"
        response = requests.post(url, json=data, headers=headers)
        response = response.json()
        status_code = int(response.get('code'))
        print(response)
        if status_code == 200:
            content = response.get('content')
            data = {
                "sent_messages":content.get('sent_messages'),
                "send_phone":content.get('send_phone'),
            }
            return custom_response(data=data, message=content.get('message'), code=status.HTTP_200_OK)
        
        else:
            error = response.get('error')
            return custom_response(message=error, code=status.HTTP_403_FORBIDDEN, success=False)

    except requests.exceptions.RequestException:
        return custom_response(message="Failed to send messages.", code=status.HTTP_400_BAD_REQUEST, success=False)

✅ Check List

  • Merge 대상 브랜치가 올바른가?
  • 최종 코드가 에러 없이 잘 동작하는가?

📟 관련 이슈

  • Resolved: #이슈번호

Copy link
Contributor

@JongbeomLee623 JongbeomLee623 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다

@JongbeomLee623 JongbeomLee623 merged commit 1188da4 into LINE-NOW:main Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants