From dabf6f3c498f41218e3120bf9116d19f20527a1f Mon Sep 17 00:00:00 2001 From: Ivan Redun Date: Tue, 19 Jan 2021 23:14:10 +0300 Subject: [PATCH] fix: sms_callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Теперь можно прописать call_back в настройках sms.ru и получать обновления статусов отправленных сообщений --- smsru/service.py | 2 -- smsru/views.py | 12 +++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/smsru/service.py b/smsru/service.py index ae309ce..d92d770 100644 --- a/smsru/service.py +++ b/smsru/service.py @@ -130,5 +130,3 @@ def send_multi_sms(self, phone_sms: dict) -> dict: post_param['multi'][phone_beautify] = msg return self._sms_request(post_param) - - diff --git a/smsru/views.py b/smsru/views.py index ce7a634..1544009 100644 --- a/smsru/views.py +++ b/smsru/views.py @@ -8,11 +8,13 @@ @csrf_exempt def sms_callback(request): if request.method == 'POST': - data = request.POST.getlist('data[]') + data = [item[1][0].split('\n') for item in request.POST.lists() if 'data[' in item[0]] hash = request.POST.get('hash') api = SmsRuApi() - if api.validate_callback(data, hash): - item = Log.objects.filter(sms_id=data[1]).first() - item.status_code = data[2] - item.save() + if api.validate_callback(["\n".join(el) for el in data], hash): + for data_item in data: + item = Log.objects.filter(sms_id=data_item[1]).first() + if item: + item.status_code = data_item[2] + item.save() return HttpResponse(100)