QuickBooks 桌面 Web 连接器自动运行请求队列
QuickBooks Desktop Web Connector Autorun a Request Queue
我正在使用 quickbooks 桌面版。我想每 5 分钟转储一次 CustomerQueryRq
响应。我从 ConsoliBYTE docs/web_connector/example_app_web_connector
开始
我想做的事情:
我正在寻找一种无需每 5 分钟访问 handler.php 文件即可触发队列的方法。我相信有更好的方法。
这是我所做的:
- 在 Web 连接器中创建并注册了一个
.qwc
文件
- 修改了配置、qbwc、处理程序和函数文件
- 已创建每 5 分钟调用一次 handler.php 文件的 cron 作业。
它给了我一个像这样的 json 文件:json file 这正是我想要的。
qbwc.php:
require_once dirname(__FILE__) . '/config.php';
require_once dirname(__FILE__) . '/functions.php';
// Map QuickBooks actions to handler functions
$map = array(
QUICKBOOKS_QUERY_CUSTOMER => array( '_quickbooks_customer_query_request', '_quickbooks_customer_query_response' ),
);
$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);
functions.php:
function _quickbooks_customer_query_request($ListID = null, $FullName = null)
{
$xml = '
<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="continueOnError">
<CustomerQueryRq />
</QBXMLMsgsRq>
</QBXML>
';
return $xml;
}
function _quickbooks_customer_query_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
$xmlData = simplexml_load_string($xml);
$json = json_encode($xmlData->QBXMLMsgsRs->CustomerQueryRs, true);
file_put_contents('customerDump.json', $json);
}
handler.php:
require_once dirname(__FILE__) . '/config.php';
// Queue up the customer dump
$Queue = new QuickBooks_WebConnector_Queue($con);
$Queue->enqueue(QUICKBOOKS_QUERY_CUSTOMER, 2);
die('Great, queued up customer dump!');
最简单的方法是让每次 Web 连接器连接时,它都会将您想要的请求排队 运行。
为此:
注册一个钩子函数,只要 Web 连接器连接运行就会
$hooks = array(
QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => 'your_function_name_here', // call this whenever a successful login occurs
);
让那个函数把东西扔进队列
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 stuff up
$Queue->enqueue(QUICKBOOKS_QUERY_CUSTOMER, 2);
}
因此,每次 Web 连接器连接时,您的东西都会被塞入队列并进行处理。不需要 cron
工作。
我正在使用 quickbooks 桌面版。我想每 5 分钟转储一次 CustomerQueryRq
响应。我从 ConsoliBYTE docs/web_connector/example_app_web_connector
我想做的事情:
我正在寻找一种无需每 5 分钟访问 handler.php 文件即可触发队列的方法。我相信有更好的方法。
这是我所做的:
- 在 Web 连接器中创建并注册了一个
.qwc
文件 - 修改了配置、qbwc、处理程序和函数文件
- 已创建每 5 分钟调用一次 handler.php 文件的 cron 作业。 它给了我一个像这样的 json 文件:json file 这正是我想要的。
qbwc.php:
require_once dirname(__FILE__) . '/config.php';
require_once dirname(__FILE__) . '/functions.php';
// Map QuickBooks actions to handler functions
$map = array(
QUICKBOOKS_QUERY_CUSTOMER => array( '_quickbooks_customer_query_request', '_quickbooks_customer_query_response' ),
);
$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);
functions.php:
function _quickbooks_customer_query_request($ListID = null, $FullName = null)
{
$xml = '
<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="continueOnError">
<CustomerQueryRq />
</QBXMLMsgsRq>
</QBXML>
';
return $xml;
}
function _quickbooks_customer_query_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
$xmlData = simplexml_load_string($xml);
$json = json_encode($xmlData->QBXMLMsgsRs->CustomerQueryRs, true);
file_put_contents('customerDump.json', $json);
}
handler.php:
require_once dirname(__FILE__) . '/config.php';
// Queue up the customer dump
$Queue = new QuickBooks_WebConnector_Queue($con);
$Queue->enqueue(QUICKBOOKS_QUERY_CUSTOMER, 2);
die('Great, queued up customer dump!');
最简单的方法是让每次 Web 连接器连接时,它都会将您想要的请求排队 运行。
为此:
注册一个钩子函数,只要 Web 连接器连接运行就会
$hooks = array(
QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => 'your_function_name_here', // call this whenever a successful login occurs
);
让那个函数把东西扔进队列
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 stuff up
$Queue->enqueue(QUICKBOOKS_QUERY_CUSTOMER, 2);
}
因此,每次 Web 连接器连接时,您的东西都会被塞入队列并进行处理。不需要 cron
工作。