PayPal贝宝集成

今天在集成PayPal贝宝在线支付功能时,遇到了一些小挫折,费了不少功夫才最终解决(贝宝的技术支持确实让我很想吐槽)。现在记录下来,供后来者参考。根据集成说明文档,我们写的测试demo如下: 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>   
    <title>Test paypal</title>   
</head>
    <body>
        <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
            <div>            
                <label>充值100美元</label>
                <input type="hidden" name="amount" value="100"/>   
                <input type="hidden" name="cmd" value="_s-xclick"/>           
                <input type="hidden" name="business" value="yourname@gmail.com"/>          
                <input type="hidden" name="item_name" value="Charge" />            
                <input type="hidden" name="currency_code" value="USD" />                     
                <input type="hidden" name="return" value="http://www.****.com/payReturn.aspx"/>
                <input type="hidden" name="notify_url" value="http://www.****.com/paypalNotify.aspx" /> 
                <input type="image" src="https://www.paypalobjects.com/zh_XC/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal——最安全便捷的在线支付方式!"/>
                <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"/>
            </div>
        </form>
    </body>
</html>

 类似这样的代码测试很多次,当跳转到贝宝的页面时,金额100没有传递过去,截图如下所示:

后来,经过摸索,发现需要将cmd项的值修改一下,如下所示: 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>   
    <title>Test paypal</title>   
</head>
    <body>
        <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
            <div>            
                <label>充值100美元</label>
                <input type="hidden" name="amount" value="100"/>   
                <input type="hidden" name="cmd" value="_xclick"/>           
                <input type="hidden" name="business" value="yourname@gmail.com"/>          
                <input type="hidden" name="item_name" value="Charge" />            
                <input type="hidden" name="currency_code" value="USD" />                     
                <input type="hidden" name="return" value="http://www.****.com/payReturn.aspx"/>
                <input type="hidden" name="notify_url" value="http://www.****.com/paypalNotify.aspx" /> 
                <input type="image" src="https://www.paypalobjects.com/zh_XC/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal——最安全便捷的在线支付方式!"/>
                <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"/>
            </div>
        </form>
    </body>
</html>

  这样就可以将金额传递到贝宝的页面了。

原文地址:https://www.cnblogs.com/justnow/p/3268218.html