繁体   English   中英

使用HTML发布表单将数据发布到外部服务器后,如何提取php响应查询字符串?

[英]How extract php response query string after posting data to external server using html post form?

使用HTML发布表单将数据发布到外部服务器后,如何提取php响应查询字符串?

页面:delivery.php

<form name="form2" method="post" action="http://dev.site.com/pay/transactionresult" id="form1">
    <input type="hidden" value="<?php echo $amt;?>" name="amt" />
    <input type="hidden" name="merchant" value="abc">
    <input type="hidden" name="orderid" value="<?php echo $orderid;?>">
    <input type="hidden" name="referenceid" value="<?php echo  $referenceid;?>">
    <input type="submit" value="submit"/>
</form>

如开发人员指南所示,我认为结果是xml

响应

<response>
    <response_code>
        success
    </response_code>
</response>

<response>
    <response_code>
        failure
    </response_code>
</response>

如何获得回应? 请显示代码。 响应代码可以在delivery.php吗?

如果要处理对远程服务器发布的响应,则必须在服务器端而不是由客户端(浏览器)执行发布。

所以这样的想法是:

client --POST--> your server --response--> client
                  |      ^
                 POST    |
                  |   response
                  V      |
                remote server

因此,向用户显示一个页面,用户可以在其中填写所需的数据,然后将其发布到服务器上的表单处理程序页面。 该处理程序页面可以向远程服务器发出请求,并解析响应,可以为客户端生成适当的答案。

例如,您可以使用CURL在服务器端发出远程请求。

一个例子可能是这样的:(基于另一个SO答案的 CURL示例)

<?php
if (empty($_POST['amt'])) {
  // show form
} else {
    $data = ...; // collect and filter data from form

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,"http://remote.example.com/transaction");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

    // receive server response ...
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $server_output = curl_exec ($ch);

    curl_close ($ch);

    // further processing ....
    if ($server_output == "OK") {
        // parse $server_output
        $message = 'success';
    } else {
        $message = 'error';
    }

    // show $message to user
}
?>

这个例子绝不完整,但希望能给您一个想法。

我给您的印象是,您只是在学习编程,但是您想使用http://www.resellerclub.com/domain-reseller/api的服务来向客户销售产品。

一种选择是让客户提交直接发送到转销商俱乐部的表格,但这样做对他们的回报并不友好。 一种替代方法是让您的用户向您的服务器提交表单,然后您的服务器向resellerclub.com发出请求。 (通过CURL)您将收到转销商俱乐部的回复(强烈建议使用http JSON选项!),您可以根据自己的喜好进行处理(通常向网站用户提供回复,感谢他们的提交)

为此,您必须将表格action=更改为action="darrens_server.com/payment_submission.php"并且在该php文件中,您可以将内容提交给resellerclub,等待响应,然后将结果回显到网站用户。

我会说,如果涉及信用卡,这可能不是最好的方法。 通常,我会避免处理信用卡交易,我希望一家货币公司为我做这件事(例如,贝宝),我不需要出现问题或我公司中的任何人都可以看到用户的信用卡号的责任。 在这种情况下,整个处理过程实际上取决于resellerclub.com。 您需要遵循他们的规则。

祝你好运。

将此表单提交到外部服务器后,响应将发送到您的浏览器,而不是您的服务器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM