[英]How is an api call made to an endpoint?
我正在尝试将一个托管支付系统集成到我正在进行的项目中,但是对于这种情况有多么困惑.Newbie
我已经在我的页面中设置了类似于条带的其他要求的内联付款。
现在它与解决托管付款有关,并且这样做当资金在托管时,我想结算卖方以获得我需要调用结算终点的资金。 https://ravesandboxapi.flutterwave.com/v2/gpx/transactions/escrow/settle
这是一个示例请求
{
"id": "348813", // this is the txid value returned in the v2/verify response.
"secret_key": "FLWSECK-*************************-X" // your merchant secret key.
}
这是一个示例响应
{
"status": "success",
"message": "SUCCESS",
"data": "Transaction settled"
}
如何使用上面的api调用。
看看Guzzle。 这是一个非常简单的PHP包来处理API路由。
http://docs.guzzlephp.org/en/stable/
$client = new GuzzleHttp\Client(['base_uri' => 'https://ravesandboxapi.flutterwave.com']);
$response = $client->request('GET',
'/v2/gpx/transactions/escrow/settle',
['json' => ['id' => '348813', 'secret_key' => 'KEY']
);
$body = $response->getBody();
$responseData = $body->getContents();
使用PHP时,我总是使用像我这样的函数,我发现它非常有用。 我认为这是非常自我解释,但如果您需要进一步的帮助,请告诉我。
function CallAPI($method, $url, $data, $id, $secret_key) {
$headers = [
"Content-type: application/json",
"id: ".$id,
"secret_key: " .$secret_key
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
switch ($method) {
case "GET":
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
break;
case "POST":
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
break;
case "PUT":
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
break;
case "DELETE":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
break;
}
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_HEADER => false, //return headers in addition to content
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 30, // timeout on connect
CURLOPT_TIMEOUT => 30, // timeout on response
CURLOPT_NOBODY => 0, // timeout on response
CURLOPT_MAXREDIRS => 9, // stop after 10 redirects
CURLINFO_HEADER_OUT => true,
CURLOPT_SSL_VERIFYPEER => true, // Disabled SSL Cert checks
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPHEADER => $headers
));
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
只需使用guzzle库。 我为任何项目中使用的API调用做了一个简单的样板
https://gist.github.com/afiqiqmal/777fc6383ffce11113dc379094ee18b4
样品使用
$result = (new ApiRequest())
->baseUrl("https://ravesandboxapi.flutterwave.com")
->setHeader([
'id' => $id,
'secret_key' => $secretKey
])
->requestUrl("v2/gpx/transactions/escrow/settle")
->fetch();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.