0

我想通过我的网站处理付款,并希望为此目的使用 sagepay。我已经完成了此处提到的 sagepay go 直接集成指南:http: //www.sagepay.com/sites/default/files/pdf/user_guides/sagepaydirectprotocolandintegrationguidelines_0.pdf 现在,我创建了一个脚本,对处理http请求的字段。这是代码:

<?php
//extract data from the post
extract($_POST);

//set POST variables
$url = 'https://live.sagepay.com/gateway/service/vspdirect-register.vsp';
$txcode = 'prefix_' . time() . rand(0, 9999);
$fields = array(
                        'VPSProtocol'=>urlencode("2.23"),
                        'TxType'=>urlencode("PAYMENT"),
                        'Vendor'=>urlencode("myvendorname"),
                        'VendorTxCode'=>urlencode($txcode),
                        'Amount'=>urlencode("2.00"),
                        'Currency'=>urlencode("GBP"),
                        'Description'=>urlencode("payment for my site"),
                        'CardHolder'=>urlencode('DELTA'),
                        'CardNumber'=>urlencode(4929000000006),
                        'ExpiryDate'=>urlencode(1213),
                        'CV2'=>urlencode(123),
                        'CardType'=>urlencode('VISA'),
                        'BillingSurname'=>urlencode('surname'),
                        'BillingFirstnames'=>urlencode('name'),
                        'BillingAddress1'=>urlencode(' clifton'),
                        'BillingCity'=>urlencode('Bristol'),
                        'BillingPostCode'=>urlencode('BS82UE'),
                        'BillingCountry'=>urlencode('United Kingdom'),
                        'DeliverySurname'=>urlencode('surname'),
                        'DeliveryFirstnames'=>urlencode('name'),
                        'DeliveryAddress1'=>urlencode(' clifton'),
                        'DeliveryCity'=>urlencode('Bristol'),
                        'DeliveryPostCode'=>urlencode('bs82ue'),
                        'DeliveryCountry'=>urlencode('united kingdom'),

                );

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

//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);

//execute post
$result = curl_exec($ch);
print_r($result);
echo "end";
//close connection
curl_close($ch);
?>

但我没有得到任何回复..可能是什么问题?它在 wamp 服务器和非 https url 中。

4

2 回答 2

2

这段代码对我有用。我添加了一些 CURL 函数并删除了一个,这就成功了。

<?php
//extract data from the post
extract($_POST);

//set POST variables
$url = 'https://live.sagepay.com/gateway/service/vspdirect-register.vsp';
$txcode = 'prefix_' . time() . rand(0, 9999);
$fields = array(
                        'VPSProtocol'=>urlencode("2.23"),
                        'TxType'=>urlencode("PAYMENT"),
                        'Vendor'=>urlencode("myvendorname"),
                        'VendorTxCode'=>urlencode($txcode),
                        'Amount'=>urlencode("2.00"),
                        'Currency'=>urlencode("GBP"),
                        'Description'=>urlencode("payment for my site"),
                        'CardHolder'=>urlencode('DELTA'),
                        'CardNumber'=>urlencode(4111111111111111),
                        'ExpiryDate'=>urlencode(1213),
                        'CV2'=>urlencode(123),
                        'CardType'=>urlencode('VISA'),
                        'BillingSurname'=>urlencode('surname'),
                        'BillingFirstnames'=>urlencode('name'),
                        'BillingAddress1'=>urlencode(' clifton'),
                        'BillingCity'=>urlencode('Bristol'),
                        'BillingPostCode'=>urlencode('BS82UE'),
                        'BillingCountry'=>urlencode('United Kingdom'),
                        'DeliverySurname'=>urlencode('surname'),
                        'DeliveryFirstnames'=>urlencode('name'),
                        'DeliveryAddress1'=>urlencode(' clifton'),
                        'DeliveryCity'=>urlencode('Bristol'),
                        'DeliveryPostCode'=>urlencode('bs82ue'),
                        'DeliveryCountry'=>urlencode('united kingdom'),

                );

//url-ify the data for the POST
$fields_string = http_build_query($fields);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);

//execute post
$result = curl_exec($ch);
print_r($result);
echo "end";
//close connection
curl_close($ch);
?>

仅供参考,使用http_build_query()非常适合构建 query_strings。

$fields_string = http_build_query($fields);
于 2012-04-16T01:52:11.070 回答
0

如果您添加字段,此代码将起作用

Crypt='Your encryption password in your account setting in sagepay test';

但是如果您使用 curl 发布它会返回空字符串,并且它将被重定向到

https://test.sagepay.com/gateway/service/cardselection?vpstxid={BDBF098F-9BB5-3822-8CAE-AC0645A2CC57}

如果您使用 Http POST。

祝你好运

于 2015-05-26T01:43:39.773 回答