2017-05-12 42 views

回答

0

我找到了解決方案,首先你下載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('&#34;', '"', $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>"; 
     } 

    } 
0

您可以從requestbin獲取json,並使用Postman等請求客戶端將其重新發送到本地主機。

if (!empty($_POST)) { 
    $data = json_decode($_POST); 
} 
+0

我在哪裏或如何指定URL和我需要什麼參數$ _POST,我真的在零,我不知道如何解決這個問題。 –

1

您可以嘗試使用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>";