我需要创建一个像$json = json_encode(array($CaseID), JSON_FORCE_OBJECT);
这样的PHP json对象并通过cURL发布它,但是我的代码:
"{"0":"15876285"}"
返回表示关联数组的字符串public function RetrieveCase($CaseID) {
$json = json_encode(array($CaseID), JSON_FORCE_OBJECT);
//*** FOR DEBUG ONLY
$f = fopen('sti_error.log', 'w');
$curl = curl_init($this->signifyd_api_endpoint);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($json)));
curl_setopt($curl, CURLOPT_USERPWD, $this->signifyd_trans_key . ":");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Return response instead of printing.
curl_setopt($curl, CURLOPT_TIMEOUT, 3);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($curl, CURLOPT_VERBOSE, 1); //** FOR DEBUG ONLY
curl_setopt($curl, CURLOPT_STDERR, $f);
curl_setopt($curl, CURLOPT_HEADER, 1); //** FOR DEBUG ONLY
curl_setopt($curl, CURLINFO_HEADER_OUT, true); //** FOR DEBUG ONLY
//** For debg only
$fp = fopen ("sti_output.log", "w") or die("Unable to open stdout for writing.\n");
curl_setopt($curl, CURLOPT_FILE, $fp);
$response = curl_exec($curl);
if (!$response) {
$this->session->data['error'] = 'SIGNIFYD RetrieveCase failed: ' . curl_error($curl) . '(#' . curl_errno($curl) . ')';
curl_close($curl);
return false;
}
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
fclose($f);
//$this->load->language('payment/signifyd_transaction_investigation');
// HHTP Status Code 201 CREATED - The resource requested was successfully created.
if ($httpcode != '201') {
return $this->getCase($response);
}
$this->session->data['error'] = 'SIGNIFYD RetrieveCase failed response: ' . $response;
return false; }
。
{{1}}
答案 0 :(得分:0)
这是该方法的工作版本。您还可以在https://github.com/mdutra555/SIGNIFYD_API_OpenCart_Model
中查看完整的课程public function RetrieveCase($CaseID) {
//** From SIGNIFYD API Docs
// GET https://api.signifyd.com/v2/cases/{CASE_ID} ****** beware of this {CASE_ID} notation, the {} curly-brackets must not be used.
// Plese note that "Retrieving a case" uses GET, unlike "Creating a new case" uses POST method.
$url = $this->signifyd_api_endpoint . '/' . $CaseID;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, 'Content-Type: application/json');
curl_setopt($curl, CURLOPT_USERPWD, $this->signifyd_trans_key . ":");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // Use 1 for curl_exec() to return the response header + content. DO NOT USE true boolean, it will not work.
curl_setopt($curl, CURLOPT_TIMEOUT, 3);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);
$response = curl_exec($curl);
if (!$response) {
$this->session->data['error'] = 'SIGNIFYD RetrieveCase failed: ' . curl_error($curl) . '(#' . curl_errno($curl) . ')';
curl_close($curl);
return false;
}
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
// HHTP Status Code 200 OK - The resource requested was successfully returned.
if ($httpcode == '200') {
return $this->getCase($response);
}
$this->session->data['error'] = 'SIGNIFYD RetrieveCase failed response: ' . $response;
return false;
}