Update mmg send_sms to include cid and request headers

Use mmg to send_sms
This commit is contained in:
Rebecca Law
2016-04-06 17:35:14 +01:00
parent 90194cbbb8
commit 340f8ceaf6
2 changed files with 9 additions and 5 deletions

View File

@@ -320,7 +320,7 @@ def send_sms_code(encrypted_verification):
mmg_client.send_sms(validate_and_format_phone_number(verification_message['to']), mmg_client.send_sms(validate_and_format_phone_number(verification_message['to']),
verification_message['secret_code'], verification_message['secret_code'],
'send-sms-code') 'send-sms-code')
except Exception as e: except MMGClientException as e:
current_app.logger.exception(e) current_app.logger.exception(e)

View File

@@ -52,16 +52,20 @@ class MMGClient(SmsClient):
"reqType": "BULK", "reqType": "BULK",
"MSISDN": to, "MSISDN": to,
"msg": content, "msg": content,
"sender": self.from_number "sender": self.from_number,
"cid": reference
} }
start_time = monotonic() start_time = monotonic()
try: try:
import json
response = request("POST", "https://www.mmgrp.co.uk/API/json/api.php", response = request("POST", "https://www.mmgrp.co.uk/API/json/api.php",
data=data) data=json.dumps(data),
headers={'Content-Type': 'application/json',
'Authorization': 'Basic {}'.format(self.api_key)})
if response.status_code != 200: if response.status_code != 200:
error = response.json error = response.text
raise MMGClientException(error) raise MMGClientException(json.loads(error))
response.raise_for_status() response.raise_for_status()
except RequestException as e: except RequestException as e:
api_error = HTTPError.create(e) api_error = HTTPError.create(e)