function registerAndSubscribe($userName, $channelName, $deviceToken, $deviceType) { Util::throwExceptionIfNullOrBlank($userName, "User Name"); Util::throwExceptionIfNullOrBlank($channelName, "Channel Name"); Util::throwExceptionIfNullOrBlank($deviceToken, "Device Token"); Util::throwExceptionIfNullOrBlank($deviceType, "Device Type"); $objUtil = new Util($this->apiKey, $this->secretKey); try { $params = null; $deviceTypeObj = new DeviceType(); if ($deviceTypeObj->isAvailable($deviceType) == "null") { throw new App42Exception("The device with type '{$deviceType}' does not Exist "); } $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $body = null; $body = '{"app42":{"push":{"userName":"******","channelName":"' . $channelName . '","deviceToken":"' . $deviceToken . '","type":"' . $deviceType . '"}}}'; $signParams['body'] = $body; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/subscribeDeviceToChannel"; $response = RestClient::post($baseURL, $params, null, null, $contentType, $accept, $body, $headerParams); $pushResponseObj = new PushNotificationResponseBuilder(); $pushObj = $pushResponseObj->buildResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $pushObj; }