创建php和curl回调函数
我正在尝试从服务器获取发送时的post响应,并更新我的数据库。到目前为止,我的代码只在通过浏览器运行时得到响应,但它没有从服务器获得任何进一步的响应。这是我目前的代码:创建php和curl回调函数,php,web-services,curl,Php,Web Services,Curl,我正在尝试从服务器获取发送时的post响应,并更新我的数据库。到目前为止,我的代码只在通过浏览器运行时得到响应,但它没有从服务器获得任何进一步的响应。这是我目前的代码: if($ch !== false){ curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); //Attach our encoded JSON s
if($ch !== false){
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Set the content type to application/json
// curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;odata=verbose',
'Content-length:' . strlen($jsonDataEncoded))
);
}
//Execute the request
$result = curl_exec($ch);
if ($result === false){
curl_close($ch);
echo "Error".curl_errno($ch). "\n";
}
else {
curl_close($ch);
$decoded = json_decode($result, true);
$data['unique_id'] = $decoded["clientCorrelator"];
$data['subscriber_number'] = $decoded["endUserId"];
$data['payment_status'] = $decoded["transactionOperationStatus"];
$data['payment_gross'] = $decoded["paymentAmount"]["totalAmountCharged"];
$data['txn_id'] = $decoded["ecocashReference"];
$this->payments->insertTransaction($data);
die;
}
你能给我举一个最简单的例子来说明这个行为吗?这就是我的全部,它仍然是一个概念。基本上,我的问题是如何获取服务器以json格式发送的任何内容,就像paypal IPN所做的一样。这个网站不是为了帮助理解概念。当你有需要解决的具体问题时,请回来找我们。