我正在尝试连接到支付网关,我将下面的表格作为 http 帖子发送:
<form name="submit2gtpay_form" action="" target="_self" method="post">
<input type="hidden" name="gtpay_mert_id" value="17" />
<input type="hidden" name="gtpay_tranx_id" value="" />
<input type="hidden" name="gtpay_tranx_amt" value="5000" />
<input type="hidden" name="gtpay_tranx_curr" value="566" />
<input type="hidden" name="gtpay_cust_id" value="458742" />
<input type="hidden" name="gtpay_cust_name" value="Test Customer" />
<input type="hidden" name="gtpay_tranx_memo" value="Mobow" />
<input type="hidden" name="gtpay_no_show_gtbank" value="yes" />
<input type="hidden" name="gtpay_echo_data" value="TEST" />
<input type="hidden" name="gtpay_gway_name" value="" />
<input type="hidden" name="gtpay_tranx_hash" value="" />
<input type="hidden" name="gtpay_tranx_noti_url" value="" />
<input type="submit" value="Pay Via GTPay" name="btnSubmit"/>
<input type="hidden" name="gtpay_echo_data" value="">
</form>
我需要执行 [gtpay_tranx_id + gtpay_tranx_amt +gtpay_tranx_noti_url + hashkey] 的 sha512 哈希
交易金额应以 kobo 为单位,所有字符串应与 hashkey 连接在一起,然后才能获取整个字符串的 sha512 哈希。
但是 gtpay_tranx_hash 的值是一个变量,我该怎么做,因为当我回显它时,我得到了缺失值
请任何帮助将不胜感激
<?php
//the has key requested
$key = hash('sha512','664879809+500000+myurl+thekeytheysupply');
//create array of data to be posted
$post_data['gtpay_mert_id'] = 3649;
$post_data['gtpay_tranx_id'] = 664879809;
$post_data['gtpay_tranx_amt'] = 500000;
$post_data['gtpay_tranx_curr'] = 566;
$post_data['gtpay_cust_id'] = 458742;
$post_data['gtpay_cust_name'] = 'Test Customer';
$post_data['gtpay_tranx_memo'] = 'Mobow';
$post_data['gtpay_no_show_gtbank'] = 'yes';
$post_data['gtpay_echo_data'] ='TEST';
$post_data['gtpay_tranx_hash'] = $key;
$post_data['gtpay_tranx_noti_url'] = 'mynotificationurl';
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//usrl
$url = 'thebankurl';
$ch = curl_init(); //initialize curl handle
// enable below 2 linesfor https sites
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url); //set the url
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //return as a variable
//curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1); //set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); //set the POST variables
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$response = curl_exec($ch); //run the whole process and return the response
curl_close($ch); //close the curl handle