Paypal加密按钮,加密值

时间:2014-08-24 17:58:07

标签: php curl encryption paypal

如何在动态paypal html表单上获得加密输入的值?我的服务器端语言是php。

这是我的HTML

<form action="https://www.paypal.com/cgi-bin/webscr" method="POST" class="block">
<input name="'.Cart_Form_Cart::FORM_TRY.'" type="hidden" value="1" />
<input name="'.Cart_Form_Cart::FORM_ACTION.'" type="hidden" value="checkout" />
<input type="submit" class="form-submit blue-button pointer margin-top-20" value="Proceed to Checkout" />
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="encrypted" value="**NEED THIS VALUE**" />
</form> 

这是我的数组和curl

$sendData = array(
     "METHOD" => "BMCreateButton",
     "VERSION" => "65.2",
     "USER" => "my-username",
     "PWD" => "my-pass",
     "SIGNATURE" => "my-sig",
     "BUTTONCODE" => "ENCRYPTED",
     "BUTTONTYPE" => "BUYNOW",
     "BUTTONSUBTYPE" => "SERVICES",
     "BUTTONCOUNTRY" => "GB",
     "BUTTONIMAGE" => "reg",
     "BUYNOWTEXT" => "BUYNOW",
     "L_BUTTONVAR1" => "item_number=$order_id",
     "L_BUTTONVAR2" => "item_name=purchase",
     "L_BUTTONVAR3" => "amount=$subtotal",
     "L_BUTTONVAR4" => "currency_code=GBP",
     "L_BUTTONVAR5" => "no_shipping=1",
     "L_BUTTONVAR6" => "no_note=1",
     "L_BUTTONVAR7" => "notify_url=http://www.abc.co.uk/paypal/ipn.php",
     "L_BUTTONVAR8" => "cancel_return=http://www.abc.co.uk/paypal/thanks",
     "L_BUTTONVAR9" => "return=http://www.abc.co.uk/paypal/return.php"
);

$url = 'https://api-3t.paypal.com/nvp?';

这是卷曲调用

$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url.http_build_query($sendData));
$encrypt = curl_exec($curl);
curl_close($curl);
return $encrypt;

更新:

我将所有内容绑定到php中的变量,然后将该变量作为文本吐出到页面中。所以对于行

$text .= '<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----'.$encryption.'-----END PKCS7-----" />';

我如何制作&#39;。$ encryption。&#39;从没有缩进输入值的新行开始?

1 个答案:

答案 0 :(得分:2)

您可以在此处阅读官方paypal文档:https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/encryptedwebpayments/#id08A3I0P017Q 您可以使用他们的官方工具。

但我使用此PHP类https://github.com/josephholsten/swaplady/blob/master/library/PaypalEwp.php的修改版本 代码陈旧而且hackish,但它确实有效。

您需要创建证书,将公共证书上传到PayPal并获取上传后生成的cerficate ID。你也需要他们的公共证书。您可以使用证书,私钥,证书ID和paypal公共证书配置该类的实例。

所以基本上代码实际上是用你的证书签署数据字段,然后是paypal公共证书。

这是我的版本,我使用它与symfony,因此前缀和sfConfig,但除此之外它只是PHP:https://gist.github.com/dincho/7d8d4ca4e1f5dede925b

请注意,示例文档(在类源代码中)HTML字段值在新行上且没有缩进 - 这非常重要