Example #1
0
 public function onSubscribe(ConnectionInterface $conn, $topic)
 {
     //Config::read('wss.username');
     $querystring = $topic->getId();
     $session = $conn->WAMP->sessionId;
     $wss_user = $conn->resourceId;
     $username = Config::read('wss.username');
     $password = Config::read('wss.password');
     $host = Config::read('api.host');
     $data = "grant_type=client_credentials&client_id=" . $username . "&client_secret=" . $password;
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "{$host}/api/token");
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_TIMEOUT, 60);
     curl_setopt($ch, CURLOPT_USERPWD, "{$username}:{$password}");
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_POST, 1);
     $curlResponse = curl_exec($ch);
     curl_close($ch);
     $curlResponse = json_decode($curlResponse, TRUE);
     var_dump($curlResponse);
     $data = "access_token=" . trim($curlResponse["access_token"]);
     $data .= "&session=" . trim($conn->WAMP->sessionId);
     $data .= "&wss_user="******"&device=" . trim($topic->getId());
     //	echo $data;
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "{$host}/api/wssdeviceAccess?" . $data);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_TIMEOUT, 60);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $result = curl_exec($ch);
     curl_close($ch);
     $i = json_decode($result, TRUE);
     echo "\n---111----\n";
     var_dump($i);
     echo "\n\n\n-----------------------------\n\n\n";
     var_dump($result);
     echo "\n---1111--" . $i["result"]["view"] . "--\n";
     //$view=1;
     if ($i["result"]["view"] == 1) {
         //if($view == 1){
         if (!array_key_exists($topic->getId(), $this->subscribedTopics)) {
             $this->subscribedTopics[$topic->getId()] = $topic;
             if (array_key_exists($topic->getId(), $this->subscribedTopics)) {
                 echo $topic->getId() . "  added with  session_id " . $conn->WAMP->sessionId . " and resource_id " . $conn->resourceId . "\n";
             } else {
                 echo $topic->getId() . " device was not added \n";
             }
         }
     } else {
         $conn->close();
     }
 }
 public function __construct()
 {
     $this->setupPaths();
     $this->config = new Config();
     $this->config->loadConfigurationFiles($this->paths['config_path'], $this->getEnvironment());
 }