繁体   English   中英

使用 php 加密动态“添加到购物车”paypal 按钮的问题

[英]problem with encrypting dynamic “add to cart” paypal button with php

I Built a simple payment system integrating paypal with wordpress in php basically I build a list where each list item retrieves metadata from a specific page in wordress (a page for every product) and with this data build dynamically an "add to cart" paypal button . 这很好用。 但是..然后我出于明显的原因尝试加密“添加到购物车”按钮,我发现了一个 php 程序应该这样做(并且从我在不同的互联网论坛中看到的 - 大部分时间都兑现了这个承诺),我想我遵循了 paypal 的所有说明和证书(私人、公共、贝宝等)

虽然我没有从 html 页面收到任何错误 - 当我按下添加到购物车按钮时,我收到 paypal 错误:“我们检测到此购物车有问题。如果问题仍然存在,请联系商家。” 但我没有任何细节为什么以及我做错了什么..

我有一个 paypal 的商家帐户。

为了消除不必要的混乱和噪音,我用 static 数据构建了一个测试页面,以检查按钮是否正常工作,这里是:很高兴有任何帮助

基本测试页面:

<?php
include_once "testfunctions.php";
//inserting some test data
$themetacost='100';
$themetaname="testbook";
$themetashipping='20';
//building the paypal button
$line='';
$line.='<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank" id="payform" >
            <input type="hidden" name="cmd" value="_cart">
                        <input type="hidden" name="encrypted" value="';
$line.= buildbutton($themetacost,$themetaname,$themetashipping);
$line.='">';
$line.='<input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/he_IL/i/btn/btn_cart_SM.gif" border="0" name="submit" alt="PayPal - הדרך הקלה והבטוחה לשלם באופן מקוון!">
                <img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/he_IL/i/scr/pixel.gif" width="1" height="1">
                </form><br/>';
echo $line;

?>

php 构建按钮和加密功能:

<?php
function buildbutton($amount,$bname,$shipping) {
//Sample PayPal Button Encryption: Copyright 2006-2010 StellarWebSolutions.com
//Not for resale  - license agreement at
//http://www.stellarwebsolutions.com/en/eula.php
//Updated: 2010 02 01



$form = array('cmd' => '_cart',
        'business' => 'X@XXX.CO.il', // changed from the original
        'cert_id' => 'XXXXXXXXXXX',// changed from the original
    'shipping' => $shipping,
        //'invoice' => '', //check what this is
        'currency_code' => 'ILS',
        //'no_shipping' => '0', //refers to shipping address
        'add'=>'1',
    'item_name' => $bname,
    'amount' => $amount
    );


    $encrypted = paypal_encrypt($form); 

return $encrypted;
}
function paypal_encrypt($hash)
{
    //Sample PayPal Button Encryption: Copyright 2006-2010 StellarWebSolutions.com
    //Not for resale - license agreement at
    //http://www.stellarwebsolutions.com/en/eula.php
    # private key file to use //

$MY_KEY_FILE = "/home/paypal/my-prvkey.pem";
# public certificate file to use
$MY_CERT_FILE = "/home/paypal/my-prvkey.pem";// 

# Paypal's public certificate
$PAYPAL_CERT_FILE = "/home/paypal/paypal_cert.pem";

# path to the openssl binary
$OPENSSL = "/usr/bin/openssl";

    if (!file_exists($MY_KEY_FILE)) {
        echo "ERROR: MY_KEY_FILE $MY_KEY_FILE not found\n";
    }
    if (!file_exists($MY_CERT_FILE)) {
        echo "ERROR: MY_CERT_FILE $MY_CERT_FILE not found\n";
    }
    if (!file_exists($PAYPAL_CERT_FILE)) {
        echo "ERROR: PAYPAL_CERT_FILE $PAYPAL_CERT_FILE not found\n";
    }
        if (!file_exists($OPENSSL)){
                echo "error with openssl $OPENSSL not found \n";
        }


    //Assign Build Notation for PayPal Support
    //$hash['bn']= 'StellarWebSolutions.PHP_EWP2'; //this is not needed cause i dont have a ewp

    $data = "";
    foreach ($hash as $key => $value) {
        if ($value != "") {
            //echo "Adding to blob: $key=$value\n";
            $data .= "$key=$value\n";
        }
    }

    $openssl_cmd = "($OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " .
                        "-outform der -nodetach -binary <<_EOF_\n$data\n_EOF_\n) | " .
                        "$OPENSSL smime -encrypt -des3 -binary -outform pem $PAYPAL_CERT_FILE";

    exec($openssl_cmd, $output, $error);

    if (!$error) {
        return implode("\n",$output);
    } else {
        return "ERROR: encryption failed";
    }
}

?>

我试图将变量更改为数字以检查是否存在没有帮助的问题。

这就是加密的测试页面源的样子:

action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank" id="payform" >

            <input type="hidden" name="cmd" value="_cart">

                        <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----
MIIBdwYJKoZIhvcNAQcDoIIBaDCCAWQCAQAxggEwMIIBLAIBADCBlDCBjjELMAkG
A1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQw
EgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UE
AxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJ
KoZIhvcNAQEBBQAEgYAiFKR0WuQJcr6cQZvDCptQeDNyfipH9pDy1Q58C+ITCZWY
XRkkUOvvL3jniO1GUxsY2JleGAdZWSV1qgnO3uNjj0V3Z0AxbrAiuA0lLd8pscBT
MM+9+1RwjTOUVtOi3PASy1TC4hk6Wq01KUk1DCpbqMtqBZ6sWb5jHRxWqbL08zAr
BgkqhkiG9w0BBwEwFAYIKoZIhvcNAwcECClgCVLJPeXAgAgr8wXDhqI+og==
-----END PKCS7-----"><input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/he_IL/i/btn/btn_cart_SM.gif" border="0" name="submit" alt="PayPal - äãøê ä÷ìä åäáèåçä ìùìí áàåôï î÷ååï!">

                <img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/he_IL/i/scr/pixel.gif" width="1" height="1">

                </form><br/>

编辑:将 html 形式(不是:php 加密函数)从“_cart”更改为“_s-xclick”后,我得到一个不同的错误:

企业的 email 地址不在加密的 blob 中。 请联系您的商家。

在各种 paypal 论坛中获得更多建议后,我还尝试更新证书和密钥(全部三个......)。 根本没有帮助!

我会将 cmd 更改为 _s-xclick。 所有 PayPal 加密支付都使用此命令。

当我尝试它时,我得到“加密的 blob 中不存在企业的 email 地址。请联系您的商家。” 错误。 您是否尝试过“安全商家 ID”而不是 email? 它在帐户的个人资料中。

我个人建议使用按钮管理器 API 而不是加密按钮。 https://merchant.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ButtonMgrAPIIntro its major advantage is you can call the API to retrieve the contents of the button. 加密的 blob 无法真正解密以查看 email 是否真的存在。

我希望这有帮助。 罗勒福尔

检查 OpenSSL 版本是否更改或证书是否有问题。

您可以参考Paypal重新生成证书并将其上传到 Paypal。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM