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
android[url] = "https://android.googleapis.com/gcm/send"
android[serverApiKey] = "AIzaSyALwyLUYtZDcJQr54V5rxhZjoWnOLWCSvc"

View File

@@ -14,32 +14,45 @@ namespace ProcessMaker\BusinessModel\Light;
class PushMessageIOS
{
var $url = 'ssl://gateway.sandbox.push.apple.com:2195';
var $passphrase = "sample";
var $pemFile;
var $devices = array();
var $response = array();
private $url = 'ssl://gateway.sandbox.push.apple.com:2195';
private $passphrase = "sample";
private $pemFile = 'mobileios.pem';
private $devices = array();
private $response = array();
/**
* Sete server notification Ios
* @param $url string the url server
*/
function setUrl($url){
public function setUrl($url)
{
$this->url = $url;
}
/**
* Constructor
* @param $passphrase update your private key's
* Set key passphrase
* @param string $passphrase update your private key's
*/
function setKey($passphrase){
public function setKey($passphrase)
{
$this->passphrase = $passphrase;
}
/**
* Set the devices token to send to
* @param $deviceIds array of device tokens to send to
* Set name file .pem
* @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)) {
$this->devices = $devicesToken;
@@ -56,14 +69,17 @@ class PushMessageIOS
$conf = \System::getSystemConfiguration(PATH_CONFIG . 'mobile.ini');
$this->setUrl($conf['apple']['url']);
$this->setKey($conf['apple']['passphrase']);
$this->setPemFile($conf['apple']['pemFile']);
}
/**
* Send the message to the device
* @param $message the message to send
* @return mixed
* @param $message string the message to send
* @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) {
$this->error("No devices set");
@@ -73,7 +89,7 @@ class PushMessageIOS
}
$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);
// Open a connection to the APNS server
@@ -138,7 +154,8 @@ class PushMessageIOS
return $this->response;
}
function error($msg){
public function error($msg)
{
echo "Android send notification failed with error:";
echo "\t" . $msg;
}