我有一个需要与 quickbooks 在线版通信的网络应用程序。我能够连接和接收数据。问题是我得到的回复不是 xml 格式,甚至更好的是 json 格式。我怎样才能让它以其中一种格式回复?这是我的代码:
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 = ' ' 。日期('Ymd')。'T'。日期('H:i:s')。' ' 。$这个->会话。' 英语 ' 。$this->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 20103-04-10T21:2 :43 2013-04-10T21:20:43 0 测试产品 测试产品 0 0 1 销售