Windows Web サーバー 2008 R2 64 ビットで SSL ペイパル ボタンを使用して暗号化しようとしています。Apache 2.2.22 、php 5.4.3、および openssl をインストールしました。
SSL Paypal ボタンで暗号化するクラスを見つけましたが、機能しません。ボタンのコードが暗号化されていないだけです。
暗号化するクラス:
<?php
class PaypalCrypt{
private $privateKey = '';
private $publicKey = '';
private $paypalKey = '';
//private $pathOpenSSL = '/usr/bin/openssl';
private $pathOpenSSL = 'C:/wamp/bin/apache/apache2.2.22/bin/openssl.exe';
private $data = array(
'bn' => 'Boutique_BuyNow_WPS_FR',
'cmd' => '_xclick',
'lc' => 'FR',
'custom' => '',
'invoice' => '',
'currency_code' => 'EUR',
'charset' => 'UTF-8', //Définit le charset utilisé sur le site
'no_shipping' => '1'
);
public function __construct(){
// Nothing
}
public function addData($key, $data){
$this->data[$key] = $data;
return $this;
}
public function setPrivateKey($privateKey){
$this->privateKey = $privateKey;
return $this;
}
public function setPublicKey($publicKey){
$this->publicKey = $publicKey;
return $this;
}
public function setPaypalKey($paypalKey){
$this->paypalKey = $paypalKey;
return $this;
}
public function getCryptedData(){
if (!file_exists($this->privateKey))
throw new Exception('ERROR: MY_KEY_FILE '.$this->privateKey.' not found');
if (!file_exists($this->publicKey))
throw new Exception('ERROR: MY_CERT_FILE '.$this->publicKey.' not found');
if (!file_exists($this->paypalKey))
throw new Exception('ERROR: PAYPAL_CERT_FILE '.$this->paypalKey.' not found');
$openssl_cmd = "$this->pathOpenSSL smime -sign -signer $this->publicKey -inkey $this->privateKey ".
"-outform der -nodetach -binary| $this->pathOpenSSL smime -encrypt ".
"-des3 -binary -outform pem $this->paypalKey";
$descriptors = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
);
$process = proc_open($openssl_cmd, $descriptors, $pipes);
if (is_resource($process)) {
foreach ($this->data as $key => &$value)
if ($value != "")
fwrite($pipes[0], "$key=$value\n");
fflush($pipes[0]);
fclose($pipes[0]);
$output = "";
while (!feof($pipes[1]))
$output .= fgets($pipes[1]);
fclose($pipes[1]);
$return_value = proc_close($process);
return $output;
}
throw new Exception('ERROR: encryption failed');
}
public function setOpenSSLPath($path){
if(!file_exists($path))
throw new Exception('OpenSSLPath "'.$path.'" don\'t exists');
$this->pathOpenSSL = $path;
}
}
$MY_KEY_FILE = "prvkey.pem";
# public certificate file to use
$MY_CERT_FILE = "pubcert.pem";
# Paypal?s public certificate
$PAYPAL_CERT_FILE = "paypal_cert.pem";
// Initialisation cryptage Paypal
$paypalCrypt = new PaypalCrypt();
$paypalCrypt->setPrivateKey($MY_KEY_FILE);
$paypalCrypt->setPublicKey($MY_CERT_FILE);
$paypalCrypt->setPaypalKey($PAYPAL_CERT_FILE);
$paypalCrypt->addData('cert_id','id_certificat_fourni_par_paypal')
->addData('business','email@email.com')
->addData('no_note','1')
->addData('shipping','0')
->addData('tax','0')
->addData('rm','2')
->addData('cbt','Retour sur la boutique')
->addData('custom','id_membre')
->addData('return','http://mon_site.com/return.php')
->addData('cancel_return','http://mon_site.com/cancel.php')
->addData('notify_url','http://mon_site.com/ipn.php')
->addData('amount','10')
->addData('item_name', 'Boite à meuh')
->addData('item_number', 'identifiant_produit');
$data = $paypalCrypt->getCryptedData();
?>
<form action="https://www.paypal.com/fr/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="<?php echo $data?>"/>
<input type="submit" value="Commander" class="input_button">
</form>
Windows で動作しない理由はわかりませんが、1and1 (Linux ?) では動作しています。
心より感謝申し上げます