├── README.md └── iptvadminAPI.php /README.md: -------------------------------------------------------------------------------- 1 | # netforms-iptvadmin-api 2 | 3 | Basic PHP class to use iptvadmin API (part of NETFORMS IPTV solution, http://4network.tv/). Boilerplate for your own code. 4 | 5 | ## Usage 6 | 7 | ```php 8 | setPrintResponse(1); 14 | 15 | $iptvadmin->registerUser("ID1", "MultiTricker", "hesl", "Michal", "Ševčík", "michal@rete.cz", 16 | "123456789", "10", "Rozšířená"); 17 | 18 | $iptvadmin->removeUser("ID1"); 19 | 20 | $iptvadmin->modifyUser("ID1", "MultiTricker", "hesl", "Michal", "Ševčík", "michal@rete.cz", 21 | "123456789", "10"); 22 | 23 | $iptvadmin->getUser("ID1"); 24 | 25 | $iptvadmin->getUsers(); 26 | 27 | $iptvadmin->getUserDevices("ID1"); 28 | 29 | $iptvadmin->removeUserDevice("ID1", "DEVICEID"); 30 | 31 | $iptvadmin->getPackages(); 32 | 33 | $iptvadmin->activateUserPackage("ID1", "SPORT"); 34 | 35 | $iptvadmin->deactivateUserPackage("ID1", "SPORT"); 36 | 37 | $iptvadmin->addUserSTB("ID1", "12:34:56:78:90:12", "STB name"); 38 | ``` -------------------------------------------------------------------------------- /iptvadminAPI.php: -------------------------------------------------------------------------------- 1 | setUrl($URL); 29 | $this->setLogin($userLogin); 30 | $this->setPassword($userPassword); 31 | $this->setPrintResponse($printResponse); 32 | 33 | return; 34 | 35 | } 36 | 37 | /** 38 | * @param mixed $URL 39 | * @return $this 40 | */ 41 | public function setUrl($URL) 42 | { 43 | 44 | if(substr($URL, -1) != "/") 45 | { 46 | $URL .= "/"; 47 | } 48 | 49 | $this->URL = $URL; 50 | 51 | return $this; 52 | } 53 | 54 | /** 55 | * @param mixed $userLogin 56 | * @return $this 57 | */ 58 | public function setLogin($userLogin) 59 | { 60 | $this->userLogin = $userLogin; 61 | return $this; 62 | } 63 | 64 | /** 65 | * @param mixed $userPassword 66 | * @return $this 67 | */ 68 | public function setPassword($userPassword) 69 | { 70 | $this->userPassword = $userPassword; 71 | return $this; 72 | } 73 | 74 | /** 75 | * @param mixed $printResponse 76 | */ 77 | public function setPrintResponse($printResponse) 78 | { 79 | $this->printResponse = $printResponse; 80 | } 81 | 82 | /** 83 | * @return string JSON 84 | */ 85 | public function getUrl() 86 | { 87 | return $this->URL; 88 | } 89 | 90 | /** 91 | * @return string JSON 92 | */ 93 | public function getLogin() 94 | { 95 | return $this->userLogin; 96 | } 97 | 98 | /** 99 | * @return string JSON 100 | */ 101 | public function getPassword() 102 | { 103 | return $this->userPassword; 104 | } 105 | 106 | /** 107 | * @return mixed 108 | */ 109 | public function getPrintResponse() 110 | { 111 | return $this->printResponse; 112 | } 113 | 114 | /** 115 | * @param string $action 116 | * @param array $parameters 117 | * @return string JSON 118 | */ 119 | public function generateApiCall($action, $parameters) 120 | { 121 | 122 | // Add login 123 | $parameters['login'] = $this->getLogin(); 124 | $parameters['password'] = $this->getPassword(); 125 | 126 | // Drop empty parameters 127 | foreach($parameters AS $key => $value) 128 | { 129 | if($value == "") 130 | { 131 | unset($parameters[$key]); 132 | } 133 | } 134 | 135 | return $this->getUrl() . $action . "?" . http_build_query($parameters, null, '&', PHP_QUERY_RFC3986); 136 | 137 | } 138 | 139 | /** 140 | * @param $request 141 | * @return string JSON 142 | */ 143 | public function callApi($request) 144 | { 145 | 146 | // INIT 147 | $ch = curl_init(); 148 | curl_setopt($ch, CURLOPT_URL, $request); 149 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 150 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); 151 | 152 | // No SSL check 153 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 154 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 155 | 156 | // Do it 157 | $response = curl_exec($ch); 158 | echo curl_error($ch); 159 | curl_close($ch); 160 | unset($ch); 161 | 162 | if($this->getPrintResponse() == 1) 163 | { 164 | echo $response; 165 | } 166 | 167 | return $response; 168 | 169 | } 170 | 171 | /** 172 | * @param $MAC 173 | * @return bool 174 | */ 175 | public function isMac($MAC) 176 | { 177 | 178 | if(preg_match("/([a-fA-F0-9]{2}[:|\-]?){6}/", $MAC)) 179 | { 180 | return true; 181 | } 182 | else 183 | { 184 | return false; 185 | } 186 | 187 | } 188 | 189 | /** 190 | * @param $MAC 191 | * @return string 192 | */ 193 | function formatMac($MAC) 194 | { 195 | 196 | return trim(str_replace(["-", ".", ",", "::", ";"], ":", $MAC)); 197 | 198 | } 199 | 200 | /** 201 | * @param string $partnerid 202 | * @param string $userLogin 203 | * @param string $userPassword 204 | * @param string $firstName 205 | * @param string $familyName 206 | * @param string $email 207 | * @param string $phone 208 | * @param int $maxDeviceCount 209 | * @param int|string $package 210 | * @param int|string $timelimit 211 | * @return string JSON 212 | */ 213 | public function registerUser($partnerid, $userLogin, $userPassword, $firstName, $familyName, $email = "", $phone = "", $maxDeviceCount = 5, $package = "", $timelimit = "") 214 | { 215 | 216 | $request = $this->generateApiCall("registeruser", get_defined_vars()); 217 | $response = $this->callApi($request); 218 | return $response; 219 | 220 | } 221 | 222 | /** 223 | * @param string $partnerid 224 | * @return string JSON 225 | */ 226 | public function removeUser($partnerid) 227 | { 228 | 229 | $request = $this->generateApiCall("remove-user", get_defined_vars()); 230 | $response = $this->callApi($request); 231 | return $response; 232 | 233 | } 234 | 235 | /** 236 | * @param string $partnerid 237 | * @param string $userLogin 238 | * @param string $userPassword 239 | * @param string $firstName 240 | * @param string $familyName 241 | * @param string $email 242 | * @param string $phone 243 | * @param int $maxDeviceCount 244 | * @return string JSON 245 | */ 246 | public function modifyUser($partnerid, $userLogin, $userPassword, $firstName, $familyName, $email = "", $phone = "", $maxDeviceCount = 5) 247 | { 248 | 249 | $request = $this->generateApiCall("modifyuser", get_defined_vars()); 250 | $response = $this->callApi($request); 251 | return $response; 252 | 253 | } 254 | 255 | /** 256 | * @param string $partnerid 257 | * @param string $packageoutput input values are: id,full,isOtt 258 | * @return string JSON 259 | */ 260 | public function getUser($partnerid, $packageoutput = "") 261 | { 262 | 263 | $request = $this->generateApiCall("getuser", get_defined_vars()); 264 | $response = $this->callApi($request); 265 | return $response; 266 | 267 | } 268 | 269 | /** 270 | * @return string JSON 271 | */ 272 | public function getUsers() 273 | { 274 | 275 | $request = $this->generateApiCall("getusers", get_defined_vars()); 276 | $response = $this->callApi($request); 277 | return $response; 278 | 279 | } 280 | 281 | /** 282 | * @param string $partnerid 283 | * @param string $packageoutput input values are: id,full,isOtt 284 | * @return string JSON 285 | */ 286 | public function getUserDevices($partnerid, $packageoutput = "") 287 | { 288 | 289 | $request = $this->generateApiCall("get-user-devices", get_defined_vars()); 290 | $response = $this->callApi($request); 291 | return $response; 292 | 293 | } 294 | 295 | /** 296 | * @param string $partnerid 297 | * @param int $deviceid 298 | * @return string JSON 299 | */ 300 | public function removeUserDevice($partnerid, $deviceid) 301 | { 302 | 303 | $request = $this->generateApiCall("remove-user-device", get_defined_vars()); 304 | $response = $this->callApi($request); 305 | return $response; 306 | 307 | } 308 | 309 | /** 310 | * @param string $packageoutput input values are: id,full,isOtt 311 | * @return string JSON 312 | */ 313 | public function getPackages($packageoutput = "") 314 | { 315 | 316 | $request = $this->generateApiCall("getpackages", get_defined_vars()); 317 | $response = $this->callApi($request); 318 | return $response; 319 | 320 | } 321 | 322 | /** 323 | * @param string $partnerid 324 | * @param string $package 325 | * @return string JSON 326 | */ 327 | public function activateUserPackage($partnerid, $package) 328 | { 329 | 330 | $request = $this->generateApiCall("activate-user", get_defined_vars()); 331 | $response = $this->callApi($request); 332 | return $response; 333 | 334 | } 335 | 336 | /** 337 | * @param string $partnerid 338 | * @param string $package 339 | * @return string JSON 340 | */ 341 | public function deactivateUserPackage($partnerid, $package) 342 | { 343 | 344 | $request = $this->generateApiCall("deactivate-user", get_defined_vars()); 345 | $response = $this->callApi($request); 346 | return $response; 347 | 348 | } 349 | 350 | /** 351 | * @param string $partnerid 352 | * @param string $mac 353 | * @param string $name 354 | * @return string JSON 355 | * @throws \Exception 356 | */ 357 | public function addUserStb($partnerid, $mac, $name = "") 358 | { 359 | 360 | $mac = $this->formatMac($mac); 361 | 362 | if(!$this->isMac($mac)) 363 | { 364 | 365 | throw new \Exception("Invalid MAC address format. Should be 00:00:00:00:00:00, is ".$mac); 366 | 367 | } 368 | else 369 | { 370 | 371 | $request = $this->generateApiCall("add-user-stb", get_defined_vars()); 372 | $response = $this->callApi($request); 373 | return $response; 374 | 375 | } 376 | 377 | } 378 | 379 | /** 380 | * @param $partnerid 381 | * @param $timelimit 382 | * @return string JSON 383 | */ 384 | public function setPvrTimelimit($partnerid, $timelimit) 385 | { 386 | 387 | $request = $this->generateApiCall("set-pvr-timelimit", get_defined_vars()); 388 | $response = $this->callApi($request); 389 | return $response; 390 | 391 | } 392 | 393 | /** 394 | * @param $partnerid 395 | * @return string JSON 396 | */ 397 | public function disableUser($partnerid) 398 | { 399 | 400 | $request = $this->generateApiCall("disable-user", get_defined_vars()); 401 | $response = $this->callApi($request); 402 | return $response; 403 | 404 | } 405 | 406 | /** 407 | * @param string $mac 408 | * @param string $type soft (default) or hard 409 | * @return string JSON 410 | */ 411 | public function restartStb($mac, $type = "") 412 | { 413 | 414 | $request = $this->generateApiCall("restart-stb", get_defined_vars()); 415 | $response = $this->callApi($request); 416 | return $response; 417 | 418 | } 419 | 420 | /** 421 | * @return string JSON 422 | */ 423 | public function getChannels() 424 | { 425 | 426 | $request = $this->generateApiCall("get-channels", get_defined_vars()); 427 | $response = $this->callApi($request); 428 | return $response; 429 | 430 | } 431 | 432 | /** 433 | * Use returned token to redirect user on portal: 434 | * https://www.urlportalu.cz/autologin/TOKEN/ 435 | * 436 | * @param string $partnerid 437 | * @return string JSON 438 | */ 439 | public function getAutologinToken($partnerid) 440 | { 441 | 442 | $request = $this->generateApiCall("get-channels", get_defined_vars()); 443 | $response = $this->callApi($request); 444 | return $response; 445 | 446 | } 447 | 448 | /** 449 | * @param string $package 450 | * @return string JSON 451 | */ 452 | public function getPackage($package) 453 | { 454 | 455 | $request = $this->generateApiCall("get-package", get_defined_vars()); 456 | $response = $this->callApi($request); 457 | return $response; 458 | 459 | } 460 | 461 | /** 462 | * @param string $package 463 | * $param int $ott 0/1 464 | * @return string JSON 465 | */ 466 | public function addPackage($package, $ott) 467 | { 468 | 469 | $request = $this->generateApiCall("add-package", get_defined_vars()); 470 | $response = $this->callApi($request); 471 | return $response; 472 | 473 | } 474 | 475 | /** 476 | * @param string $package 477 | * @return string JSON 478 | */ 479 | public function removePackage($package) 480 | { 481 | 482 | $request = $this->generateApiCall("remove-package", get_defined_vars()); 483 | $response = $this->callApi($request); 484 | return $response; 485 | 486 | } 487 | 488 | /** 489 | * @param string $package 490 | * @param string $onstb 0/1 491 | * @param string $onss 0/1 492 | * @param int $channelid 493 | * @param int $position 494 | * @return string JSON 495 | */ 496 | public function addPackageChannel($package, $onstb, $onss, $channelid, $position) 497 | { 498 | 499 | $request = $this->generateApiCall("add-package-channel", get_defined_vars()); 500 | $response = $this->callApi($request); 501 | return $response; 502 | 503 | } 504 | 505 | /** 506 | * @param string $package 507 | * @param $int $channelid 508 | * @return string JSON 509 | */ 510 | public function removePackageChannel($package, $channelid) 511 | { 512 | 513 | $request = $this->generateApiCall("remove-package-channel", get_defined_vars()); 514 | $response = $this->callApi($request); 515 | return $response; 516 | 517 | } 518 | 519 | /** 520 | * @param string $partnerid 521 | * @return string JSON 522 | */ 523 | public function generatePairCode($partnerid) 524 | { 525 | 526 | $request = $this->generateApiCall("generate-pair-code", get_defined_vars()); 527 | $response = $this->callApi($request); 528 | return $response; 529 | 530 | } 531 | 532 | function __destruct() 533 | { 534 | return; 535 | } 536 | 537 | } --------------------------------------------------------------------------------