尝试使用/ PHP通过Localhost上的API访问First Data的WSDL

时间:2011-10-04 01:11:16

标签: php api soap curl wsdl

首先,让我说我对SOAP / WSDL / API相对较新,所以这篇文章有点冗长,因为我不知道什么是正在发生的。过去几个小时我一直在谷歌搜索,没有运气。我希望有人能指出我正确的方向,以便继续前进。

我正在尝试使用FirstData的API来制作PHP支付脚本。我在使用PHP通过其API访问WSDL时遇到问题。我的卷曲是(基于他们的documentation):

$wsdl = "https://ws.merchanttest.firstdataglobalgateway.com/fdggwsapi/services/order.wsdl";

$userid = "WSxxxxxxxxxxx._.1";
$password = "xxxxxxxxxx";
$pemlocation = realpath("WSxxxxxxxxxx._.1.pem");
$kslocation = realpath("WSxxxxxxxxxx._.1.key");
$keyname = "ckp_xxxxxxxx";

$transactiontype = "sale";
$creditcardnumber = "4111111111111111";
$cardexpirationmonth = "10";
$cardexpirationyear = "12";
$chargetotal = "1";

$body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$body .= "<SOAP-ENV:Envelope xmlns:SOAP-    ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">";
$body .= "<SOAP-ENV:Header />";
$body .= "<SOAP-ENV:Body>";
$body .= "<fdggwsapi:FDGGWSApiOrderRequest xmlns:fdggwsapi= \"http://secure.linkpt.net/fdggwsapi/schemas_us/fdggwsapi\">";
$body .= "<v1:Transaction xmlns:v1= \"http://secure.linkpt.net/fdggwsapi/schemas_us/v1\">";
$body .= "<v1:CreditCardTxType>";
$body .= "<v1:Type>";
$body .= $transactiontype;
$body .= "</v1:Type>";
$body .= "</v1:CreditCardTxType>";
$body .= "<v1:CreditCardData>";
$body .= "<v1:CardNumber>";
$body .= $creditcardnumber;
$body .= "</v1:CardNumber>";
$body .= "<v1:ExpMonth>";
$body .= $cardexpirationmonth;
$body .= "</v1:ExpMonth>";
$body .= "<v1:ExpYear>";
$body .= $cardexpirationyear;
$body .= "</v1:ExpYear>";
$body .= "</v1:CreditCardData>";
$body .= "<v1:Payment>";
$body .= "<v1:ChargeTotal>";
$body .= $chargetotal;
$body .= "</v1:ChargeTotal>";
$body .= "</v1:Payment>";
$body .= "</v1:Transaction>";
$body .= "</fdggwsapi:FDGGWSApiOrderRequest>";
$body .= "</SOAP-ENV:Body>";
$body .= "</SOAP-ENV:Envelope>";

$ch = curl_init($wsdl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$userid:$password");
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSLCERT, $pemlocation);
curl_setopt($ch, CURLOPT_SSLKEY, $kslocation);
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $keyname);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);

返回HTTP Status 401 - type: Status report | description: This request requires HTTP authentication (). | JBossWeb/2.0.0.GA。根据他们的文档OpenSSL,需要SSL certificateTCP Port 1129。由于我没有得到任何回报,我认为这是因为我的OpenSSL没有在我的XAMPP上设置。如果这没有意义(?)跳过下一位。

我尝试在XAMPP下的apache中设置我的SSL。 xampp\apache\makecert收益:

Unable to load config info from ./bin/openssl.cnf
Error opening Private Key privkey.pem
6264:error:02001002:system library:fopen:No such file or directory:.\crypto\bio\bass_file.c:356:fopen('privkey.pem','rb')
6264:error:20064002:BIO routines:FILE_CTRL:system lib:.\crypto\bio\file.c:358:unable to load Private Key
Loading 'screen' into random state - done
server.csr: No such file or directory
Could Not Find c:\xampp\apache\.rnd
Could Not Find c:\xampp\apache\prikey.pem
Could Not Find c:\xampp\apache\server.csr
The system cannot find the file specified.
The system cannot find the file specified.

我的openssl.cnf位于@ c:\xampp\php\extras\openssl\openssl.cnf。我做了一个有效的openssl req -new -key digitss.key -out digitss.csr -config "c:\xampp\php\extras\openssl\openssl.cnf",但最后什么也没做。我不确定如何让SSL运行。

无论如何,如果有人能够对我的问题有所启发,我会非常感激。我不知道它是我的PHP,$body var,还是我尝试在没有SSL(或所有3的组合)的情况下访问WSDL的事实。我已经看到了我使用的代码的一些变体,所以我认为它是正确的。我有一个FirstData设置的试用帐户,以及我可以发送给任何人的.pem和.key文件,如果他们想帮我调查一下。我完全失去了!

提前致谢,

1 个答案:

答案 0 :(得分:1)

我相信你混淆了First Data API。

有2个First Data API:

  • First Data Global Gateway API 2
  • First Data Global Gateway Web服务API

Web服务API通过端口443发送,遗留API通过端口1129发送。

您希望在curl请求中使用端口443作为上面列出的代码。