Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建php和curl回调函数_Php_Web Services_Curl - Fatal编程技术网

创建php和curl回调函数

创建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

我正在尝试从服务器获取发送时的post响应,并更新我的数据库。到目前为止,我的代码只在通过浏览器运行时得到响应,但它没有从服务器获得任何进一步的响应。这是我目前的代码:

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所做的一样。这个网站不是为了帮助理解概念。当你有需要解决的具体问题时,请回来找我们。