Clean up code. #658
This commit is contained in:
parent
b712b35a97
commit
9bc1f44ca2
1 changed files with 53 additions and 52 deletions
|
|
@ -37,60 +37,61 @@ class RisingTideGateway
|
||||||
$clean_num = $this->cleanPhoneNumber($mobile_num);
|
$clean_num = $this->cleanPhoneNumber($mobile_num);
|
||||||
|
|
||||||
if ($clean_num === false)
|
if ($clean_num === false)
|
||||||
error_log('Invalid mobile number provided. Cannot send SMS message to ' . $mobile_num);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
$headers = [
|
error_log('Invalid mobile number provided. Cannot send SMS message to ' . $mobile_num);
|
||||||
'Content-Type: application/vnd.net.wyrls.Document-v3+json'
|
return;
|
||||||
];
|
|
||||||
|
|
||||||
$sms = new SMSMessage();
|
|
||||||
$sms->setFrom($this->shortcode)
|
|
||||||
->setFromAlias($mask)
|
|
||||||
->setTo($clean_num)
|
|
||||||
->setMessage($message)
|
|
||||||
->setStatus('sent');
|
|
||||||
|
|
||||||
$this->em->persist($sms);
|
|
||||||
$this->em->flush();
|
|
||||||
|
|
||||||
$date = $sms->getDateCreate();
|
|
||||||
// $date = new DateTime();
|
|
||||||
$date_string = $date->format('Y-m-d') . 'T' . $date->format('H:m:s');
|
|
||||||
|
|
||||||
$data = [
|
|
||||||
'id' => $sms->getID(),
|
|
||||||
'from' => $this->shortcode,
|
|
||||||
'from_alias' => $mask,
|
|
||||||
'to' => $clean_num,
|
|
||||||
'content_type' => 'text/plain',
|
|
||||||
'body' => $message,
|
|
||||||
'date' => $date_string,
|
|
||||||
'usagetype' => $this->usage_type,
|
|
||||||
'delivery_receipt_url' => $this->dr_url,
|
|
||||||
];
|
|
||||||
error_log(print_r($data, true));
|
|
||||||
|
|
||||||
$data_json = json_encode($data);
|
|
||||||
|
|
||||||
$userpwd = $this->user . ':' . $this->pass;
|
|
||||||
|
|
||||||
$curl = curl_init();
|
|
||||||
curl_setopt($curl, CURLOPT_URL, self::SERVER_URL);
|
|
||||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
|
||||||
curl_setopt($curl, CURLOPT_VERBOSE, true);
|
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json);
|
|
||||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
|
|
||||||
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
|
||||||
curl_setopt($curl, CURLOPT_USERPWD, $userpwd);
|
|
||||||
$result = curl_exec($curl);
|
|
||||||
error_log('error_no - ' . curl_errno($curl));
|
|
||||||
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
||||||
error_log($http_code);
|
|
||||||
curl_close($curl);
|
|
||||||
|
|
||||||
error_log($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$headers = [
|
||||||
|
'Content-Type: application/vnd.net.wyrls.Document-v3+json'
|
||||||
|
];
|
||||||
|
|
||||||
|
$sms = new SMSMessage();
|
||||||
|
$sms->setFrom($this->shortcode)
|
||||||
|
->setFromAlias($mask)
|
||||||
|
->setTo($clean_num)
|
||||||
|
->setMessage($message)
|
||||||
|
->setStatus('sent');
|
||||||
|
|
||||||
|
$this->em->persist($sms);
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
|
$date = $sms->getDateCreate();
|
||||||
|
// $date = new DateTime();
|
||||||
|
$date_string = $date->format('Y-m-d') . 'T' . $date->format('H:m:s');
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'id' => $sms->getID(),
|
||||||
|
'from' => $this->shortcode,
|
||||||
|
'from_alias' => $mask,
|
||||||
|
'to' => $clean_num,
|
||||||
|
'content_type' => 'text/plain',
|
||||||
|
'body' => $message,
|
||||||
|
'date' => $date_string,
|
||||||
|
'usagetype' => $this->usage_type,
|
||||||
|
'delivery_receipt_url' => $this->dr_url,
|
||||||
|
];
|
||||||
|
error_log(print_r($data, true));
|
||||||
|
|
||||||
|
$data_json = json_encode($data);
|
||||||
|
|
||||||
|
$userpwd = $this->user . ':' . $this->pass;
|
||||||
|
|
||||||
|
$curl = curl_init();
|
||||||
|
curl_setopt($curl, CURLOPT_URL, self::SERVER_URL);
|
||||||
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
curl_setopt($curl, CURLOPT_VERBOSE, true);
|
||||||
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json);
|
||||||
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||||
|
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||||
|
curl_setopt($curl, CURLOPT_USERPWD, $userpwd);
|
||||||
|
$result = curl_exec($curl);
|
||||||
|
error_log('error_no - ' . curl_errno($curl));
|
||||||
|
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
|
error_log($http_code);
|
||||||
|
curl_close($curl);
|
||||||
|
|
||||||
|
error_log($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validatePhoneNumber($mobile)
|
public function validatePhoneNumber($mobile)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue