调用REST API以使用URL和参数从网站检索数据

时间:2016-03-08 11:19:33

标签: php api rest

您好我必须使用url和登录参数以及一些XML参数作为输入从网站获取信息使用PHP。我是任何API调用的新手所以请解释我如何在我的PHP代码中使用这些参数并向服务器发出请求以获取信息 当我在SOAP UI中使用它们时,我可以得到演示结果,我需要在PHP中构建相同的。

https://transact-prelive.litle.com/vap/communicator/online
Username: u82917418420715660 
Password: dENteSXnXwfqKHF 
Merchant Id: 01183990

<litleOnlineRequest version="9.4" xmlns="http://www.litle.com/schema" merchantId="01183990">
    <authentication>
        <user>u82917418420715660</user>
        <password>dENteSXnXwfqKHF</password>
    </authentication>
    <authorization id="834262" reportGroup="ABC Division" customerId="038945">
        <orderId>65347567</orderId>
        <amount>40000</amount>
        <orderSource>3dsAuthenticated</orderSource>
        <billToAddress>
            <name>John Smith</name>
            <addressLine1>100 Main St</addressLine1>
            <city>Boston</city>
            <state>MA</state>
            <zip>12345</zip>
            <email>jsmith@someaddress.com</email>
            <phone>555-123-4567</phone>
        </billToAddress>
        <card>
        <type>VI</type>
        <number>4000000000000001</number>
        <expDate>1209</expDate>
        <cardValidationNum>555</cardValidationNum>
        </card>
        <cardholderAuthentication>
            <authenticationValue></authenticationValue>
            <authenticationTransactionId></authenticationTransactionId>
        </cardholderAuthentication>
    </authorization>
</litleOnlineRequest>

1 个答案:

答案 0 :(得分:0)

您可以使用nusoap库来使用SOAP和PHP。以下是如何使用它的示例。它与您的查询类似。

        $this->load->library("lib_nusoap");
        $wsdl = "https://transact-prelive.litle.com/vap/communicator/online";
        $client = new nusoap_client($wsdl, 'wsdl');

        //$client->setCredentials($api_username,$api_password);
        $error = $client->getError();
        if ($error)
        {
            echo "\nSOAP Error\n".$error."\n";
            return false;
        }
        else
        {
            $params = array ('user' => "u82917418420715660 ", 'Password' => "dENteSXnXwfqKHF "); 
            $result = $client->call('retrive', $params);
            if ($client->fault)
            {
                print_r($result);
                print $client->fault;
            }
            else
            {
                $result_arr = json_decode($result, true);
            }    
        }
        print_r($result_arr);

Nusoap库将处理CURL API调用。