Merge branch '658-check-numbers-sent-to-rising-tide' into 'master'
Resolve "Check numbers sent to Rising Tide" Closes #658 See merge request jankstudio/resq!770
This commit is contained in:
commit
2caa286f12
1 changed files with 63 additions and 16 deletions
|
|
@ -32,6 +32,16 @@ class RisingTideGateway
|
||||||
|
|
||||||
public function sendSMS($mobile_num, $mask, $message)
|
public function sendSMS($mobile_num, $mask, $message)
|
||||||
{
|
{
|
||||||
|
// make sure number is acceptable to RT
|
||||||
|
// at this point, assume that mobile is numeric and valid mobile number
|
||||||
|
$clean_num = $this->cleanPhoneNumber($mobile_num);
|
||||||
|
|
||||||
|
if ($clean_num === false)
|
||||||
|
{
|
||||||
|
error_log('Invalid mobile number provided. Cannot send SMS message to ' . $mobile_num);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$headers = [
|
$headers = [
|
||||||
'Content-Type: application/vnd.net.wyrls.Document-v3+json'
|
'Content-Type: application/vnd.net.wyrls.Document-v3+json'
|
||||||
];
|
];
|
||||||
|
|
@ -39,7 +49,7 @@ class RisingTideGateway
|
||||||
$sms = new SMSMessage();
|
$sms = new SMSMessage();
|
||||||
$sms->setFrom($this->shortcode)
|
$sms->setFrom($this->shortcode)
|
||||||
->setFromAlias($mask)
|
->setFromAlias($mask)
|
||||||
->setTo($mobile_num)
|
->setTo($clean_num)
|
||||||
->setMessage($message)
|
->setMessage($message)
|
||||||
->setStatus('sent');
|
->setStatus('sent');
|
||||||
|
|
||||||
|
|
@ -54,7 +64,7 @@ class RisingTideGateway
|
||||||
'id' => $sms->getID(),
|
'id' => $sms->getID(),
|
||||||
'from' => $this->shortcode,
|
'from' => $this->shortcode,
|
||||||
'from_alias' => $mask,
|
'from_alias' => $mask,
|
||||||
'to' => $mobile_num,
|
'to' => $clean_num,
|
||||||
'content_type' => 'text/plain',
|
'content_type' => 'text/plain',
|
||||||
'body' => $message,
|
'body' => $message,
|
||||||
'date' => $date_string,
|
'date' => $date_string,
|
||||||
|
|
@ -67,21 +77,21 @@ class RisingTideGateway
|
||||||
|
|
||||||
$userpwd = $this->user . ':' . $this->pass;
|
$userpwd = $this->user . ':' . $this->pass;
|
||||||
|
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
curl_setopt($curl, CURLOPT_URL, self::SERVER_URL);
|
curl_setopt($curl, CURLOPT_URL, self::SERVER_URL);
|
||||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||||
curl_setopt($curl, CURLOPT_VERBOSE, true);
|
curl_setopt($curl, CURLOPT_VERBOSE, true);
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json);
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json);
|
||||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||||
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||||
curl_setopt($curl, CURLOPT_USERPWD, $userpwd);
|
curl_setopt($curl, CURLOPT_USERPWD, $userpwd);
|
||||||
$result = curl_exec($curl);
|
$result = curl_exec($curl);
|
||||||
error_log('error_no - ' . curl_errno($curl));
|
error_log('error_no - ' . curl_errno($curl));
|
||||||
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
error_log($http_code);
|
error_log($http_code);
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
|
||||||
error_log($result);
|
error_log($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validatePhoneNumber($mobile)
|
public function validatePhoneNumber($mobile)
|
||||||
|
|
@ -107,4 +117,41 @@ class RisingTideGateway
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function cleanPhoneNumber($mobile)
|
||||||
|
{
|
||||||
|
// remove any non digit character from string
|
||||||
|
$clean_number = preg_replace('~\D~', '', $mobile);
|
||||||
|
error_log('cleaned ' . $clean_number);
|
||||||
|
|
||||||
|
// does it fit our 09XXXXXXXXX pattern?
|
||||||
|
if (preg_match('/^09[0-9]{9}$/', $clean_number))
|
||||||
|
{
|
||||||
|
// remove first '0'
|
||||||
|
$clean_number = substr($clean_number, 1);
|
||||||
|
|
||||||
|
// prepend 63
|
||||||
|
$clean_number = '63' . $clean_number;
|
||||||
|
|
||||||
|
error_log("CONVERTED TO $clean_number");
|
||||||
|
return $clean_number;
|
||||||
|
}
|
||||||
|
// does it fit our 63XXXXXXXXXX pattern?
|
||||||
|
else if (preg_match('/^63[0-9]{10}$/', $clean_number))
|
||||||
|
{
|
||||||
|
// leave alone
|
||||||
|
return $clean_number;
|
||||||
|
}
|
||||||
|
// does it fit our 9XXXXXXXXX pattern?
|
||||||
|
else if (preg_match('/^9[0-9]{9}$/', $clean_number))
|
||||||
|
{
|
||||||
|
// prepend 63
|
||||||
|
$clean_number = '63' . $clean_number;
|
||||||
|
|
||||||
|
error_log("CONVERT TO $clean_number");
|
||||||
|
return $clean_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue