获取由在线托管的 webhook 生成的 JSON
Get JSON generated by a webhook hosted online
我刷卡支付,然后通过webhook与公司的服务器通信,然后将响应记录在RequestBin中,在他们的网站上生成一个JSON响应,我如何提取从网站到我的 PHP 代码的信息?
该网页如下所示:
my requestb.in online webhook
我需要的是获得原始 JSON。
您可以从 requestbin 获取 json 并使用像 Postman 这样的请求客户端将其重新发送到您的本地主机。
if (!empty($_POST)) {
$data = json_decode($_POST);
}
您可以尝试使用 CURL 检索 JSON 对象。您是否使用 CURL 将支付有效负载发送到处理器等?下面是一个示例(显然,您需要在适用的地方填写适当的 PHP 变量)。
$reqbody = json_encode($_REQUEST);
$serviceURL = "http://www.url.com/payment_processor";
$curl = curl_init($serviceURL);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $reqbody);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$headers = array(
'Content-type: application/json',
"Authorization: ".$hmac_enc,
"apikey: ".$apikey,
"token: ".$token,
"timestamp: ".$timestamp,
"nonce: ".$nonce,
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
die("Error: call to URL $serviceURL failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
echo "<hr/><br/><strong>PROCESSOR RESPONSE:</strong><br/>";
echo "<pre>";
print_r($response);
echo "</pre>";
我找到了解决方案,首先您下载 HTML dom 然后您只需更改字段即可。 for循环从0到19的原因是因为requestb.in保存了20个条目,其余的只需替换变量。
include('../simple_html_dom.php');
// get DOM from URL or file
// asegurese de incluir el ?inspect en el URL
$html = file_get_html('https://requestb.in/YOURURL?inspect');
for ($x = 0; $x <= 19; $x++) {
$result = $html->find('pre[class=body prettyprint]', $x)->plaintext;
if($result){
$json_a = str_replace('"', '"', $result);
$object = json_decode($json_a);
if(isset($object->type)) echo $object->type . "<br>";
if(isset($object->transaction->customer_id)) echo $object->transaction->customer_id . "<br>";
}
}
我刷卡支付,然后通过webhook与公司的服务器通信,然后将响应记录在RequestBin中,在他们的网站上生成一个JSON响应,我如何提取从网站到我的 PHP 代码的信息?
该网页如下所示: my requestb.in online webhook
我需要的是获得原始 JSON。
您可以从 requestbin 获取 json 并使用像 Postman 这样的请求客户端将其重新发送到您的本地主机。
if (!empty($_POST)) {
$data = json_decode($_POST);
}
您可以尝试使用 CURL 检索 JSON 对象。您是否使用 CURL 将支付有效负载发送到处理器等?下面是一个示例(显然,您需要在适用的地方填写适当的 PHP 变量)。
$reqbody = json_encode($_REQUEST);
$serviceURL = "http://www.url.com/payment_processor";
$curl = curl_init($serviceURL);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $reqbody);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$headers = array(
'Content-type: application/json',
"Authorization: ".$hmac_enc,
"apikey: ".$apikey,
"token: ".$token,
"timestamp: ".$timestamp,
"nonce: ".$nonce,
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
die("Error: call to URL $serviceURL failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
echo "<hr/><br/><strong>PROCESSOR RESPONSE:</strong><br/>";
echo "<pre>";
print_r($response);
echo "</pre>";
我找到了解决方案,首先您下载 HTML dom 然后您只需更改字段即可。 for循环从0到19的原因是因为requestb.in保存了20个条目,其余的只需替换变量。
include('../simple_html_dom.php');
// get DOM from URL or file
// asegurese de incluir el ?inspect en el URL
$html = file_get_html('https://requestb.in/YOURURL?inspect');
for ($x = 0; $x <= 19; $x++) {
$result = $html->find('pre[class=body prettyprint]', $x)->plaintext;
if($result){
$json_a = str_replace('"', '"', $result);
$object = json_decode($json_a);
if(isset($object->type)) echo $object->type . "<br>";
if(isset($object->transaction->customer_id)) echo $object->transaction->customer_id . "<br>";
}
}