2013-01-25 35 views
1

我尝试在我的Windows Web服务器2008 R2 64位上使用SSL paypal按钮进行加密。 我已经安装了Apache 2.2.22,php 5.4.3和openssl。如何在Windows Web服务器2008 R2 64位的crypt SSL paypal按钮,

我在crypt找到类在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 protected]') 
      ->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> 

我不知道为什么它不能在窗口中运行,则,但它工作的1and1(Linux呢?)

非常感谢 亲切

回答

相关问题