php - 将 CURL_OPTPOST 设置为 true 时,CURL http 身份验证失败

标签 php curl

我正在尝试构建一个与 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 似乎会以某种方式干扰身份验证 header 。我不知道我错过了什么。

已解决:

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

最佳答案

据我所知,您需要一个 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";
    }

关于php - 将 CURL_OPTPOST 设置为 true 时,CURL http 身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10339746/

相关文章:

curl - 将 bitbucket 工件部署到下载

php - SQL 防止重复插入

linux - 远程 curl 错误但本地不 curl

linux - 使用 curl 发送 post json 时出错

php - 从特定键迭代 PHP 数组

php - 错误: Undefined Index php

PHP round(12,2) 显示 12 而不是 12.00

php - curl 给出 403 错误?

javascript - 如何触发 javascript css 操作?

python - PyCurl 已安装但未找到