【问题标题】:How can set variable in curl?如何在 curl 中设置变量?
【发布时间】:2011-12-22 09:47:11
【问题描述】:

我正在开发一个网站,我正在尝试访问贝宝。所以我正在尝试使用 curl 将存储在我的数据库中的用户信息发送到贝宝服务器。我不知道该怎么做。请问您能在这方面帮助我吗?

我的代码:

$fetSql     ="SELECT * FROM `donator` WHERE `donatorId`='".$_REQUEST['donatorId']."'";
        //echo $fetSql;
        $fetQry     =$db->query($fetSql);
        $array      =$db->fetch_array($fetQry);



    $customer_first_name        =$array['donatorFName'];
    $customer_last_name     =$array['donatorLName'];
    $example_payment_amuont     =$array['amount'];
    $customer_address1      =$array['address1'];
    $customer_address2      =$array['address2'];
    $customer_city      =$array['city'];
    $customer_state     =$array['state'];
    $customer_zip           =$array['zip'];
    $customer_country       =$array['country'];
    $customer_credit_card_number        =$array['cardNo'];
    $cc_cvv2_number     =$array['cvvNo'];
    $cc_expiration_month        =$array['expMnth'];
    $cc_expiration_year     =$array['expYr'];
    $currencyCodeType   ='GBP';

如何在 curl 中分配这些数据?

【问题讨论】:

  • Bobby-Tables想来玩。 叹息
  • cURL 是一个用于发出 HTTP 请求的库。您必须以客户端想要的格式构造 HTTP 请求。

标签: php curl paypal


【解决方案1】:

您必须在 PHP 中回显表单并将值作为隐藏字段提供。

<body onLoad="document.forms['gateway_form'].submit();">
<form method="POST" name="gateway_form" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="$FIELD" value="$VALUE"/>
<input type="hidden" name="$FIELD2" value="$VALUE2"/>
 ....
</form>

由于onLoad脚本自动提交。

然后用户将被重定向到 PayPal 进行登录。

如果你用 CURL 做这个,用户不能付款。

【讨论】:

    【解决方案2】:

    首先,我不是贝宝专家,但我怀疑您使用的方法是否正确,我认为您必须将表单的 action 设置为指向贝宝而不使用 curl。

    无论如何,要回答您在 curl 中设置参数的问题,您必须使用 curl_setopt 函数和 CURLOPT_POSTFIELDS 常量。

    这里是一个完整的例子

    $ch=curl_init();
    curl_setopt ($ch,CURLOPT_URL,"https://example.com/");
    curl_setopt ($ch,CURLOPT_POST,1);
    
    
    $post = "user_id=001&price=105";
    
    curl_setopt ($ch,CURLOPT_POSTFIELDS,$post);
    curl_setopt ($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
    curl_setopt ($ch,CURLOPT_RETURNTRANSFER, 1);
    
    var_dump(curl_exec($ch));
    curl_close ($ch);
    

    【讨论】:

      【解决方案3】:

      PHP 网站上有一个很好的 cUrl 教程。请看链接http://php.net/manual/en/ref.curl.php

      对于集成 Paypal,您可以在该站点中看到非常好的示例代码。这将对您有很大帮助https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/library_code

      以上示例是使用 curl 的非常好的示例

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多