RomanL 7 роки тому
батько
коміт
200f9c1459
1 змінених файлів з 10 додано та 2 видалено
  1. 10 2
      inc/classes/BxDolTwilio.php

+ 10 - 2
inc/classes/BxDolTwilio.php

@@ -50,8 +50,8 @@ class BxDolTwilio extends BxDolFactory implements iBxDolSingleton
         try{
             require_once BX_DIRECTORY_PATH_PLUGINS . 'Twilio/autoload.php'; // Loads the library
             $client = new Twilio\Rest\Client($this->_sSid, $this->_sToken);
-            $aParams = array('body' => $sMessage, 'from' => $sFrom != '' ? $sFrom : $this->_sFromNumber);
-            $client->messages->create($sTo, $aParams);
+            $aParams = array('body' => $sMessage, 'from' => $sFrom != '' ? $this->normalizePhone($sFrom) : $this->normalizePhone($this->_sFromNumber));
+            $client->messages->create($this->normalizePhone($sTo), $aParams);
             return true;
         }
         catch (Exception $oException) {
@@ -60,6 +60,14 @@ class BxDolTwilio extends BxDolFactory implements iBxDolSingleton
         }
     }
     
+    public function normalizePhone($sPhone){
+		$sPhone = trim($sPhone);
+		if (substr($sPhone, 0, 1) != '+'){
+			$sPhone = '+' . $sPhone;	
+		}
+		return $sPhone;
+	}
+    
     private function writeLog($sString)
 	{
 		$sFile = BX_DIRECTORY_PATH_LOGS . '/bx_twilio.log';