Merged in qronald/processmaker/HOR-541 (pull request #3916)

HOR-541
This commit is contained in:
Julio Cesar Laura Avendaño
2016-03-23 18:34:42 -04:00
2 changed files with 40 additions and 24 deletions

View File

@@ -1,4 +1,3 @@
;Setting Android ;Setting Android
android[url] = "https://android.googleapis.com/gcm/send" android[url] = "https://android.googleapis.com/gcm/send"
android[serverApiKey] = "AIzaSyALwyLUYtZDcJQr54V5rxhZjoWnOLWCSvc" android[serverApiKey] = "AIzaSyALwyLUYtZDcJQr54V5rxhZjoWnOLWCSvc"

View File

@@ -14,34 +14,47 @@ namespace ProcessMaker\BusinessModel\Light;
class PushMessageIOS class PushMessageIOS
{ {
var $url = 'ssl://gateway.sandbox.push.apple.com:2195'; private $url = 'ssl://gateway.sandbox.push.apple.com:2195';
var $passphrase = "sample"; private $passphrase = "sample";
var $pemFile; private $pemFile = 'mobileios.pem';
var $devices = array(); private $devices = array();
var $response = array(); private $response = array();
/** /**
* Sete server notification Ios
* @param $url string the url server * @param $url string the url server
*/ */
function setUrl($url){ public function setUrl($url)
{
$this->url = $url; $this->url = $url;
} }
/** /**
* Constructor * Set key passphrase
* @param $passphrase update your private key's * @param string $passphrase update your private key's
*/ */
function setKey($passphrase){ public function setKey($passphrase)
{
$this->passphrase = $passphrase; $this->passphrase = $passphrase;
} }
/** /**
* Set the devices token to send to * Set name file .pem
* @param $deviceIds array of device tokens to send to * @param string $file name file .pem
*/ */
function setDevices($devicesToken) public function setPemFile($file)
{ {
if(is_array($devicesToken)){ $file = file_exists(PATH_CONFIG . $file)?$file:'mobileios.pem';
$this->pemFile = $file;
}
/**
* Set the devices token to send to
* @param array $devicesToken of device tokens to send to
*/
public function setDevices($devicesToken)
{
if (is_array($devicesToken)) {
$this->devices = $devicesToken; $this->devices = $devicesToken;
} else { } else {
$this->devices = array($devicesToken); $this->devices = array($devicesToken);
@@ -53,27 +66,30 @@ class PushMessageIOS
*/ */
public function setSettingNotification() public function setSettingNotification()
{ {
$conf = \System::getSystemConfiguration( PATH_CONFIG . 'mobile.ini' ); $conf = \System::getSystemConfiguration(PATH_CONFIG . 'mobile.ini');
$this->setUrl($conf['apple']['url']); $this->setUrl($conf['apple']['url']);
$this->setKey($conf['apple']['passphrase']); $this->setKey($conf['apple']['passphrase']);
$this->setPemFile($conf['apple']['pemFile']);
} }
/** /**
* Send the message to the device * Send the message to the device
* @param $message the message to send * @param $message string the message to send
* @return mixed * @param $data object for payload body
* @return array
* @throws \Exception
*/ */
function send($message, $data) public function send($message, $data)
{ {
if(!is_array($this->devices) || count($this->devices) == 0){ if (!is_array($this->devices) || count($this->devices) == 0) {
$this->error("No devices set"); $this->error("No devices set");
} }
if(strlen($this->passphrase) < 8){ if (strlen($this->passphrase) < 8) {
$this->error("Server API Key not set"); $this->error("Server API Key not set");
} }
$ctx = stream_context_create(); $ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', PATH_CONFIG . 'mobileios.pem'); stream_context_set_option($ctx, 'ssl', 'local_cert', PATH_CONFIG . $this->pemFile);
stream_context_set_option($ctx, 'ssl', 'passphrase', $this->passphrase); stream_context_set_option($ctx, 'ssl', 'passphrase', $this->passphrase);
// Open a connection to the APNS server // Open a connection to the APNS server
@@ -112,7 +128,7 @@ class PushMessageIOS
$fp = stream_socket_client($this->url, $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx); $fp = stream_socket_client($this->url, $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp) { if (!$fp) {
throw (new \Exception( \G::LoadTranslation( 'ID_FAILED' ).': ' ."$err $errstr")); throw (new \Exception(\G::LoadTranslation('ID_FAILED') . ': ' . "$err $errstr"));
} else { } else {
//echo 'Apple service is online. ' . '<br />'; //echo 'Apple service is online. ' . '<br />';
} }
@@ -138,7 +154,8 @@ class PushMessageIOS
return $this->response; return $this->response;
} }
function error($msg){ public function error($msg)
{
echo "Android send notification failed with error:"; echo "Android send notification failed with error:";
echo "\t" . $msg; echo "\t" . $msg;
} }