Paybox集成

时间:2012-07-25 13:55:40

标签: php integration credit-card

我尝试整合Paybox信用卡交易解决方案。

我尝试了至少100种不同的解决方案(不是开玩笑),但没有人工作,每次我得到“Problèmed'dentifityducommerce.Accèsrefusé!”消息(法语)。

这是我拥有的最“稳定”的代码:

<?php

function gen_hmac($site, $rang, $identifiant, $devise, $cmd, $porteur, $hash, $time, $total, $retour, $key) {
    $msg = "PBX_SITE=". $site 
        ."&PBX_RANG=". $rang 
        ."&PBX_IDENTIFIANT=". $identifiant 
        ."&PBC_TOTAL=". $total 
        ."&PBX_DEVISE=". $devise 
        ."&PBC_CMD=". $cmd 
        ."&PBC_PORTEUR=". $porteur 
        ."&PBC_RETOUR=". $retour 
        ."&PBC_HASH=". $hash 
        ."&PBC_TIME=" . $time ; 
        $binkey = pack("H*", $key);
        echo "<!-- " . $msg . " -->";
        $hmac = strtoupper(hash_hmac('sha512', $msg, $binkey));
        echo "<!-- " . $hmac . " -->";
    return $hmac;
}

    // static
    $site = 1999888;
    $rang = 32;
    //$identifiant = 110647233;
    $identifiant = 107904482;
    $devise = 978;
    $hash = "SHA512";
    $key = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
    $cmd = "TEST Paybox";
    $porteur = "test@paybox.com";
    $time = date("c");
    //$time = "2011-02-28T11:01:50+01:00";

    // variable
    $total = 1000;
    //$retour = "ref:R;trans:T;auto:A;tarif:M;abonnement:B;pays:Y;erreur:E";
    $retour = "Mt:M;Ref:R;Auto:A;Erreur:E";
    $hmac = gen_hmac($site, $rang, $identifiant, $devise, $cmd, $porteur, $hash, $time, $total, $retour, $key);

?>

<html>
<head>
<title>Paybox TEST</title>
</head>
<body>
<?php
//print_r(hash_algos());    
?>
<form method="POST" action="https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi">
<!--<form method="POST" action="https://preprod-tpeweb.paybox.com/cgi/MYframepagepaiement_ip.cgi">-->
<!--<form method="POST" action="https://preprod-tpeweb.paybox.com/cgi/ChoixPaiementMobile.cgi">-->
    <input type="hidden" name="PBX_SITE" value="<?php echo $site; ?>" />
    <input type="hidden" name="PBX_RANG" value="<?php echo $rang; ?>" />
    <input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $identifiant; ?>" />
    <input type="hidden" name="PBX_TOTAL" value="<?php echo $total; ?>" />
    <input type="hidden" name="PBX_DEVISE" value="<?php echo $devise; ?>" />
    <input type="hidden" name="PBX_CMD" value="<?php echo $cmd; ?>" />
    <input type="hidden" name="PBX_PORTEUR" value="<?php echo $porteur; ?>" />
    <input type="hidden" name="PBX_RETOUR" value="<?php echo $retour; ?>" />
    <input type="hidden" name="PBX_HASH" value="<?php echo $hash; ?>" />
    <input type="hidden" name="PBX_TIME" value="<?php echo $time; ?>" />
    <input type="hidden" name="PBX_HMAC" value="<?php echo $hmac; ?>" />
    <!--<input type="hidden" name="PBX_REFUSE" value="http://test.fr/" />
    <input type="hidden" name="PBX_ANNULE" value="http://test.fr/" />
    <input type="hidden" name="PBX_EFFECTUE" value="http://test.fr/" />-->
    <input type="submit" value="envoyer" />
</form>
</body>
</html>

大多数静态值来自paybox测试文档。

那么你知道我的代码有什么问题吗?或者你知道如何获得有关发送到paybox服务器的错误的更多细节吗?

此致

编辑: 关于我的目标的更多细节。我真正的需要是在java中编写代码,但我在php中有一些代码示例,最终帮助了。

现在我尝试了解如何在java中生成干净的hmac / sha512。

<?php 
$key = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
$binkey = pack("H*", $key); 
echo strtoupper(hash_hmac('sha512', "ABC", $binkey)); 
?>

产出:100A6A016A4B21AE120851D51C93B293D95B7D8A44B16ACBEFC2D1C9DF02B6F54FA3C2D6802E52FED5DF8652DDD244788A204682D2D1CE861FDA4E67F2792643

那么我怎样才能在java中重新创建相同的hmac算法呢?

我尝试过很多东西,但没有人能实现我的目标,但这就是我目前的目标:

private String generateHMAC( String datas )
    {

        //                final Charset asciiCs = Charset.forName( "utf-8" );
        Mac mac;
        String result = "";
        try
        {
            byte[] bytesKey = PayboxConstants.KEY.getBytes( );
            final SecretKeySpec secretKey = new SecretKeySpec( bytesKey, "HmacSHA512" );
            mac = Mac.getInstance( "HmacSHA512" );
            mac.init( secretKey );
            final byte[] macData = mac.doFinal( datas.getBytes( ) );
            byte[] hex = new Hex( ).encode( macData );
            result = new String( hex, "ISO-8859-1" );
        }
        catch ( final NoSuchAlgorithmException e )
        {
            AppLogService.error( e );
        }
        catch ( final InvalidKeyException e )
        {
            AppLogService.error( e );
        }
        catch ( UnsupportedEncodingException e )
        {
            AppLogService.error( e );
        }

        return result.toUpperCase( );

    }

但其输出为:AA6492987D7A7AC81109E877315414806F1973CC47B897ECE713171A25A11B279329B1BFF39EA72A5EFB7EDCD71D1F34D5AAC49999A780BD13F019ED99685B80

这绝对不等同于“克隆”的php hmac算法。

那么我可以添加到我的java代码中以使其符合其php等价?

编辑: 实际上我设法使所有东西一起工作,我在这里可用: http://dev.lutece.paris.fr/plugins/plugin-paybox/index.html

1 个答案:

答案 0 :(得分:0)

<section class="rl-box">
    <div class="container padd-xs-0">
        <div class="content-section1">
            <div class="left-cont col-md-12 col-sm-12">



                <div class="container-fluid">

                    <?php
                    $PBX_SITE = "1999888";
                    $PBX_RANG = "32";
                    $PBX_IDENTIFIANT = "your identifiant id";
                    $secretKeyTest = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
                    $PBX_PORTEUR = "your-email";
                    $PAYBOX_DOMAIN_SERVER = "tpeweb.paybox.com";
                    $dateTime = date("c");

                    $PBX_TOTAL = 4000; //$_POST["PBX_TOTAL"];   // Amount
                    $PBX_DEVISE = 978;
                    //$PBX_CMD = $_POST["PBX_CMD"]."|".$_POST["user"]."|".$_POST["typed"]."|".$_POST["period"]."|".$_POST["id"]; // order ID no.                          
                    $PBX_CMD = 1; // order ID no.Eg: userid,order_id


                    $PBX_RETOUR = "Mt:M;Ref:R;Auto:A;Erreur:E";
                    $PBX_HASH = "SHA512";
                    $PBX_TIME = $dateTime;

                    //$PBX_EFFECTUE = "http://www.leader-underwriting.eu/payment/payment.php";

                    $msg = "PBX_SITE=$PBX_SITE" .
                            "&PBX_RANG=$PBX_RANG" .
                            "&PBX_IDENTIFIANT=$PBX_IDENTIFIANT" .
                            "&PBX_TOTAL=$PBX_TOTAL" .
                            "&PBX_DEVISE=$PBX_DEVISE" .
                            "&PBX_CMD=$PBX_CMD" .
                            "&PBX_PORTEUR=$PBX_PORTEUR" .
                            "&PBX_RETOUR=$PBX_RETOUR" .
                            "&PBX_HASH=$PBX_HASH" .
                            "&PBX_TIME=$PBX_TIME";


                    $binKey = pack("H*", $secretKeyTest);
                    $hmac = strtoupper(hash_hmac('sha512', $msg, $binKey));

                    $cuu = str_replace(",", "", $ramount);
                    ?>                             
                    <form method="POST" name="form_payment" action="https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi">

                        <input type="hidden" name="PBX_SITE" value="<?php echo $PBX_SITE; ?>">
                        <input type="hidden" name="PBX_RANG" value="<?php echo $PBX_RANG; ?>">
                        <input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $PBX_IDENTIFIANT; ?>">
                        <input type="hidden" name="PBX_TOTAL" value="<?php echo $PBX_TOTAL; ?>"> <!--dynamic-->
                        <input type="hidden" name="PBX_DEVISE" value="<?php echo $PBX_DEVISE; ?>">
                        <input type="hidden" name="PBX_CMD" value="<?php echo $PBX_CMD; ?>">  <!--dynamic-->
                        <input type="hidden" name="PBX_PORTEUR" value="<?php echo $PBX_PORTEUR ?>">
                        <input type="hidden" name="PBX_RETOUR" value="<?php echo $PBX_RETOUR; ?>">
                        <input type="hidden" name="PBX_HASH" value="<?php echo $PBX_HASH; ?>">
                        <input type="hidden" name="PBX_TIME" value="<?php echo $PBX_TIME; ?>">
                        <input type="hidden" name="PBX_HMAC" value="<?php echo $hmac; ?>">
                        <button type="submit" class="btn btn-primary payment">
                            Payer
                        </button> 
                    </form>





                    <center>

                    </center>

                </div>

            </div>


        </div> <!-- .container-fluid -->

    </div>               

</div>
</div>
</section>