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,32 +14,45 @@ 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)
{
$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)) { if (is_array($devicesToken)) {
$this->devices = $devicesToken; $this->devices = $devicesToken;
@@ -56,14 +69,17 @@ class PushMessageIOS
$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");
@@ -73,7 +89,7 @@ class PushMessageIOS
} }
$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
@@ -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;
} }