1

我尝试在我的 windows web server 2008 R2 64bits 上使用 SSL paypal 按钮进行加密。我已经安装了 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 ?)

非常感谢

4

1 回答 1

0

我今晚找到了解决办法。事实上,解决方案是使用 PHP 加密 SSL paypal 按钮,无需命令 openssl。Paypal 给出了一个使用它的例子: https ://cms.paypal.com/fr/cgi-bin/?cmd=_render-content&content_ID=developer/library_download_sdks#WPST并下载网站支付标准工具包。

非常感谢很快见到你

于 2013-01-26T07:09:42.293 回答