I am trying to gain a token via the android paypal sdk. I created this cURL inside a php script, but I am unable to update my tkn column in my 000webhost database. The script is called from my app, but I think there might be something wrong with the script. Please let me know if you see anything wrong. Also, it might be that 000webhost does not allow cURL scripts. Please advise. On last minute, one thing that I noticed is that the variable "idclient" and "sekret" are not set as strings. Perhaps this is the problem. Please see if there are any other problems you might encounter.
Here's my script with the cURL:
<?php
require "quimasetup.php";
$name = $_POST["name"];
$email = $_POST["email"];
$phone_number= $_POST["phone_number"];
$subject= $_POST["subject"];
$grade= $_POST["grade"];
$payment_id = $_POST["payment_id"];
$idclient = AVe40dqVhDDmGDbLhNEkH6G9eWyvgrqPrkKAucGv;
$sekret = ELQ595K9VZyfQcJuj7pw1yPVVv7OnNw;
$ch = curl_init("https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch,CURLOPT_HEADER,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $idclient.":".$sekret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
curl_close($ch);
$json = json_encode($result);
$jsonn = json_decode($json);
$tkn = $jsonn->access_token;
$sql = "insert into craddle values('$name','$email','$phone_number','$subject','$grade','$payment_id','$tkn');";
if (isset($tkn)){
if(mysqli_query($connection,$sql)){
echo "<br><h3>one row inserted...</h3>";
}
else{
echo "Error in insertion...".mysqli_error($connection);
}
}
else{
var_dump($json);
var_dump($jsonn);
var_dump($tkn);
}
?>
Related
I am sending push notes from a PHP script. They are received twice on all my devices, so this is not a question of a wrong setup in one of my devices. OTOH, if I send a push notice from one of my devices to another, it appears only once.
I cannot figure out why this is happening and hope someone else has the right idea. The script looks ok to me.
<?php
$qs = $_SERVER['QUERY_STRING']; // get query string like "bookid=35954441&status=modify"
if ($qs ==""){
$qs = 'no message';
}
date_default_timezone_set('America/Panama');
$today = date('d/m/Y H:i:s',$_SERVER['REQUEST_TIME']);
$data = array();
$data['type'] = 'note';
$data['title'] = 'Aparthotel Boquete - '.$today;
$data['body'] = "· ". str_replace("&"," \n· ",$qs) ;
$json = json_encode($data);
$url="https://api.pushbullet.com/v2/pushes";
$ch=curl_init();
curl_setopt($ch, CURLOPT_POST, 1) ;
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ##################', 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$Json_object = curl_exec($ch); // this is a JSON string
$result = json_decode(curl_exec($ch),true); // creates an associative 2 dimensional array $booking[i]['key'] where i= booking index
curl_close ($ch);
?>
var_dump of the JSON object shows this among other items:
,"created":1674359389.1863782,"modified":1674359389.1906438,
This could be a hint. Maybe the push note is created (and sent), and then sent again as "modified"? But why? Is any of the CURL options the cause?
I just found the answer myself after several tests. While the script is executed only once, the CURL call was run a second time when I decoded the result:
.....
$Json_object = curl_exec($ch); // <== first execution
$result = json_decode(curl_exec($ch),true); // <== second execution
curl_close ($ch);
Thank you for your hint, ADyson. I am glad I found it fast enough not to waste more people's time. I let it stand anyway, hoping that it may help others to discover similar errors.
I'm new here so please be patient, This is my request code, I want to write another piece of code in another server that will be accepting it and returning an xml 7101 success code using php and curl. How do I write code in a receiving server. This is actually API that I will be using to exchange data between my system and another remote system stored in clouds I have managed to send request successfully but I have stuck at receiving their requests, I have spent an entire week on it please help me out on receiving the requests when they send them to me.
success code is
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gepgBillSubReqAck>
<TrxStsCode>7101</TrxStsCode>
</gepgBillSubReqAck>
the request code is this,
<?php
//Bill Request
$content ="<gepgBillSubReq>
<BillHdr>
<SpCode>SP103</SpCode>
<RtrRespFlg>true</RtrRespFlg>
</BillHdr>
<BillTrxInf>
<BillId>1812022009968</BillId>
<SubSpCode>1001</SubSpCode>
<SpSysId>TANESCO001</SpSysId>
<BillAmt>1180</BillAmt>
<MiscAmt>0</MiscAmt>
<BillExprDt>2017-12-31T23:59:59</BillExprDt>
<PyrId>5144AA5914</PyrId>
<PyrName>test</PyrName>
<BillDesc>Bill Number 5913</BillDesc>
<BillGenDt>2017-12-21T09:39:00</BillGenDt>
<BillGenBy>Bhstenkubo</BillGenBy>
<BillApprBy>Bhstenkubo</BillApprBy>
<PyrCellNum/>
<PyrEmail/>
<Ccy>TZS</Ccy>
<BillEqvAmt>1180</BillEqvAmt>
<RemFlag>false</RemFlag>
<BillPayOpt>1</BillPayOpt>
<BillItems>
<BillItem>
<BillItemRef>5144AA5914</BillItemRef>
<UseItemRefOnPay>N</UseItemRefOnPay>
<BillItemAmt>1180</BillItemAmt>
<BillItemEqvAmt>1180</BillItemEqvAmt>
<BillItemMiscAmt>0</BillItemMiscAmt>
<GfsCode>140316</GfsCode>
</BillItem>
</BillItems>
</BillTrxInf>
</gepgBillSubReq>";
$resultCurlPost = "";
$serverIp = "XXXXXXXXXXXXXXXX";
$uri = "/XXX/XXX/qrequest"; //this is for qrequest
echo "Message ready to GePG:"."\n".$content."\n";
$ch = curl_init($serverIp.$uri);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/xml',
'Gepg-Com:default.sp.in',
'Gepg-Code:SP103',
'Content-Length:'.strlen($content))
);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50);
//Capture returned content from GePG
$resultCurlPost = curl_exec($ch);
curl_close($ch);
//$resultCurlPost=$data;
if(!empty($resultCurlPost)){
echo "\n\n";
echo "Received Response\n";
echo $resultCurlPost;
echo "\n";
}
else
{
echo "No result Returned"."\n";
}
?>
Thanks, you guys for contributing I found a solution, I used file_get_contents("php://input"); on the receiving server and so far it is working fine.
I am trying to write a PHP script that post username and password as JSON object to a server and in response get a JSON object that contains UserId and token in JSON.
Following is my code
if (isset($_GET["user"]) && isset($_GET["key"])){
$username = $_GET["user"];
$pass = $_GET["key"];
$data = array("username" => $username, "password" => $pass);
$data_string = json_encode($data);
echo $data_string;
$ch = curl_init('https://sce15.appspot.com/api/g_usrs/signin');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($ch);
curl_close($ch);
$usr = json_decode($response, true);
echo $usr;
}
else{
echo "Oops Something went wrong: Error 1";
}
But I am not getting anything in output, my browser window is white blank. I am not able to figure out the mistake. I am able to get JSON object when using javascript for the same URL, but I need to do it with PHP.
Any help is appreciated. Thanks
I finally pointed out the problem after 2 days of head banging on google. It was the SSL certificate error, CURL was not able to verify the SSL certificate.
I got to knew that after checking curl errors print_r(curl_error($ch));
And then by using the curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); i was able to disable SSL certificate security check. Although it made my connection insecure but i think that's not important in my case.
Thanks Everyone
Please am creating a web application that sends sms alert when a user is registered. i wrote the script to do that which is below, i then uploaded that file to my web server for testing but it refuse to work. am actually having issues understanding curl. can someone tell me what am not doing right?
<?php
$number='08166848961';
$message_body='my test from server';
echo CURLsendsms($number,$message_body);
function CURLsendsms($number, $message_body){
$type='0';
$routing='3';
$token = 'VMnzTxbzgFKs5Po2vt6BhVt6VSWWNSDuaKAeI4Nch2cL4USf6furZ7ckVSc4Qf8jk';
$api_params ='message='.$message_body.'&to='.$number.'&sender='.$number.'&type='.$type.'&routing='.$routing.'&token='.$token;
$smsGatewayUrl = "https://smartsmssolutions.com/api/?";
$smsgatewaydata = $smsGatewayUrl.$api_params;
$url = $smsgatewaydata;
$ch = curl_init(); // initialize CURL
curl_setopt($ch, CURLOPT_POST, false); // Set CURL Post Data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch); // Close CURL
// Use file get contents when CURL is not installed on server.
if(!$output){
return $output = file_get_contents($smsgatewaydata);
}else
}
?>
I am creating a web service. I have tried to write an URL but its throwing error. I am not getting where I am going wrong. I want to pass these variable values in url and depending on this i want to call the web service
<?php
if($_POST["occupation"] == '1'){
$occupation = 'Salaried';
}
else{
$occupation = 'Self+Employed';
}
$url = 'http://www.aaa.com/ajaxv2/getCompareResults.html?interestRateType='.$_POST["interestRateType"]'.&occupation='.$_POST["occupation"].'&offeringTypeId='.$_POST["offeringID"].'&city='.$_POST["city"].'&loanAmt='.$_POST["loanAmt"].'&age='.$_POST["age"];
echo $url;
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
$json = json_decode($result, true);
//print_r($json);
//echo $json['resultList']['interestRateMin'];
$json_array = $json['resultList'];
print_r($json_array);
?>
Try below code. You have syntax error before &occupation
$url = 'http://www.aaa.com/ajaxv2/getCompareResults.html?interestRateType='.$_POST["interestRateType"].'&occupation='.$_POST["occupation"].'&offeringTypeId='.$_POST["offeringID"].'&city='.$_POST["city"].'&loanAmt='.$_POST["loanAmt"].'&age='.$_POST["age"];
Copy this because there is some ' and . error
$url = 'http://www.aaa.com/ajaxv2/getCompareResults.html?
interestRateType='.$_POST["interestRateType"].'&
occupation='.$_POST["occupation"].'&
offeringTypeId='.$_POST["offeringID"].'&
city='.$_POST["city"].'&
loanAmt='.$_POST["loanAmt"].'&
age='.$_POST["age"];