QuickBooks 桌面和 Laravel- 内容类型 xml; charset=UTF-8 但预期 text/xml
QuickBooks desktop and Laravel- content type xml; charset=UTF-8 but expected text/xml
我正在尝试获取在 Laravel (5.1) 中工作的 consolibyte quickbooks-php 的示例之一。我无法使用控制器让它工作。 Web 连接器的日志显示客户端发现响应内容类型为 'xml; charset=UTF-8',但应为 'text/xml'。
我使用的代码是 quickbooks-php demo 的略微修改版本。我一直无法找到 quickbooks-php 桌面和 laravel 的示例,并且不确定我做错了什么。
注意- require_once('../QuickBooks.php') 在 app/config/app.php.
控制器
public function sync(RequestInterface $request, InvoiceSyncService $obj){
$this->logger->info('############################### Start QB sync (laravel) ######################################');
$user = 'user';
$pass = 'password';
// Map QuickBooks actions to handler functions
$map = array(
QUICKBOOKS_ADD_CUSTOMER => array( array( $obj, 'addCustomerRequest' ), array( $obj, 'addCustomerResponse' ) ),
);
// This is entirely optional, use it to trigger actions when an error is returned by QuickBooks
$errmap = array(
500 => array( $obj, 'handleError500' ),
);
// An array of callback hooks
$hooks = array(
);
// Logging level
$log_level = QUICKBOOKS_LOG_DEVELOP; // Use this level until you're sure everything works!!!
// What SOAP server you're using
$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN; // A pure-PHP SOAP server (no PHP ext/soap extension required, also makes debugging easier)
$soap_options = array( // See http://www.php.net/soap
);
$handler_options = array(
); // See the comments in the QuickBooks/Server/Handlers.php file
$driver_options = array(
);
$callback_options = array(
);
$dsn = 'mysqli://username:password@localhost/database';
if (!QuickBooks_Utilities::initialized($dsn))
{
// Initialize creates the neccessary database schema for queueing up requests and logging
QuickBooks_Utilities::initialize($dsn);
// This creates a username and password which is used by the Web Connector to authenticate
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);
}
// Set the DSN string because some of our callbacks will use it
$obj->setDSN($dsn);
// Create a new server and tell it to handle the requests
$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);
return response()->view('invoicing/sync', ['response' => $response])->header('Content-type', 'xml');
}
发票同步服务
protected $_dsn;
private $logger;
public function __construct(LoggerFactory $loggerFactory)
{
$this->logger = $loggerFactory->createLogger('invoice-sync');
}
public function setDSN($dsn)
{
$this->_dsn = $dsn;
}
public function addCustomerRequest($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
$this->logger->info('A request occurred');
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<CustomerAddRq>
<CustomerAdd>
<Name>ConsoliBYTE Solutions (' . mt_rand() . ')</Name>
<CompanyName>ConsoliBYTE Solutions</CompanyName>
<FirstName>Keith</FirstName>
<LastName>Palmer</LastName>
<BillAddress>
<Addr1>ConsoliBYTE Solutions</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;
}
public function addCustomerResponse($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
$this->logger->info('A response occured');
}
public function handleError500($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{
// return true; // If you return TRUE, it will continue to process requests
return false; // If you return FALSE, it will stop processing requests
}
public function hookLoginSuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config)
{
if ($this->_dsn)
{
return true;
}
return false;
}
编辑
这是格式不正确的 Web 连接器日志 xml。
20190201.22:01:32 UTC : QBWebConnector.WebServiceManager.DoUpdateSelected() : updateWS() for application = 'Laravel' has STARTED
20190201.22:01:32 UTC : QBWebConnector.RegistryManager.getUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock = FALSE
20190201.22:01:32 UTC : QBWebConnector.RegistryManager.setUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock has been set to True
20190201.22:01:32 UTC : QBWebConnector.RegistryManager.setUpdateLock() : ********************* Update session locked *********************
20190201.22:01:32 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : Initiated connection to the following application.
20190201.22:01:32 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppName: Laravel
20190201.22:01:32 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppUniqueName (if available): Laravel
20190201.22:01:32 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppURL: http://localhostvisuals/invoicing/sync
20190201.22:01:32 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : * Calling serverVersion().
20190201.22:01:33 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : Actual error received from web service for serverVersion call: . For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-serverVersion.
20190201.22:01:33 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : This application does not contain support for serverVersion. Allowing update operation for backward compatibility.
20190201.22:01:33 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : * Calling clientVersion() with following parameter:
20190201.22:01:34 UTC : QBWebConnector.SOAPWebService.updateWS() : Actual error received from web service for clientVersion call: . For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-clientVersion.
20190201.22:01:34 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : This application does not contain support for clientVersion. Allowing update operation for backward compatibility.
20190201.22:01:34 UTC : QBWebConnector.SOAPWebService.do_authenticate() : Authenticating to application 'Laravel', username = ‘user’
20190201.22:01:34 UTC : QBWebConnector.SOAPWebService.do_authenticate() : *** Calling authenticate() with following parameters:
20190201.22:01:34 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
20190201.22:01:34 UTC : QBWebConnector.RegistryManager.setUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock has been set to False
20190201.22:01:34 UTC : QBWebConnector.RegistryManager.setUpdateLock() : ********************* Update session unlocked *********************
20190201.22:01:34 UTC : QBWebConnector.WebServiceManager.DoUpdateSelected() : Update completed with errors. See log (QWClog.txt) for details.
您想要的内容类型是 text/xml
,而不仅仅是 xml
。
例如改变这个:
return response()->view('invoicing/sync', ['response' => $response])->header('Content-type', 'xml');
}
为此:
return response()->view('invoicing/sync', ['response' => $response])->header('Content-type', 'text/xml');
}
只是 xml
不是有效的内容类型。
我正在尝试获取在 Laravel (5.1) 中工作的 consolibyte quickbooks-php 的示例之一。我无法使用控制器让它工作。 Web 连接器的日志显示客户端发现响应内容类型为 'xml; charset=UTF-8',但应为 'text/xml'。
我使用的代码是 quickbooks-php demo 的略微修改版本。我一直无法找到 quickbooks-php 桌面和 laravel 的示例,并且不确定我做错了什么。
注意- require_once('../QuickBooks.php') 在 app/config/app.php.
控制器
public function sync(RequestInterface $request, InvoiceSyncService $obj){
$this->logger->info('############################### Start QB sync (laravel) ######################################');
$user = 'user';
$pass = 'password';
// Map QuickBooks actions to handler functions
$map = array(
QUICKBOOKS_ADD_CUSTOMER => array( array( $obj, 'addCustomerRequest' ), array( $obj, 'addCustomerResponse' ) ),
);
// This is entirely optional, use it to trigger actions when an error is returned by QuickBooks
$errmap = array(
500 => array( $obj, 'handleError500' ),
);
// An array of callback hooks
$hooks = array(
);
// Logging level
$log_level = QUICKBOOKS_LOG_DEVELOP; // Use this level until you're sure everything works!!!
// What SOAP server you're using
$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN; // A pure-PHP SOAP server (no PHP ext/soap extension required, also makes debugging easier)
$soap_options = array( // See http://www.php.net/soap
);
$handler_options = array(
); // See the comments in the QuickBooks/Server/Handlers.php file
$driver_options = array(
);
$callback_options = array(
);
$dsn = 'mysqli://username:password@localhost/database';
if (!QuickBooks_Utilities::initialized($dsn))
{
// Initialize creates the neccessary database schema for queueing up requests and logging
QuickBooks_Utilities::initialize($dsn);
// This creates a username and password which is used by the Web Connector to authenticate
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);
}
// Set the DSN string because some of our callbacks will use it
$obj->setDSN($dsn);
// Create a new server and tell it to handle the requests
$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);
return response()->view('invoicing/sync', ['response' => $response])->header('Content-type', 'xml');
}
发票同步服务
protected $_dsn;
private $logger;
public function __construct(LoggerFactory $loggerFactory)
{
$this->logger = $loggerFactory->createLogger('invoice-sync');
}
public function setDSN($dsn)
{
$this->_dsn = $dsn;
}
public function addCustomerRequest($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
$this->logger->info('A request occurred');
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<CustomerAddRq>
<CustomerAdd>
<Name>ConsoliBYTE Solutions (' . mt_rand() . ')</Name>
<CompanyName>ConsoliBYTE Solutions</CompanyName>
<FirstName>Keith</FirstName>
<LastName>Palmer</LastName>
<BillAddress>
<Addr1>ConsoliBYTE Solutions</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;
}
public function addCustomerResponse($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
$this->logger->info('A response occured');
}
public function handleError500($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{
// return true; // If you return TRUE, it will continue to process requests
return false; // If you return FALSE, it will stop processing requests
}
public function hookLoginSuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config)
{
if ($this->_dsn)
{
return true;
}
return false;
}
编辑
这是格式不正确的 Web 连接器日志 xml。
20190201.22:01:32 UTC : QBWebConnector.WebServiceManager.DoUpdateSelected() : updateWS() for application = 'Laravel' has STARTED 20190201.22:01:32 UTC : QBWebConnector.RegistryManager.getUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock = FALSE 20190201.22:01:32 UTC : QBWebConnector.RegistryManager.setUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock has been set to True 20190201.22:01:32 UTC : QBWebConnector.RegistryManager.setUpdateLock() : ********************* Update session locked ********************* 20190201.22:01:32 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : Initiated connection to the following application. 20190201.22:01:32 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppName: Laravel 20190201.22:01:32 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppUniqueName (if available): Laravel 20190201.22:01:32 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppURL: http://localhostvisuals/invoicing/sync 20190201.22:01:32 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : * Calling serverVersion(). 20190201.22:01:33 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : Actual error received from web service for serverVersion call: . For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-serverVersion. 20190201.22:01:33 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : This application does not contain support for serverVersion. Allowing update operation for backward compatibility. 20190201.22:01:33 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : * Calling clientVersion() with following parameter: 20190201.22:01:34 UTC : QBWebConnector.SOAPWebService.updateWS() : Actual error received from web service for clientVersion call: . For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-clientVersion. 20190201.22:01:34 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : This application does not contain support for clientVersion. Allowing update operation for backward compatibility. 20190201.22:01:34 UTC : QBWebConnector.SOAPWebService.do_authenticate() : Authenticating to application 'Laravel', username = ‘user’ 20190201.22:01:34 UTC : QBWebConnector.SOAPWebService.do_authenticate() : *** Calling authenticate() with following parameters: 20190201.22:01:34 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 20190201.22:01:34 UTC : QBWebConnector.RegistryManager.setUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock has been set to False 20190201.22:01:34 UTC : QBWebConnector.RegistryManager.setUpdateLock() : ********************* Update session unlocked ********************* 20190201.22:01:34 UTC : QBWebConnector.WebServiceManager.DoUpdateSelected() : Update completed with errors. See log (QWClog.txt) for details.
您想要的内容类型是 text/xml
,而不仅仅是 xml
。
例如改变这个:
return response()->view('invoicing/sync', ['response' => $response])->header('Content-type', 'xml');
}
为此:
return response()->view('invoicing/sync', ['response' => $response])->header('Content-type', 'text/xml');
}
只是 xml
不是有效的内容类型。