adding command test in apiserver\nsome debugging\nfree sms now running fine
This commit is contained in:
		| @@ -5,8 +5,11 @@ class notificationFreemobile | ||||
| 	private $name = "freemobile"; | ||||
| 	public $active = true; | ||||
| 	public $level; | ||||
| 	private $dest = array( | ||||
| 		"daniel" =>	"32886706&pass=JTGUY6l5OG73zX", | ||||
| 	public $curlErr; | ||||
| 	public $lastTry; | ||||
| 	public $lastTryTimeout = 5; | ||||
| 	protected $dest = array( | ||||
| 		"daniel" =>	"15480189&pass=yVpPmCWmUl2HGp", | ||||
| 		); | ||||
|  | ||||
| 	function __construct() | ||||
| @@ -16,37 +19,50 @@ class notificationFreemobile | ||||
|  | ||||
| 	function send($message, $destinataire=NOTIF_DEFAULT_DEST) | ||||
| 	{ | ||||
| 		global $curlErr; | ||||
| 		$result = false; | ||||
| 		$error = false; | ||||
| 		if ($this->active === true) | ||||
| 		{ | ||||
| 			$ch = curl_init(); | ||||
| 			// set url | ||||
| 			curl_setopt($ch, CURLOPT_URL, $this->url . $this->dest[$destinataire]  . "&msg=" . urlencode(trim($message))); | ||||
| 			echo $this->url . urlencode(trim($message)) . EOL; | ||||
| 			 | ||||
| 			//return the transfer as a string | ||||
| 			//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||||
| 			// $result contains the output string | ||||
| 			if ($curlErr <= 10) | ||||
| 			if ($this->curlErr <= 5) | ||||
| 			{ | ||||
| 				$result = curl_exec($ch); | ||||
| 				if ($result === false) | ||||
|                 logger(DEBUG, _("Curl sending message"), false, __FILE__ . ":" . __LINE__); | ||||
|                 echo $this->url . urlencode(trim($message)) . EOL; | ||||
| 				curl_exec($ch); | ||||
| 				if (curl_errno($ch) != 0) | ||||
| 				{ | ||||
| 					$curlErr += 1; | ||||
| 					$this->curlErr += 1; | ||||
| 					$this->lastTry = time(); | ||||
| 					logger(ERROR, sprintf( _("Curl return error  %d: %s when sending notification"), curl_errno($ch), curl_error($ch)), false, __FILE__ . ":" . __LINE__); | ||||
| 					$error = true; | ||||
| 				}else | ||||
| 				{ | ||||
| 					logger(DEBUG, sprintf(_("Curl return: %s when sending notification"), $result), false); | ||||
| 					logger(DEBUG, sprintf(_("Curl return: %s when sending notification"), $result), false, __FILE__ . ":" . __LINE__); | ||||
| 					$this->curlErr = 0; | ||||
| 				} | ||||
| 			} //TODO managing curl errors | ||||
| 			}else | ||||
| 			{ | ||||
| 				if ((time() - $this->lastTry) > ($this->lastTryTimeout*60)) | ||||
| 				{ | ||||
| 					$this->curlErr -= 1; | ||||
| 				} | ||||
| 				$error = true; | ||||
| 			} | ||||
| 			 | ||||
| 			 | ||||
| 			//TODO managing curl errors | ||||
| 			// close curl resource to free up system resources | ||||
| 			curl_close($ch); | ||||
| 			return true; | ||||
| 			 | ||||
| 		} | ||||
| 		return false; | ||||
| 		return $error; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| $notificationMethods["freemobile"] = new notificationFreemobile(); | ||||
|  | ||||
| ?> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user