gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:22:38 25 4
gpt4 key购买 nike

我正在尝试构建一个与 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 header 。我不知道我错过了什么。

解决了:

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

最佳答案

形成我认为您需要 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";
}

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com