2

我正在尝试构建一个与 Firstdata 的 api 集成的支付表单。我需要将 XML 字符串发布到他们的服务器。它们还需要客户端证书和 http 身份验证。我的 CURL 设置目前如下所示:

function firstdata_send($config_param, $data) {
  $config_default = array(
    'test' => FALSE,
  );
  // settings in $config_param will overwrite settings in $config_default
  $config = (object)array_merge($config_default, $config_param);

  if($config->test) {
    $url = 'https://ws.merchanttest.firstdataglobalgateway.com/fdggwsapi/services/order.wsdl';
  }
  else {
    $url = 'https://ws.firstdataglobalgateway.com/fdggwsapi/services/order.wsdl';
  }

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_POST, TRUE);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, "{$config->username}:{$config->password}");
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_SSLCERT, $config->pemfile);
  curl_setopt($ch, CURLOPT_SSLKEY, $config->keyfile);
  curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $config->keypass);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_HEADER, TRUE);
  curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
  $result = curl_exec($ch);
  $result .= curl_error($ch);
  return $result;
}

他们的服务器以HTTP/1.1 401 Unauthorized. 但是,如果我注释掉帖子选项:

  //curl_setopt($ch, CURLOPT_POST, TRUE);
  //curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

我明白了HTTP/1.1 200 OK。除非我完全误解了发生了什么,否则使用 post 似乎会以某种方式干扰 auth 标头。我不知道我错过了什么。

解决了:

结果证明测试帐户生成的 ssl 证书很糟糕。我不得不打电话给他们的技术支持,他们必须重新生成证书 3 次,然后系统才会接受它们。很抱歉浪费您的时间。我应该先打电话给他们。如果有人感兴趣,我拨打的技术支持号码是 (888) 477-3611。我认为 NomikOS 最接近正确,所以我会将他标记为答案,并投票给你们其他人。再次感谢。

4

3 回答 3

2

形成我认为您需要格式certificate才能pem使用此服务....

A. 下载 API https://www.firstdata.com/downloads/customerservice/30006_api_php.zip

B. 你会看到很多例子

示例销售信息

    include"lphp.php";
    $mylphp=new lphp;

    $myorder["host"]       = "secure.linkpt.net";
    $myorder["port"]       = "1129";
    $myorder["keyfile"]    = "./YOURCERT.pem"; # Change this to the name and location of your certificate file 
    $myorder["configfile"] = "1234567";        # Change this to your store number 

    $myorder["ordertype"]    = "SALE";
    $myorder["result"]       = "LIVE"; # For a test, set result to GOOD, DECLINE, or DUPLICATE
    $myorder["cardnumber"]   = "4111-1111-1111-1111";
    $myorder["cardexpmonth"] = "01";
    $myorder["cardexpyear"]  = "05";
    $myorder["chargetotal"]  = "9.99";

    $myorder["addrnum"]   = "123";   # Required for AVS. If not provided, transactions will downgrade.
    $myorder["zip"]       = "12345"; # Required for AVS. If not provided, transactions will downgrade.
//  $myorder["debugging"] = "true";  # for development only - not intended for production use


  # Send transaction. Use one of two possible methods  #
//  $result = $mylphp->process($myorder);       # use shared library model
    $result = $mylphp->curl_process($myorder);  # use curl methods


    if ($result["r_approved"] != "APPROVED")    // transaction failed, print the reason
    {   
        print "Status: $result[r_approved]\n";
        print "Error: $result[r_error]\n";
    }
    else
    {   // success
        print "Status: $result[r_approved]\n";
        print "Code: $result[r_code]\n";
        print "OID: $result[r_ordernum]\n\n";
    }
于 2012-04-26T19:44:57.070 回答
1

检查您的访问凭据(用户名、密码)

401未经授权

该请求需要用户身份验证。响应必须包含一个 WWW-Authenticate 头字段(第 14.47 节),其中包含适用于所请求资源的质询。客户端可以使用合适的授权头域重复请求(第 14.8 节)。如果请求已包含授权凭证,则 401 响应指示已拒绝对这些凭证的授权. 如果 401 响应包含与先前响应相同的质询,并且用户代理已经尝试了至少一次身份验证,则应该向用户呈现响应中给出的实体,因为该实体可能包含相关的诊断信息。HTTP 访问身份验证在“HTTP 身份验证:基本和摘要式访问身份验证”[43] 中进行了说明。

来源:http ://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2

==

OBS:我建议您使用此代码检查错误

// check for errors before close
$result = curl_exec($ch);
if ($result === false)
{
    echo curl_error($ch);
}
curl_close($ch);
于 2012-04-26T19:15:52.130 回答
1

刚刚检查过 First Datas API 是一个基于 SOAP 的 API ...

wsdl 的 url 只接受 GET,因为 wsdl 只是用于发送 soap 调用的 xml 指令集。

PHP 肥皂客户端类

于 2012-04-26T19:39:24.037 回答