quickbooks在线互动

时间:2013-04-12 04:20:06

标签: integration quickbooks-online

我有一个网络应用程序,我需要与quickbooks在线版沟通。我能够连接和接收数据。问题是,我得到的回应不是xml格式,甚至更好的是json formate。如何让它以其中一种格式回复?这是我的代码:

function request($xml, $certificate = null, $debug = false){
    $ch = curl_init(); 

    $header[] = 'Content-Type: application/x-qbxml'; 
    $header[] = 'Content-Length: ' . strlen($xml); 

    $params = array();
    $params[CURLOPT_HTTPHEADER] = $header; 
    $params[CURLOPT_POST] = true; 
    $params[CURLOPT_RETURNTRANSFER] = true; 
    $params[CURLOPT_URL] = $this->gateway; 
    $params[CURLOPT_TIMEOUT] = 30; 
    $params[CURLOPT_POSTFIELDS] = $xml; 
    $params[CURLOPT_VERBOSE] = $debug; 
    $params[CURLOPT_HEADER] = true;

    // This is only for the HOSTED security model
    if (file_exists($certificate))
    {
        $params[CURLOPT_SSL_VERIFYPEER] = false; 
        $params[CURLOPT_SSLCERT] = $certificate; 
    }

    // Some Windows servers will fail with SSL errors unless we turn this off
    $params[CURLOPT_SSL_VERIFYPEER] = false;
    $params[CURLOPT_SSL_VERIFYHOST] = 0;        

    // Diagnostic information: https://merchantaccount.quickbooks.com/j/diag/http
    // curl_setopt($ch, CURLOPT_INTERFACE, '<myipaddress>');

    $ch = curl_init();
    curl_setopt_array($ch, $params);
    $response = curl_exec($ch);

    if (curl_errno($ch)) 
    {
        $errnum = curl_errno($ch);
        $errmsg = curl_error($ch);

        _log('CURL error: ' . $errnum . ': ' . $errmsg, $debug);

        return false;
    } 

    // Close the connection 
    @curl_close($ch);

    // Remove the HTTP headers from the response
    $pos = strpos($response, "\r\n\r\n");
    $response = ltrim(substr($response, $pos));

    return $response;       
}
function item_list(){

    $xml = 
        '<?xml version="1.0"?>
        <?qbxml version="6.0"?>
        <QBXML>
            <SignonMsgsRq>
                <SignonTicketRq>
                    <ClientDateTime>' . date('Y-m-d') . 'T' . date('H:i:s') . '</ClientDateTime>
                    <SessionTicket>' . $this->session . '</SessionTicket>
                    <Language>English</Language>
                    <AppID>' . $this->application_id . '</AppID>
                    <AppVer>1</AppVer>
                </SignonTicketRq>
            </SignonMsgsRq>
            <QBXMLMsgsRq onError="stopOnError">
                <ItemQueryRq> 
                    <OwnerID>0</OwnerID>
                </ItemQueryRq>

            </QBXMLMsgsRq>
        </QBXML>';
        $response = $this->request($xml, null, true);
        echo $response;

}

由于

这是我的xml请求:     $ xml =     “                                                 '。日期('Y-m-d')。 'T'。日期('H:i:s')。 “                 '。 $ this-&gt; session。 “                 英语                 '。 $ this-&gt; application_id。 “                 1                                                              0             

    </QBXMLMsgsRq>
</QBXML>';

以下是我的答复:

2013-04-12T12:28:11 V1-115-Q03kydq32h22tnfqnd5izf:689712285 1 2013-04-10T06:02:40 2013-04-10T06:02:40 0销售销售0 0 1销售2 2013-04- 10T21:20:43 2013-04-10T21:20:43 0测试产品测试产品0 0 1销售

1 个答案:

答案 0 :(得分:2)

我的愚蠢错误。我把我的结果回显给浏览器,它将xml标签解释为html标签。我用$ xml = simplexml_load_string($ response);的print_r($ XML);在浏览器中查看响应。