connect_errno){ $err = "CONNECT FAIL: ". $mysqli->connect_errno.' '.$mysqli->connect_error; $err_cnt++; } $debug=$_REQUEST["d"]; $gsp_access_token="not_set"; $q23="SELECT `gsp_access_token`,`gsp_refresh_token`,`gsp_exp`,`gsp_base_url` FROM `gsp_auth` WHERE `co_gstin`='".$co_gstin."' AND `gsp_exp`>'$nxt1min' AND `type`='ewb' ORDER BY `ga_id` DESC LIMIT 1"; //exit($q23); $g_gsp=$mysqli->query($q23); if(!$g_gsp){echo " GSA Detail error. Possible reasons ". $mysqli->error."
$q23";;exit;} while($gsa=$g_gsp->fetch_array()){ $gsp_access_token=$gsa["gsp_access_token"]; $gsp_refresh_token=$gsa["gsp_refresh_token"]; $gsp_exp=$gsa["gsp_exp"]; $gsp_base_url=$gsa["gsp_base_url"]; } if($gsp_access_token=='not_set'){ $q40="SELECT * FROM `gsp_details` WHERE `co_gstin`='".$co_gstin."' AND `gsp_status`='active' AND `type`='ewb' LIMIT 1"; $g_gsp=$mysqli->query($q40); if(!$g_gsp){echo "GSP Detail error. Possible reasons ". $mysqli->error."
$q40";;exit;} while($gsro=$g_gsp->fetch_array()){ $gsp_un=$gsro["gsp_un"]; $gsp_pw=$gsro["gsp_pw"]; $gsp_client_id=$gsro["gsp_client_id"]; $gsp_authorisation=$gsro["gsp_authorisation"]; $gsp_base_url=$gsro["gsp_base_url"]; } // echo "hreer 51"; // // $gsp_un="erp1%40perennialsys.com"; // // $gsp_pw="einv12345"; // // $gsp_client_id="testerpclient"; // // $gsp_authorisation="Basic dGVzdGVycGNsaWVudDpBZG1pbkAxMjM="; // // $gsp_base_url="http://35.154.208.8:8080"; //$co_gstin="29AFQPB8708K000"; // Script to test if the CURL extension is installed on this server // Ouput text to user based on test if (_is_curl_installed()) { //echo "cURL is Installed on this server.
"; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => ''.$gsp_base_url.'/auth-server/oauth/token', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => 'grant_type=password&username='.$gsp_un.'&password='.$gsp_pw.'&client_id='.$gsp_client_id.'&scope=', CURLOPT_HTTPHEADER => array( 'Content-Type: application/x-www-form-urlencoded', 'gstin: '.$co_gstin.'', 'Accept: application/json', 'Authorization: '.$gsp_authorisation.'' ), )); // CURLOPT_URL => $url.'/auth-server/oauth/token', // CURLOPT_RETURNTRANSFER => true, // CURLOPT_ENCODING => '', // CURLOPT_MAXREDIRS => 10, // CURLOPT_TIMEOUT => 0, // CURLOPT_FOLLOWLOCATION => true, // CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, // CURLOPT_CUSTOMREQUEST => 'POST', // CURLOPT_POSTFIELDS => 'grant_type=password&username='.urlencode($un).'&password='.urlencode($pwd).'&client_id='.urlencode($client_id).'&scope=', // CURLOPT_HTTPHEADER => array( // 'Content-Type: application/x-www-form-urlencoded', // 'gstin: '.$co_gstin, // 'Accept: application/json', // 'Authorization: Basic '.$auth_basic // ), // )); $response = curl_exec($curl); curl_close($curl); $responseJson=json_decode($response); if ( json_last_error() !== 0 ) { echo json_last_error_msg(); } else { $gsp_access_token=$responseJson->access_token; $token_type=$responseJson->token_type; $gsp_refresh_token=$responseJson->refresh_token;; $expires_in=$responseJson->expires_in;; $scope=$responseJson->scope; if($gsp_access_token!=""){ $exp_dtt=date("Y-m-d H:i:s",strtotime("+".$expires_in." seconds",strtotime(date("Y-m-d H:i:s")))); $ins_q="INSERT INTO `gsp_auth` (`gsp_access_token`,`gsp_token_type`,`gsp_refresh_token`,`gsp_token_expires_in`,`gsp_dtt`,`gsp_exp`,`gsp_scope`,`co_gstin`,`gsp_base_url`,`type`) VALUES ('$gsp_access_token','$token_type','$gsp_refresh_token','$expires_in','".date("Y-m-d H:i:s")."','$exp_dtt','$scope','$co_gstin','$gsp_base_url','ewb')"; //echo $ins_q; $ins=$mysqli->query($ins_q); if(!$ins){echo $mysqli->error."
".$ins_q;} // echo "
				// Access Token : $access_token=$responseJson->access_token;
				// Token type : $token_type=$responseJson->token_type;
				// Refresh token :		$refresh_token=$responseJson->refresh_token;;
				// Expires in : $expires_in=$responseJson->expires_in;;
				// Scope : $scope=$responseJson->scope;			
				// 
"; }else{ echo "GSP Credentials Error: ".$responseJson->error_description."
"; } } } else { echo "cURL is NOT installed on this server.
Exiting..."; exit; } } // if($debug=='y'){ // echo "Line No 139 Debug mode GSP Access Token : $gsp_access_token
$exp_dtt
"; // } // exit; //checking for valid api_token $api_access_token="not_set"; $q123="SELECT `api_access_token`,`api_refresh_token`,`api_exp`,`api_base_url` FROM `api_auth` WHERE `co_gstin`='".$co_gstin."' AND `api_exp`>'$nxt1min' AND `type`='ewb' ORDER BY `api_id` DESC LIMIT 1"; //exit($q123); $g_api=$mysqli->query($q123); if(!$g_api){echo " API Fetch Detail error. Possible reasons ". $mysqli->error."
$q123";;exit;} while($gari=$g_api->fetch_array()){ $api_access_token=$gari["api_access_token"]; $api_refresh_token=$gari["api_refresh_token"]; $api_exp=$gari["api_exp"]; $api_base_url=$gari["api_base_url"]; } if($api_access_token=='not_set'){ //!checking for valid api_token //Getting ewb_un/pwd $q139="SELECT * FROM `gsp_details` WHERE `co_gstin`='".$co_gstin."' AND `gsp_status`='active' AND `type`='ewb' LIMIT 1"; $g_gsp=$mysqli->query($q139); if(!$g_gsp){echo "GSP Detail error. Possible reasons ". $mysqli->error."
$q139";;exit;} while($gsro=$g_gsp->fetch_array()){ $ewb_un=$gsro["ewb_un"]; $ewb_pwd=$gsro["ewb_pwd"]; // $gsp_client_id=$gsro["gsp_client_id"]; // $gsp_authorisation=$gsro["gsp_authorisation"]; $gsp_base_url=$gsro["gsp_base_url"]; } //!Getting ewb_un/pwd //sob GST auth $curl2 = curl_init(); //182.50.130.44 //http://35.154.208.8:8080/einvoice/v1.03/authentication curl_setopt_array($curl2, array( CURLOPT_URL => $gsp_base_url.'/ewb/enc/v1.03/authentication', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>'{ "action":"ACCESSTOKEN", "username":"'.$ewb_un.'", "password":"'.$ewb_pwd.'" } ', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'gstin: '.$co_gstin.'', 'Accept: application/json', 'X-Connector-Auth-Token: l7xxba7aa16e968646b992298b377e955e7c:20180622093257:27GSPMH2101G1Z2', 'action: ACCESSTOKEN', 'Authorization: Bearer '.$gsp_access_token.'' ), )); //'gstin: 05AALFP1139Q003','gstin: 05AALFP1139Q003', //'X-Connector-Auth-Token: l7xxba7aa16e968646b992298b377e955e7c:20180519134451:27GSPMH2101G1Z2', $response2 = curl_exec($curl2); // var_dump($response2)."
GAT ".$gsp_access_token; curl_close($curl2); $response2Json=json_decode($response2); // if ( json_last_error() !== 0 ) { echo json_last_error_msg(); } else { if($debug=='y'){ echo "
$gsp_access_token. . Line 206 ".$response2; }else{ if($response2Json->error[0]->errorMsg==""){ $api_access_token=$response2Json->access_token; $api_token_type=$response2Json->token_type; $api_refresh_token=$response2Json->refresh_token;; $api_expires_in=$response2Json->expires_in;; $scope=$response2Json->scope; $availableApiHits=$response2Json->availableApiHits; if($api_access_token!=""){ $api_exp_dtt=date("Y-m-d H:i:s",strtotime("+".$api_expires_in." seconds",strtotime(date("Y-m-d H:i:s")))); $api_ins_q="INSERT INTO `api_auth` (`api_access_token`,`api_token_type`,`api_refresh_token`,`api_token_expires_in`,`api_dtt`,`api_exp`,`api_scope`,`co_gstin`,`api_base_url`,`availableApiHits`,`type`) VALUES ('$api_access_token','$api_token_type','$api_refresh_token','$api_expires_in','".date("Y-m-d H:i:s")."','$api_exp_dtt','$scope','$co_gstin','$api_base_url','$availableApiHits','ewb')"; //echo $ins_q; $api_ins=$mysqli->query($api_ins_q); if(!$api_ins){echo $mysqli->error."
".$api_ins_q;} } }else{ echo "
API Error : ".$response2Json->error[0]->errorMsg; exit; } } } } // else{echo "here ".$api_access_token."||".$api_exp_dtt;;} // if($debug=='y'){ // echo "Line 236 Debug mode API Access Token : ".$api_access_token."||".$api_exp_dtt; // } // Define function to test function _is_curl_installed() { if (in_array ('curl', get_loaded_extensions())) { return true; } else { return false; } } ?>