然后,出于显而易见的原因,我尝试加密“添加到购物车”按钮。我找到了一个PHP程序来做到这一点(根据我在不同互联网论坛上看到的大多数情况下都可以实现),并且我认为我按照PayPal的所有说明进行了操作(私有、公共、PayPal等证书)。
虽然我的html页面没有出现任何错误,但当我点击“添加到购物车”按钮时,我收到了PayPal错误:“我们检测到这个购物车存在问题。如果问题仍然存在,请联系商家。” 但我不知道具体是哪里出了问题和我做错了什么……
我已经拥有了一个PayPal商家账户。
为了消除不必要的杂乱和噪音,我创建了一个带有静态数据的测试页面来检查按钮是否正常工作,在此提供给需要帮助的人。
基本测试页面:
<?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”后,我得到了不同的错误:
商家的电子邮件地址未出现在加密的 blob 中。请联系您的商家。
根据PayPal论坛上的更多建议,我还尝试更新证书和密钥(所有三个..),但没有任何帮助!