QuickBooks 桌面 PHP 开发工具包客户 Authenticate/Add
QuickBooks Desktop PHP Dev Kit Customer Authenticate/Add
我的 QuickBooks XML 版本是 13.0。我用过 example_web_connector_auth.php(https://github.com/consolibyte/quickbooks-php/blob/master/docs/web_connector/example_web_connector_auth.php)。它应该已经添加了一个客户。但是没有添加任何东西。我不知道它有什么问题或我该如何解决?核心错误貌似-"Response is not well-formed XML"。它可能是一个 SOAP 异常,虽然我还不确定。
PHP 错误日志如下所示。它不包含涉及 XML 的错误,仅返回 SQL 弃用消息:
[02-Nov-2015 14:55:28 America/New_York] PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\xampp\htdocs\qb\QuickBooks\Driver\Sql\Mysql.php on line 289
修改后的SQL日志为:
(12, NULL, 0, 'Handler is starting up...: array (\n ''qb_company_file'' => NULL,\n ''qbwc_min_version'' => NULL,\n ''qbwc_wait_before_next_update'' => NULL,\n ''qbwc_min_run_every_n_seconds'' => NULL,\n ''qbwc_version_warning_message'' => NULL,\n ''qbwc_version_error_message'' => NULL,\n ''qbwc_interactive_url'' => NULL,\n ''autoadd_missing_requestid'' => true,\n ''check_valid_requestid'' => true,\n ''server_version'' => ''PHP QuickBooks SOAP Server v3.0 at /qb/docs/web_connector/example_web_connector_auth.php'',\n ''authenticate'' => ''_quickbooks_custom_auth'',\n ''authenticate_dsn'' => NULL,\n ''map_application_identifiers'' => true,\n ''allow_remote_addr'' => \n array (\n ),\n ''deny_remote_addr'' => \n array (\n ),\n ''convert_unix_newlines'' => true,\n ''deny_concurrent_logins'' => false,\n ''deny_concurrent_timeout'' => 60,\n ''deny_reallyfast_logins'' => true,\n ''deny_reallyfast_timeout'' => 600,\n ''masking'' => true,\n)', '2015-11-02 14:36:01'),
(13, NULL, 0, 'Incoming HTTP Headers: User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.42000)\nContent-Type: text/xml; charset=utf-8\nSOAPAction: "http://developer.intuit.com/authenticate"\nHost: localhost:24260\nContent-Length: 384\nExpect: 100-continue\n', '2015-11-02 14:36:01'),
(14, NULL, 0, 'Incoming SOAP Request: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><authenticate xmlns="http://developer.intuit.com/"><strUserName>quickbooks</strUserName><strPassword>xxxxxxxx</strPassword></authenticate></soap:Body></soap:Envelope>', '2015-11-02 14:36:01'),
(15, NULL, 0, 'authenticate()', '2015-11-02 14:36:01'),
(16, NULL, 0, 'Calling auth callback [function]: _quickbooks_custom_auth', '2015-11-02 14:36:01'),
(17, NULL, 0, 'Calling auth function: _quickbooks_custom_auth', '2015-11-02 14:36:01'),
(18, 1, 0, 'Login via _quickbooks_custom_auth: quickbooks', '2015-11-02 14:36:02'),
(19, NULL, 0, 'Outgoing SOAP Response: <?xml version="1.0" encoding="UTF-8"?>\n <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" \n xmlns:ns1="http://developer.intuit.com/">\n <SOAP-ENV:Body><ns1:authenticateResponse><ns1:authenticateResult><ns1:string>b221c6f1-17b1-6164-9578-3b6760753d5c</ns1:string>\n<ns1:string>C:\Users\Public\Documents\Intuit\QuickBooks\Sample Company Files\QuickBooks Enterprise Solutions 14.0\sample_product-based business.QBW</ns1:string>\n</ns1:authenticateResult></ns1:authenticateResponse>\n </SOAP-ENV:Body>\n </SOAP-ENV:Envelope>', '2015-11-02 14:36:02');
和 QWClog.txt returns 下面的行:
20151102.19:55:25 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : *** Calling serverVersion().
20151102.19:55:26 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : Actual error received from web service for serverVersion call: <Response is not well-formed XML.>. For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-serverVersion.
20151102.19:55:27 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : This application does not contain support for serverVersion. Allowing update operation for backward compatibility.
20151102.19:55:27 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : *** Calling clientVersion() with following parameter:<productVersion="2.1.0.30">
20151102.19:55:27 UTC : QBWebConnector.SOAPWebService.updateWS() : Actual error received from web service for clientVersion call: <Response is not well-formed XML.>. For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-clientVersion.
20151102.19:55:27 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : This application does not contain support for clientVersion. Allowing update operation for backward compatibility.
20151102.19:55:27 UTC : QBWebConnector.SOAPWebService.do_authenticate() : Authenticating to application 'QuickBooks Integrator', username = 'quickbooks'
20151102.19:55:28 UTC : QBWebConnector.SOAPWebService.do_authenticate() : *** Calling authenticate() with following parameters:<userName="quickbooks"><password=<MaskedForSecurity>
20151102.19:55:29 UTC : QBWebConnector.SOAPWebService.do_authenticate() : QBWC1012: Authentication failed due to following error message.
Response is not well-formed XML.
More info:
StackTrace = at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at QBWebConnector.localhost.WCWebServiceDoc.authenticate(String strUserName, String strPassword)
at QBWebConnector.localhost.WCWebService.authenticate(String strUserName, String strPassword)
at QBWebConnector.SOAPWebService.authenticate(String UserName, String Password)
at QBWebConnector.WebService.do_authenticate(String& ticket, String& companyFileName)
Source = System.Web.Services
而PHP代码如下。我的 DSN 是正确的。 PHP 版本为 5.5+:
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
if (function_exists('date_default_timezone_set')){
date_default_timezone_set('America/New_York');
}
require_once '../../QuickBooks.php';
$user = 'quickbooks';
$pass = 'password';
$map = array(
QUICKBOOKS_ADD_CUSTOMER => array( '_quickbooks_customer_add_request', '_quickbooks_customer_add_response' ),
);
$errmap = array(
3070 => '_quickbooks_error_stringtoolong'
);
$hooks = array();
$log_level = QUICKBOOKS_LOG_DEBUG;
$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;
$soap_options = array();
$handler_options = array(
'deny_concurrent_logins' => false,
'deny_reallyfast_logins' => false,
);
$driver_options = array();
$callback_options = array();
$dsn = 'mysql://root@localhost/quickbooks_server';
if (!QuickBooks_Utilities::initialized($dsn)){
QuickBooks_Utilities::initialize($dsn);
QuickBooks_Utilities::createUser($dsn, $user, $pass);
$primary_key_of_your_customer = 5;
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);
}
$Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level, $soapserver, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);
$response = $Server->handle(true, true);
function _quickbooks_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<CustomerAddRq requestID="' . $requestID . '">
<CustomerAdd>
<Name>ConsoliBYTE, LLC (' . mt_rand() . ')</Name>
<CompanyName>ConsoliBYTE, LLC</CompanyName>
<FirstName>Keith</FirstName>
<LastName>Palmer</LastName>
<BillAddress>
<Addr1>ConsoliBYTE, LLC</Addr1>
<Addr2>134 Stonemill Road</Addr2>
<City>Mansfield</City>
<State>CT</State>
<PostalCode>06268</PostalCode>
<Country>United States</Country>
</BillAddress>
<Phone>860-634-1602</Phone>
<AltPhone>860-429-0021</AltPhone>
<Fax>860-429-5183</Fax>
<Email>Keith@ConsoliBYTE.com</Email>
<Contact>Keith Palmer</Contact>
</CustomerAdd>
</CustomerAddRq>
</QBXMLMsgsRq>
</QBXML>';
return $xml;
}
function _quickbooks_customer_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
//
}
function _quickbooks_error_stringtoolong($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{
mail('your-email@your-domain.com',
'QuickBooks error occured!',
'QuickBooks thinks that ' . $action . ': ' . $ID . ' has a value which will not fit in a QuickBooks field...');
}
此错误:
Response is not well-formed XML
表示您有 PHP 或 SQL 错误。您似乎在这里发现了错误:
[02-Nov-2015 14:55:28 America/New_York] PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\xampp\htdocs\qb\QuickBooks\Driver\Sql\Mysql.php on line 289
您需要修复该错误。
您可以通过更改 $dsn
字符串以使用未弃用的数据库驱动程序来实现,例如:
$dsn = 'mysqli://...';
我的 QuickBooks XML 版本是 13.0。我用过 example_web_connector_auth.php(https://github.com/consolibyte/quickbooks-php/blob/master/docs/web_connector/example_web_connector_auth.php)。它应该已经添加了一个客户。但是没有添加任何东西。我不知道它有什么问题或我该如何解决?核心错误貌似-"Response is not well-formed XML"。它可能是一个 SOAP 异常,虽然我还不确定。
PHP 错误日志如下所示。它不包含涉及 XML 的错误,仅返回 SQL 弃用消息:
[02-Nov-2015 14:55:28 America/New_York] PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\xampp\htdocs\qb\QuickBooks\Driver\Sql\Mysql.php on line 289
修改后的SQL日志为:
(12, NULL, 0, 'Handler is starting up...: array (\n ''qb_company_file'' => NULL,\n ''qbwc_min_version'' => NULL,\n ''qbwc_wait_before_next_update'' => NULL,\n ''qbwc_min_run_every_n_seconds'' => NULL,\n ''qbwc_version_warning_message'' => NULL,\n ''qbwc_version_error_message'' => NULL,\n ''qbwc_interactive_url'' => NULL,\n ''autoadd_missing_requestid'' => true,\n ''check_valid_requestid'' => true,\n ''server_version'' => ''PHP QuickBooks SOAP Server v3.0 at /qb/docs/web_connector/example_web_connector_auth.php'',\n ''authenticate'' => ''_quickbooks_custom_auth'',\n ''authenticate_dsn'' => NULL,\n ''map_application_identifiers'' => true,\n ''allow_remote_addr'' => \n array (\n ),\n ''deny_remote_addr'' => \n array (\n ),\n ''convert_unix_newlines'' => true,\n ''deny_concurrent_logins'' => false,\n ''deny_concurrent_timeout'' => 60,\n ''deny_reallyfast_logins'' => true,\n ''deny_reallyfast_timeout'' => 600,\n ''masking'' => true,\n)', '2015-11-02 14:36:01'),
(13, NULL, 0, 'Incoming HTTP Headers: User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.42000)\nContent-Type: text/xml; charset=utf-8\nSOAPAction: "http://developer.intuit.com/authenticate"\nHost: localhost:24260\nContent-Length: 384\nExpect: 100-continue\n', '2015-11-02 14:36:01'),
(14, NULL, 0, 'Incoming SOAP Request: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><authenticate xmlns="http://developer.intuit.com/"><strUserName>quickbooks</strUserName><strPassword>xxxxxxxx</strPassword></authenticate></soap:Body></soap:Envelope>', '2015-11-02 14:36:01'),
(15, NULL, 0, 'authenticate()', '2015-11-02 14:36:01'),
(16, NULL, 0, 'Calling auth callback [function]: _quickbooks_custom_auth', '2015-11-02 14:36:01'),
(17, NULL, 0, 'Calling auth function: _quickbooks_custom_auth', '2015-11-02 14:36:01'),
(18, 1, 0, 'Login via _quickbooks_custom_auth: quickbooks', '2015-11-02 14:36:02'),
(19, NULL, 0, 'Outgoing SOAP Response: <?xml version="1.0" encoding="UTF-8"?>\n <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" \n xmlns:ns1="http://developer.intuit.com/">\n <SOAP-ENV:Body><ns1:authenticateResponse><ns1:authenticateResult><ns1:string>b221c6f1-17b1-6164-9578-3b6760753d5c</ns1:string>\n<ns1:string>C:\Users\Public\Documents\Intuit\QuickBooks\Sample Company Files\QuickBooks Enterprise Solutions 14.0\sample_product-based business.QBW</ns1:string>\n</ns1:authenticateResult></ns1:authenticateResponse>\n </SOAP-ENV:Body>\n </SOAP-ENV:Envelope>', '2015-11-02 14:36:02');
和 QWClog.txt returns 下面的行:
20151102.19:55:25 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : *** Calling serverVersion().
20151102.19:55:26 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : Actual error received from web service for serverVersion call: <Response is not well-formed XML.>. For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-serverVersion.
20151102.19:55:27 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : This application does not contain support for serverVersion. Allowing update operation for backward compatibility.
20151102.19:55:27 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : *** Calling clientVersion() with following parameter:<productVersion="2.1.0.30">
20151102.19:55:27 UTC : QBWebConnector.SOAPWebService.updateWS() : Actual error received from web service for clientVersion call: <Response is not well-formed XML.>. For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-clientVersion.
20151102.19:55:27 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : This application does not contain support for clientVersion. Allowing update operation for backward compatibility.
20151102.19:55:27 UTC : QBWebConnector.SOAPWebService.do_authenticate() : Authenticating to application 'QuickBooks Integrator', username = 'quickbooks'
20151102.19:55:28 UTC : QBWebConnector.SOAPWebService.do_authenticate() : *** Calling authenticate() with following parameters:<userName="quickbooks"><password=<MaskedForSecurity>
20151102.19:55:29 UTC : QBWebConnector.SOAPWebService.do_authenticate() : QBWC1012: Authentication failed due to following error message.
Response is not well-formed XML.
More info:
StackTrace = at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at QBWebConnector.localhost.WCWebServiceDoc.authenticate(String strUserName, String strPassword)
at QBWebConnector.localhost.WCWebService.authenticate(String strUserName, String strPassword)
at QBWebConnector.SOAPWebService.authenticate(String UserName, String Password)
at QBWebConnector.WebService.do_authenticate(String& ticket, String& companyFileName)
Source = System.Web.Services
而PHP代码如下。我的 DSN 是正确的。 PHP 版本为 5.5+:
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
if (function_exists('date_default_timezone_set')){
date_default_timezone_set('America/New_York');
}
require_once '../../QuickBooks.php';
$user = 'quickbooks';
$pass = 'password';
$map = array(
QUICKBOOKS_ADD_CUSTOMER => array( '_quickbooks_customer_add_request', '_quickbooks_customer_add_response' ),
);
$errmap = array(
3070 => '_quickbooks_error_stringtoolong'
);
$hooks = array();
$log_level = QUICKBOOKS_LOG_DEBUG;
$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;
$soap_options = array();
$handler_options = array(
'deny_concurrent_logins' => false,
'deny_reallyfast_logins' => false,
);
$driver_options = array();
$callback_options = array();
$dsn = 'mysql://root@localhost/quickbooks_server';
if (!QuickBooks_Utilities::initialized($dsn)){
QuickBooks_Utilities::initialize($dsn);
QuickBooks_Utilities::createUser($dsn, $user, $pass);
$primary_key_of_your_customer = 5;
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);
}
$Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level, $soapserver, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);
$response = $Server->handle(true, true);
function _quickbooks_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<CustomerAddRq requestID="' . $requestID . '">
<CustomerAdd>
<Name>ConsoliBYTE, LLC (' . mt_rand() . ')</Name>
<CompanyName>ConsoliBYTE, LLC</CompanyName>
<FirstName>Keith</FirstName>
<LastName>Palmer</LastName>
<BillAddress>
<Addr1>ConsoliBYTE, LLC</Addr1>
<Addr2>134 Stonemill Road</Addr2>
<City>Mansfield</City>
<State>CT</State>
<PostalCode>06268</PostalCode>
<Country>United States</Country>
</BillAddress>
<Phone>860-634-1602</Phone>
<AltPhone>860-429-0021</AltPhone>
<Fax>860-429-5183</Fax>
<Email>Keith@ConsoliBYTE.com</Email>
<Contact>Keith Palmer</Contact>
</CustomerAdd>
</CustomerAddRq>
</QBXMLMsgsRq>
</QBXML>';
return $xml;
}
function _quickbooks_customer_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
//
}
function _quickbooks_error_stringtoolong($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{
mail('your-email@your-domain.com',
'QuickBooks error occured!',
'QuickBooks thinks that ' . $action . ': ' . $ID . ' has a value which will not fit in a QuickBooks field...');
}
此错误:
Response is not well-formed XML
表示您有 PHP 或 SQL 错误。您似乎在这里发现了错误:
[02-Nov-2015 14:55:28 America/New_York] PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\xampp\htdocs\qb\QuickBooks\Driver\Sql\Mysql.php on line 289
您需要修复该错误。
您可以通过更改 $dsn
字符串以使用未弃用的数据库驱动程序来实现,例如:
$dsn = 'mysqli://...';