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` FROM `gsp_auth` WHERE `co_gstin`='".$co_gstin."' AND `gsp_exp`>'$nxt1min' 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"]; } if($gsp_access_token=='not_set'){ $q40="SELECT * FROM `gsp_details` WHERE `co_gstin`='".$co_gstin."' AND `gsp_status`='active' 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"]; } // // $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(); //CURLOPT_URL => 'http://qa.gsthero.com/auth-server/oauth/token', 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=einvauth', CURLOPT_HTTPHEADER => array( 'Content-Type: application/x-www-form-urlencoded', 'gstin: '.$co_gstin.'', 'Accept: application/json', 'Authorization: '.$gsp_authorisation.'' ), )); $response = curl_exec($curl); curl_close($curl); // echo $response."
"; $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`) 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')"; //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.
"; } } if($debug=='y'){ echo "$gsp_access_token
$exp_dtt/$gsp_exp"; } // Define function to test function _is_curl_installed() { if (in_array ('curl', get_loaded_extensions())) { return true; } else { return false; } } ?>