gpt4 book ai didi

php - Paypal - 用 php 加密 buynow 动态结帐按钮

转载 作者:太空宇宙 更新时间:2023-11-03 15:56:37 25 4
gpt4 key购买 nike

上周我一直在尝试制作一个加密的“使用 paypal 结帐”按钮。

最后我在这个网站“https://ppmts.custhelp.com/app/answers/detail/a_id/502”中找到了使用 php 进行加密的网络支付

我正在尝试根据我在本地主机中的站点在该示例中实现。但显示错误“收到错误 #3”

这是我的代码例子.php

         <?php
$config = array("cert_id" => "PHCVJS6GDV6TY", "business" => "roki_1347003608_biz@gmail.com","basedir" => "./",
"certstore" => "./", "tempdir" => "./", "my_private" => "my-prvkey.pem", "my_public" => "my.pubcert.pem",
"paypal_public" => "paypal_cert_pem.txt");
$paypal = new PayPal_EncryptedButtons($config);

// You can add parameters to the button one by one (name, value) or you can pass two
// arrays of names and values, as documented below.
$names = array("amount", "currency_code", "item_name", "item_number");
$values = array("2.56", "USD", "Dave's secret encryption sauce (encryption via PHP)", "123456");
$paypal->addButtonParam($names, $values);

// We can now generate our code
$result = $paypal->encryptButtonData();
if ($result !== PP_ERROR_OK) {
// Something went wrong
echo "Received Error #".$result."\n";
exit;
}

// Get the string of encrypted button data

echo '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">';
echo '<input type="hidden" name="cmd" value="_s-xclick">';
echo '<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">';
echo '<input type="hidden" name="encrypted" value="';
echo $paypal->getButton();
echo '">';
echo "</form>\n";
?>
</body>
</html>

加密按钮.php

          <?php

define("PP_ERROR_OK", 0);
define("PP_ERROR_FILE", 1);
define("PP_ERROR_OPENSSL", 2);
define("PP_ERROR_DATA", 3);
define("PP_ERROR_PARAMS", 4);
define("PP_ERROR_NOTFOUND", 5);
define("PP_ERROR_UNKNOWN", 6);


require_once "/wamp/www/var/Php/Config.php";


class PayPal_EncryptedButtons {



/** Button Data Array */
var $buttonData = array();

/** Config Pointer */
var $config;

/** Internal Data Handler */
var $_data;

/** Random Transaction ID */
var $_rnd;

var $debug = true;

function PayPal_EncryptedButtons($config = array()) {
$this->config = new PayPal_EncryptedButtons_Config;
/*
foreach ($config as $name => $val) {
if ($this->config->$name) {
$this->config->$name = $val;
}
else {
return PP_ERROR_UNKNOWN;
}
}
*/
return;
}


function changeConfig($name, $value = "") {
if ($this->config->$name) {
$this->config->$name = $value;
return true;
}
else {
return false;
}
}


function addButtonParam($names = "", $values = "") {
if ((is_array($names) && !is_array($values)) || (!is_array($names) && is_array($values))) {
return PP_ERROR_PARAMS;
}
elseif (is_array($names) && is_array($values)) {
if (count($names) !== count($values)) {
return PP_ERROR_PARAMS;
}
$i = 0;
while ($i < count($names)) {
$this->buttonData[$names[$i]] = $values[$i];
$i++;
}
return PP_ERROR_OK;
}
else {
if ($names == "" || $values == "") {
return PP_ERROR_PARAMS;
}
else {
$this->buttonData[$names] = $values;
return PP_ERROR_OK;
}
}
}


function delButtonParam($name = "") {
if ($name == "") {
return PP_ERROR_PARAMS;
}
if ($this->buttonData[$name] !== null) {
$this->buttonData[$name] = null;
return PP_ERROR_OK;
}
return PP_ERROR_NOTFOUND + 10;
}


function encryptButtonData() {
$this->encryptedButton = null;
if (!is_dir($this->config->basedir)) {
if (!mkdir($this->config->basedir)) {
return PP_ERROR_NOTFOUND + 20;
}
}
@chdir($this->config->basedir);
$this->_data = "cmd=_xclick\n";
$this->_data .= "business=".$this->config->business."\n";
$this->_data .= "receiver_email=".$this->config->receiver_email."\n";
foreach ($this->buttonData as $name => $val) {
if ($val == null) { continue; }
$this->_data .= $name."=".$val."\n";
}
$this->_data .= "cert_id=".$this->config->cert_id;
$this->_rnd = rand(100000, 999999);
if (!is_dir($this->config->tempdir)) {
if (!@mkdir($this->config->tempdir)) {
return PP_ERROR_NOTFOUND + 30;
}
}
$f = @fopen($this->config->tempdir.$this->_rnd.".1", "w");
//if (!$f) { return PP_ERROR_FILE; }
if (!$f) { return 41; }
fwrite($f, trim($this->_data), strlen(trim($this->_data)));
fclose($f);
if (!file_exists($this->config->my_private)) {
return 145;
}
if (!file_exists($this->config->my_public)) {
return 245;
}
if (!file_exists($this->config->paypal_public)) {
return 345;
}
if (!file_exists($this->config->my_private) || !file_exists($this->config->my_public) || !file_exists($this->config->paypal_public)) {
return PP_ERROR_NOTFOUND + 40;
}
$exec = $this->config->openssl." smime -sign -in ".$this->config->tempdir.$this->_rnd.".1 -signer ".$this->config->my_public." -inkey ".$this->config->my_private." -outform der -nodetach -binary > ".$this->config->tempdir.$this->_rnd.".2";
$status1 = `$exec`;
$exec = $this->config->openssl." smime -encrypt -des3 -binary -outform pem ".$this->config->paypal_public." < ".$this->config->tempdir.$this->_rnd.".2 > ".$this- >config->tempdir.$this->_rnd.".3";
$status2 = `$exec`;
$this->encryptedButton = trim(file_get_contents($this->config->tempdir.$this->_rnd.".3"));
@unlink($this->config->tempdir.$this->_rnd.".1");
@unlink($this->config->tempdir.$this->_rnd.".2");
@unlink($this->config->tempdir.$this->_rnd.".3");
if (strpos($status1, "No such file or directory") !== false || strpos($status2, "No such file or directory") !== false) {
return PP_ERROR_OPENSSL;
}
if (!$this->encryptedButton) {
return PP_ERROR_DATA;
}
return PP_ERROR_OK;
}


function getButton() {
if (!$this->encryptedButton) {
return "";
}
return $this->encryptedButton;
}

配置.php

       <?php
class PayPal_EncryptedButtons_Config {
var $cert_id = "PHCVJS6GDV6TY";
var $business = "roki_1347003608_biz@gmail.com";

var $receiver_email = "";

var $basedir = "/wamp/www/var/";

var $certstore = "/wamp/www/key/cert/";

var $tempdir = "/wamp/www/temp/";

var $openssl = "openssl";

var $my_private = "/wamp/www/key/cert/my-prvkey.pem";

/* Your Public Certificate Filename */
var $my_public = "/wamp/www/key/cert/my.pubcert.pem";

/* PayPal's Public Certificate Filename */
var $paypal_public = "/wamp/www/key/cert/paypal_cert_pem.txt";

}

?>

错误

       Received Error #3

任何人都可以知道这是什么错误任何人都可以帮助我如何解决这个问题真的我帮助较少。谢谢

最佳答案

问题是要使脚本正常工作,您需要有 OpenSSL。在脚本的注释中,它确实指定使用它来加密 PayPal 按钮。

这一行是导致问题的原因,因为它无法创建文件,因为尚未指定 OpenSSL。

$exec = $this->config->openssl." smime -encrypt -des3 -binary -outform pem ".$this->config->paypal_public." < ".$this->config->tempdir.$this->_rnd.".2 > ".$this->config->tempdir.$this->_rnd.".3";

您需要指定 OpenSSL 的路径才能使其正常工作。

以下内容摘自您链接的网站。

配置:

/* OpenSSL Path - Path to the OpenSSL Binary */
/* If openssl isn't in your PATH, then change this to where it's located, otherwise leave it as it is */
/* No trailing slash */
var $openssl = "openssl";

有关在本地主机中使用 OpenSSL 的信息可以通过以下谷歌查询找到: https://www.google.co.uk/search?q=openssl+for+localhost

OpenSSL:http://www.openssl.org/

希望对您有所帮助。

关于php - Paypal - 用 php 加密 buynow 动态结帐按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12552124/

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