SMS 전송하기 - Tirrilee/TechTalk GitHub Wiki

문자 발송 서비스

가이드

DJANGO SMS 송수신 [가이드 본문]

문자 서비스는 선생님이 소개해주신 사이트의 SDK를 통해 구현하였다. coolsms라는 서비스로, 지인들에게 구한 좋은 사이트라고 한다.

이곳의 sdk는 UX적으로는 불편하게 찾아가야 했지만 사용법은 매우 간단했는데 나도 가져다가 바로 쓸 수 있었다. 선생님이 충전해주신 계정을 통해 메시지를 보낼 수 있었다.

from sdk.api.message import Message
from sdk.exceptions import CoolsmsException

##  @brief This sample code demonstrate how to send sms through CoolSMS Rest API PHP

def send_sms(number, message):
    # set api key, api secret
    api_key = "NCS5805501D*****"
    api_secret = "A86DF83FB2F77AC52F0322A8B1B*****"

    params = dict()
    params['type'] = 'sms' # Message type ( sms, lms, mms, ata )
    params['from'] = '01029953874' # Sender number
    params['text'] = str(message) # Message

    if isinstance(number, (list, tuple)):
        number = ','.join(number)

    params['to'] = str(number)  # Recipients Number '01000000000,01000000001'

    cool = Message(api_key, api_secret)
    try:
        response = cool.send(params)
        print("Success Count : %s" % response['success_count'])
        print("Error Count : %s" % response['error_count'])
        print("Group ID : %s" % response['group_id'])

        if "error_list" in response:
            print("Error List : %s" % response['error_list'])

    except CoolsmsException as e:
        print("Error Code : %s" % e.code)
        print("Error Message : %s" % e.msg)

해당 SDK는 pip를 통해 설치가 가능했다. 위 코드는 sdk안에 제공된 코드를 내 입맛에 맞게 아주 조금 수정했다.

예를 들어 한 사람이 아닌 다수에게 보내고 싶을 때가 있다고 하자. SDK는 그 경우 이렇게 하라고만 소개하고 있지 구현해놓진 않았다. 그래서 다수에게 메일 보내기를 직접 구현하였다.
문자 보낼 번호가 리스트나 튜플의 형태로 여러 개 왔을 때 하나의 문자열로 이어서 함수에 넣어줘야 문자가 보내진다고 설명에 쓰여 있다.(ex. Recipients Number '01000000000,01000000001')

⚠️ **GitHub.com Fallback** ⚠️