2015-11-01 48 views
1

我有网站有捐赠页面。在网关注册 招是发送交易请求通过HTTP POST到汇通宝是到URL https://ibank.gtbank.com/GTPay/Tranx.aspx我怎样才能发送请求通过HTTP发布到网址在php

当我提出我的要求我看到显示上述网址的这个页面里面我的捐款页面,而不是把我的URL 以下是我的代码:

$url = 'https://ibank.gtbank.com/GTPay/Tranx.aspx'; 
$fields = array(
     'gtpay_mert_id' => urlencode($gtpay_mert_id), 
     'gtpay_tranx_id' => urlencode($gtpay_tranx_id), 
     'gtpay_tranx_amt' => urlencode($gtpay_tranx_amt), 
     'gtpay_tranx_curr' => urlencode($gtpay_tranx_curr), 
     'gtpay_cust_id' => urlencode($gtpay_cust_id), 
     'gtpay_tranx_noti_url' => urlencode($gtpay_tranx_noti_url), 
     'gtpay_hash' => urlencode($gtpay_hash) 
    ); 


//url-ify the data for the POST 
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
    rtrim($fields_string, '&'); 

    $form_files=array(); 
    $form_options=array('cookies' => array('auth' => $auth)); 
    http_post_fields($url, $fields, $form_files, $form_options); 
//open connection 
    $ch = curl_init(); 

//set the url, number of POST vars, POST data 
    curl_setopt($ch,CURLOPT_URL, $url); 
    curl_setopt($ch,CURLOPT_POST, count($fields)); 
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 

//execute post 
    $result = curl_exec($ch); 

//close connection 
    curl_close($ch); 

回答

0

使用cURL进行的请求不会将您带到URL。它只会处理请求并将数据返回到最后。

您需要使用HTML表单和您的字段提交您的请求。

事情是这样的:

<form action=" https://ibank.gtbank.com/GTPay/Tranx.aspx" method="post"> 

<!-- Saved buttons use the "secure click" command --> 
<input type="hidden" name="cmd" value="_s-xclick"> 

<!-- Saved buttons are identified by their button IDs --> 
<input type="hidden" name="hosted_button_id" value="221"> 

<!-- Saved buttons display an appropriate button image. --> 
<input type="image" name="submit" border="0" 
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" 
alt="PayPal - The safer, easier way to pay online"> 
<img alt="" border="0" width="1" height="1" 
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" > 

</form> 
+0

感谢@harunur。输入的捐赠金额将乘以100,并且要提交的参数gtpay_hash(表单中的隐藏字段)的值应该是表单中以下参数的值的串联值。 gtpay_mert_id,gtpay_tranx_id,gtpay_tranx_amt,gtpay_tranx_curr,gtpay_cust_id,gtpay_tranx_noti_url,hashkey。如何获取表单中输入的值,对这些值执行哈希处理,并将其分配给隐藏的参数,并与表单中输入的其他值一起提交给url? – ali79

+0

在这种情况下,您可以在结帐过程中为用户提供另一种表单。收集所有信息,然后将您的值推送到付款表单并进行javascript表单提交。 –

相关问题