This API is used to validate the linked Device with the respective user.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
/** * JunctionTV Subscriber Management with access token * */ class Container { function __construct(){ // Domain $this->domain = "http://__JTV__HOST__"; $this->token = ""; $this->device_type = "web"; $this->username = "helloworld@test.com"; $this->password = "123456"; $this->firstname = "Hello"; $this->lastname = "World"; $this->device_num = "web"; $this->device_name = "Web Browser"; } function getAccessToken(){ // set up request for access token $data = array(); $client_id = 'jtv'; // Client ID $client_secret = '************'; // Client Secret $auth_string = "{$client_id}:{$client_secret}"; $request = "https://cloud.junctiontv.net/ums/2.0/oauth/"; $ch = curl_init($request); curl_setopt_array($ch, array( CURLOPT_POST => TRUE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_USERPWD => $auth_string, CURLOPT_HTTPHEADER => array( 'Content-type: application/x-www-form-urlencoded' ), CURLOPT_POSTFIELDS => $data )); $response = curl_exec($ch); // Check for errors if (!curl_errno($ch)) { $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); }else{ die(curl_error($ch)); } curl_close($ch); if(isset($httpcode) && $httpcode == 200){ return $response; }else{ return false; } } } class Logcheck extends Container { function __construct(){ parent::__construct(); // Authentication Url $this->authUrl = "/sms/2.0/user/auth"; $this->device_num = "587753777ed6c3598601d9c4"; // Get this device_num from login success parameter value "device_num" $tok = $this->getAccessToken(); if($tok){ $tok = json_decode($tok); if(isset($tok->access_token)){ $this->token = $tok->access_token; }else{ die("Unauthorize"); } }else{ die("Unauthorize"); } } function logcheck(){ $url = $this->domain . $this->authUrl . "/" . $this->device_num . "?username=" . $this->username; $ch = curl_init($url); curl_setopt_array($ch, array( CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HTTPHEADER => array( "Authorization: Bearer " . $this->token, ) )); //execute $result = curl_exec($ch); // Check for errors if (!curl_errno($ch)) { $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); }else{ die(curl_error($ch)); } //close connection curl_close($ch); if(isset($httpcode) && $httpcode == 200){ return $result; }else{ return "HTTP Status Code ". $httpcode; } } } $r = new Logcheck(); $resp = $r->logcheck(); print_r($resp); |
1 2 3 4 5 |
{ "code": 0, "result": "success", "message": "Authentication success" } |
1 2 3 4 5 |
{ "err_code" :1011, "result" : "failure", "message" : "Invalid access" } |