我有一个 PHP 脚本需要指向我的服务器 openssl 目录,但我迷路了。我知道该目录位于 /usr/bin/openssl,而我的网站页面位于 /var/www/vhosts/domain/httpdocs/test.php。
在 test.php 中,我尝试使用 /usr/bin/openssl 处的相对路径调用 openssl 目录,但我知道这会导致问题。有人可以帮忙吗?
尝试调用 openssl 进行证书加密的 PHP 脚本:
<?php
//文件中先前的 $operatingos 根据操作系统设置为 true 或 false。
if (!$operatingos) {
#PRIVATE KEY FILE
$MY_KEY_FILE = "my-prvkey.pem";
#PUBLIC KEY FILE
$MY_CERT_FILE = "my-pubcert.pem";
#PAYPAL PUBLIC CERTIFICATE
if(!$testingservices) {
$PAYPAL_CERT_FILE = "paypal_cert.pem"; //LIVE
} else {
$PAYPAL_CERT_FILE = "paypal_cert_sandbox.pem"; //SANDBOX
}
#PATH TO OPENSSL BINARY
$OPENSSL = "/usr/bin/openssl";
} 别的 {
#PRIVATE KEY FILE
$MY_KEY_FILE = "C:\\xampp\\htdocs\\privkey.pem";
#PUBLIC KEY FILE
$MY_CERT_FILE = "C:\\xampp\\htdocs\\pubcert.pempem";
#PAYPAL PUBLIC CERTIFICATE
if(!$testingservices) {
$PAYPAL_CERT_FILE = "C:\\xampp\\htdocs\\pppubcert.pem";
} else {
$PAYPAL_CERT_FILE = "C:\\xampp\\htdocs\\pppubcert_sandbox.pem";
}
#PATH TO OPENSSL BINARY
$OPENSSL = "C:\\OpenSSL-Win32\\bin\\openssl.exe";
}
$form = array('cmd' => '_xclick',
'business' => 'email',
'cert_id' => 'certid',
'lc' => 'US',
'custom' => 'test',
'invoice' => '',
'currency_code' => 'USD',
'no_shipping' => '1',
'item_name' => 'Donation',
'item_number' => '1',
'amount' => '10'
);
$encrypted = paypal_encrypt($form);
function paypal_encrypt($hash)
{
global $MY_KEY_FILE;
global $MY_CERT_FILE;
global $PAYPAL_CERT_FILE;
global $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";
}
//Assign Build Notation for PayPal Support
$hash['bn']= 'domain.PHP_EWP2';
$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";
}
};
?>
答案1
问题在于 Windows 和 Linux 系统之间的目录结构不同。我有点笨,但 Windows 目录中的双斜杠是必需的