我有这个问题。我有这个表格
<form action="https://ipg.e-biner.com:7000/bayaro/GetToken" name="" method="post">
<input type="hidden" name="username" value="av" />
<input type="hidden" name="password" value="a" />
<input type="hidden" name="total" value="25000" />
<input type="hidden" name="items" value="a" />
<input type="hidden" name="trxid" value="12345678" />
<input type="hidden" name="voucher_code" value="" />
<input type="hidden" name="successUrl" value=""/>
<input type="hidden" name="failedUrl" value=""/>
<input type="submit" value="Checkout" />
</form>
响应可能是JSON格式,如{“token”:“20170214111050614349”,“trxid”:“123803742384723874”,“validthru”: “1487345450”, “RC”: “0”}
我需要使用该响应中的令牌号到另一个php文件。这是我的代码,我知道这可能是某种错误。
if (isset($_POST['Checkout']))
{ ?>
<?php
//JSON URL which should be requested
$json_url = 'https://ipg.e-biner.com:7000/bayaro/GetToken';
$ch = curl_init( $json_url );
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
CURLOPT_POSTFIELDS => $jsonstring
);
curl_setopt_array( $ch, $options ); //Setting curl options
$result = curl_exec($ch); //Getting jSON result string
$jsonstring=file_get_contents($json_url);
$decode = json_decode($result, true);
foreach($decode as $row){
echo $row;
}
?>;
<script type="text/javascript">
window.location = "New.php";
</script>
<?php } ?>;
这是我想要提供令牌的另一个php文件
<?php
$row=(isset ($_GET['token']));
?>
<form action="https://ipg.e-biner.com:7000/bayaro/Pay" method="post">
<input type="hidden" value='token' name="token" />
<input type="submit" value="Submit" />
</form>
答案 0 :(得分:0)
试试这样..
$decode = json_decode($result, true);
$token = $decode['token'];
?>
<script type="text/javascript">
var token = <?php echo $token;?>
window.location = "New.php?token="+token;
</script>
在另一个php文件中
<?php
$token= $_GET['token'];//get value
?>
<form action="https://ipg.e-biner.com:7000/bayaro/Pay" method="post">
<input type="hidden" value='<?php echo $token;?>' name="token" />
<input type="submit" value="Submit" />
</form>