This API is used when user initiates Login process.
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 127 128 129 130 131 |
/** * 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 Login extends Container { function __construct(){ parent::__construct(); // Login Url $this->loginUrl = "/sms/2.0/user/login"; $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 login(){ $url = $this->domain . $this->loginUrl . "/" . $this->device_type . "/" . $this->username; $post_data = "username=".rawurlencode($this->username). "&password=".rawurlencode($this->password). "&device_num=".rawurlencode($this->device_num). "&device_name=".rawurlencode($this->device_name); $ch = curl_init($url); curl_setopt_array($ch, array( CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_POSTFIELDS => $post_data, 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 Login(); $resp = $r->login(); print_r($resp); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
{ "code": 0, "result": "success", "message": "Successfully loggedin", "user": { "UId": "58762cff7ed6c353df684ccf", "id": 19, "username": "email@example.com", "uname": "email@example.com", "email": "email@example.com", "createDate": "Wed Jan 11 18:32:55 IST 2017", "dob": "", "gender": "m", "status": "registered", "reg_time": "Wed Jan 11 18:32:55 IST 2017", "fname": "FirstName", "lname": "LastName", "reg_device": "WEB", "is_blocked": false }, "device_num": "587645d9efb0ae4232e" } |
1 2 3 4 5 |
{ "err_code" :1003, "result" : "failure", "message" :"Invalid login" } |