好的 authorize.net PHP 库

Posted

技术标签:

【中文标题】好的 authorize.net PHP 库【英文标题】:Good authorize.net PHP libraries 【发布时间】:2010-11-15 14:56:25 【问题描述】:

我正在开发一个 php 项目,正在寻找一个好的 authorize.net 网关。我想要一些经过测试的成熟代码。目标是避免自己根据 authorize.net api 文档编写和测试整个事情。

有谁知道这方面有什么好的 PHP 库吗?我用谷歌搜索无济于事。

【问题讨论】:

【参考方案1】:

Authorize.net 提供自己的SDK for PHP and other languages。可能没有必要去别处看看。

【讨论】:

当我最初问这个问题时,我不确定他们是否提供了这些......只有一个规范。 :) @markwatson 我确定这不是因为我在同一时间实现了一个,如果他们有 SDK 我会使用它:) 我查看了他们的 SDK....并决定实现我自己的。他们的 SDK 比普通的 REST API 集成更令人困惑。【参考方案2】:

你很幸运。这是我使用的(用于 SIM 网关):

include("../../simdata.php");
...
<!--form action="https://test.authorize.net/gateway/transact.dll" method="POST"-->
<FORM action="https://secure.authorize.net/gateway/transact.dll" method="POST">
<?
$x_description = "website.com";
$currency = "";
$tstamp = time();
// Seed random number for security and better randomness.
srand(time());
$sequence = rand(1, 1000);
$data = "$x_loginid^$sequence^$tstamp^$total^$currency";
#echo "data = $data\n";
#echo $x_tran_key;
$fingerprint = bin2hex(mhash(MHASH_MD5, $data, $x_tran_key));
# php 5 only $fingerprint = hash_hmac("md5", $data, $x_tran_key);
echo ("<input type='hidden' name='x_fp_sequence' value='" . $sequence . "'>\n" );
echo ("<input type='hidden' name='x_fp_timestamp' value='" . $tstamp . "'>\n" );
echo ("<input type='hidden' name='x_fp_hash' value='" . $fingerprint . "'>\n" );
echo ("<input type=\"hidden\" name=\"x_description\" value=\"" . $x_description . "\">\n" );
echo ("<input type=\"hidden\" name=\"x_login\" value=\"$x_loginid\">\n");
echo ("<input type=\"hidden\" name=\"x_amount\" value=\"$total\">\n");

?>
<input type="hidden" name="x_first_name" value="<?=firstName($_SESSION['user']['name'])?>">
<input type="hidden" name="x_last_name" value="<?=lastName($_SESSION['user']['name'])?>">
<input type="hidden" name="x_company" value="<?=$_SESSION['user']['company']?>">
<input type="hidden" name="x_address" value="<?=$_SESSION['user']['address']?>">
<input type="hidden" name="x_city" value="<?=$_SESSION['user']['city']?>">
<input type="hidden" name="x_state" value="<?=$_SESSION['user']['state']?>">
<input type="hidden" name="x_zip" value="<?=$_SESSION['user']['zip']?>">
<input type="hidden" name="x_phone" value="<?=$_SESSION['user']['phone']?>">
<input type="hidden" name="x_email" value="<?=$_SESSION['user']['email']?>">
<input type="hidden" name="x_cust_id" value="<?=$_SESSION['user']['username']?>">
<INPUT TYPE="HIDDEN" name="x_logo_url" VALUE= "https://secure.authorize.net/mgraphics/logo_99999.gif">
<INPUT type="hidden" name="x_show_form" value="PAYMENT_FORM">
<!--INPUT type="hidden" name="x_test_request" value="TRUE"-->

<!--input type="hidden" name="x_receipt_link_method" value="POST">
<input type="hidden" name="x_receipt_link_text" value="Click for listings">
<input type="hidden" name="x_receipt_link_url" value="http://website.com/confirmation.php"-->

<input type="hidden" name="x_relay_response" value="TRUE">
<input type="hidden" name="x_relay_url" value="http://website.com/confirmation.php">
<input type="hidden" name="<?=session_name()?>" value="<?=session_id()?>">

<input type="hidden" name="" value="">
<input type="hidden" name="" value="">
<input type="hidden" name="" value="">
<? if ($total==0)  ?>
    <a href="account.php">Your Account</a>
<?  else  ?>
    <INPUT type="submit" value="Accept Order">
<?  ?>
</form> 

这就是我用于确认的.php

include("../../simdata.php");
#print_r($_POST);

// verify transaction comes from authorize.net and save user details
$responseCode = $_POST['x_response_code'];
if ( $responseCode == 1)  // approved
    $md5 = $_POST['x_MD5_Hash'];
    $transId = $_POST['x_trans_id'];
    $amount = $_POST['x_amount'];
    $myMD5 = strtoupper(md5("$x_tran_key$x_loginid$transId$amount"));
    #echo $myMD5;
    #print_r ($_POST);
    #print_r ($_SESSION['user']);

    if ($myMD5 == $md5)  // authenticated response from authorize.net
       ...
     else 
        $error = "Unauthenticated response.";
    
 else if (isset($_POST['x_response_code']))  // error
    $error = $_POST['x_response_reason_text'].", #".$_POST['x_response_code'].'.'.$_POST['x_response_subcode'].
        '.'.$_POST['x_response_reason_code'];

【讨论】:

请注意 $x_tran_key 不是 Authorize.Net 交易密钥。这是一个人在设置下在他们的帐户上生成的 MD5 哈希。我一遍又一遍地运行你的代码,直到我弄清楚这个事实才能让它工作。 使用这种方法是否有任何实际的安全损失?这仍然对哪些攻击开放? 比我当时知道的更多,我不会使用rand,而是使用mcrypt_create_iv。如果我今天这样做,我会使用他们的 API。【参考方案3】:

表单方法是传输此信息的不安全方式。更好的选择是使用他们的 API AIM 方法。

可以在这里找到一个很棒的教程: http://www.johnconde.net/blog/tutorial-integrating-the-authorizenet-aim-api-with-php

【讨论】:

【参考方案4】:

Magento 支持 Authorize.Net。提取您需要的代码,因为 Magento 是经过良好测试且质量良好的代码。

【讨论】:

我认为他更多的是寻找现成的解决方案。挖掘 magento 的代码可能比他想的要多【参考方案5】:

我认为 simdata.php 只包含交易数据...比如金额、人的名字等。

【讨论】:

【参考方案6】:

James Gifford 为 codeigniter 创建了一些 Authorize.net 代码。在这里下载...

http://jamesgifford.com/programming/codeigniter-authorize-net-library/

我正在使用直接从 Authorize.nets 开发站点获得的 php sdk...

http://developer.authorize.net/downloads/

【讨论】:

【参考方案7】:

这是一个在 CodeIgniter 中使用的不错的库,但它可以单独使用:

http://code.google.com/p/authorizenetlib/downloads/detail?name=Authorize_net-1.0.php

感谢:james gifford 提供代码。

【讨论】:

链接似乎不再有效。【参考方案8】:

我使用了 Kohana 2.3.x 中包含的支付模块和内置的 Authorize.Net 驱动程序。 http://docs.kohanaphp.com/addons/payment

【讨论】:

【参考方案9】:

http://www.micahcarrick.com/04-19-2005/php-authorizenet-aim-interfacing-class.html

这就是我使用的类。使用起来相当简单。不过,您仍然需要深入研究 API,以确定您想要发送哪些变量以及不发送哪些变量。

【讨论】:

以上是关于好的 authorize.net PHP 库的主要内容,如果未能解决你的问题,请参考以下文章

authorize.net C# 包装器/库

authorize.net 使用 php 集成

Authorize.Net Paypal Express PHP API:交易未在 Authorize.Net 中更新,也未捕获正确金额的问题

Authorize.net 支付集成[关闭]

Authorize.net 接受托管和客户资料

我有几个关于 Authorize.Net 的问题