3

我以前从未做过贝宝集成,但我曾与其他网关合作过。

对于其他网关,还有一个哈希值,它也以 post 形式发送,这可以防止人们篡改数据,即更改数量。

贝宝如何阻止这种篡改,似乎没有任何哈希值。

<form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
  <input type="hidden" value="_xclick" name="cmd">
  <input type="hidden" value="online****@theg*****.com" name="business">
  <!-- <input type="hidden" name="undefined_quantity" value="1" /> -->
  <input type="hidden" value="Order" name="item_name">
  <input type="hidden" value="NA" name="item_number">
  <input type="hidden" value="22.16" name="amount">
  <input type="hidden" value="5.17" name="shipping">
  <input type="hidden" value="0" name="discount_amount">        
  <input type="hidden" value="0" name="no_shipping">
  <input type="hidden" value="No comments" name="cn">
  <input type="hidden" value="USD" name="currency_code">
  <input type="hidden" value="http://XXX/XXX/XXX/paypal/return" name="return">
  <input type="hidden" value="2" name="rm">      
  <input type="hidden" value="11255XXX" name="invoice">
  <input type="hidden" value="US" name="lc">
  <input type="hidden" value="PP-BuyNowBF" name="bn">
  <input type="submit" value="Place Order!" name="finalizeOrder" id="finalizeOrder" class="submitButton">
</form>

那么我怎样才能阻止人们在发布到贝宝之前修改金额?即数量应该是 100,但人们将其更改为 1。

4

2 回答 2

5

有几种方法可以防止这种情况。第一个是使用 PayPal 的即时付款通知(IPN)。使用它,您可以比较 PayPal 发回给您的价格,以确认它们与您的预期相符。如果它们不匹配,您将取消订单。

示例工作流程:

  • 用户订购商品并将价格修改为 0.01 美元
  • 订单发布到 PayPal,显示价格为 0.01 美元
  • 用户接受价格并支付 0.01 美元
  • PayPal 调用您的 IPN URL 并发布交易详情,显示用户支付了 0.01 美元购买了一件物品
  • 您的 IPN 会检查 PayPal 收到的价格 ($0.01) 与您的预期价格 (> $0.01)。由于它们不匹配,因此您取消订单

贝宝 IPN 流

另一种选择是使用 PayPal 的Button API来创建动态的加密按钮。这些嵌入到您的页面中,用户单击它来下订单。由于它是加密的,因此用户无法在交易过程中可靠地修改源代码。这个答案中有一个很好的例子。此外,您可以将其与上面列出的 IPN 选项结合起来,作为对交易的良好审计

于 2013-11-01T15:01:02.800 回答
0

您需要做的是实现一个简单的发票系统。在您的数据库中有一个名为invoices (ID, User_Id, Invoice_Value, Payment_Status)(example) 的表。

当用户进入结帐页面时,现在您应该已经在 db 表中为该用户插入了一个条目,即他们必须支付的总金额以及“待处理”的初始付款状态)。插入发票表行后,获取最后一个插入 id 和一个名为$invoice_id.

现在,您输出 html paypal 结帐按钮表单,其中一个隐藏的输入字段应如下所示:

<input type="hidden" value="<?php echo $invoice_id; ?>" name="custom">

现在,当 paypal 使用 IPN 响应您的返回 URL 时,您的 IPN 处理程序应该按照以下方式运行:

<?php

// read the post from PayPal system and add 'cmd'  
$req = 'cmd=_notify-validate';  
foreach ($_POST as $key => $value) {  
    $value = urlencode(stripslashes($value));  
    $req .= "&$key=$value";  
}

// post back to PayPal system to validate  
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";  
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";  
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";  

$fp = fsockopen ('ssl://sandbox.www.paypal.com', 443, $errno, $errstr, 30);  
if (!$fp) {  
    // HTTP ERROR  
}
else
{
    // Make Request To PayPal
    fputs ($fp, $header . $req);  
    while (!feof($fp))
    { 
        // Read Response 
        $res = fgets ($fp, 1024);

        // Check Response  
        if (strcmp ($res, "VERIFIED") == 0)
        {  
            // PAYMENT VALIDATED & VERIFIED!

            // Load the Invoice_Value from invoices table for $_POST['custom']
            // and compare it with paypal posted amount held in $_POST['mc_gross']
            // if it matches, paypal has authenticated the payment and the value has not been tampered with
            // update the invoice table and set the payment status
        }  
        else if (strcmp ($res, "INVALID") == 0)
        {  
            // PAYMENT INVALID & INVESTIGATE MANUALY!  
        }
    }  
    fclose ($fp);  
}  

?>
于 2013-11-01T14:54:52.807 回答