目标:我们正尝试使用QuickBooks Web连接器每小时从Windows版QuickBooks Desktop中获取所有交易。
状态:QuickBooks Web Connector可以在配置的qwc文件中成功运行。
问题:QuickBooks Web Connector返回绿色消息“不需要数据交换”。我希望事务存储在log.txt中。下面是我的代码。我怀疑这是一个排队问题?我希望所有问题都出现在该文件中,该文件每小时在QBWC中运行一次,以获取所有交易。您能提供的任何帮助将不胜感激。
//web_connector.php - called every 60 min from QBWC
$map = array(
'*' => array( '_quickbooks_get_transactions', '_quickbooks_get_transactions_response' ),
);
$log_level = QUICKBOOKS_LOG_DEVELOP;
$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;
$handler_options = array(
'deny_concurrent_logins' => false,
'deny_reallyfast_logins' => false,
);
$dsn = 'mysqli://'.$dbUser.':'.$dbPass.'@localhost/'.$dbName;
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);
}
//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);
function _quickbooks_get_transactions($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
//I want to get all transactions from this QuickBooks file and then insert into a database table on my cloud server.
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<TransactionQuery requestID="' . $requestID . '">
</TransactionQuery>
</QBXMLMsgsRq>
</QBXML>';
return $xml;
}
function _quickbooks_get_transactions_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
//I want to get all transactions from this QuickBooks file and then insert into a database table on my cloud server.
//store returned data in text file for testing
$fp = fopen('log.txt', 'a+');
fwrite($fp, $xml);
fclose($fp);
return;
}
答案 0 :(得分:0)
该消息的确切含义是:
没有数据可交换。无事可做。
Web连接器和此框架使用“队列”概念工作。队列为空后,无需执行其他任何操作,您将收到该消息。如果您将某些内容添加到队列中,它将处理这些项目,直到无所事事为止,然后您将再次收到“无数据交换…”消息。
您尚未向队列添加任何内容。
您可以使用cron作业或来实现此目的,方法是注册一个在Web连接器连接时即运行并立即将某些内容填充到队列中的函数。例如:
// An array of callback hooks
$hooks = array(
QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => '_quickbooks_hook_loginsuccess', // call this whenever a successful login occurs
);
/**
* Login success hook - perform an action when a user logs in via the Web Connector
*/
function _quickbooks_hook_loginsuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config)
{
// For new users, we need to set up a few things
// Fetch the queue instance
$Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
$Queue->enqueue(QUICKBOOKS_IMPORT_TRANSACTION);
}
您可以在此处看到扩展示例:
您可能希望从示例中删除一些其他内容:
<?qbxml version="2.0"?>
)