QuickBooks桌面Web连接器自动运行请求队列

时间:2018-08-17 19:24:05

标签: php quickbooks

我正在使用quickbooks桌面。我想每5分钟转储一次CustomerQueryRq响应。我从ConsoliBYTE docs/web_connector/example_app_web_connector

开始

我想做什么:

我正在寻找一种不必每5分钟访问一次handler.php文件即可触发队列的方法。我相信有更好的方法。


这就是我所做的:

  1. 在网络连接器中创建并注册了.qwc文件
  2. 修改了配置,qbwc,处理程序和函数文件
  3. 创建的cron作业,每5分钟调用一次handler.php文件。 它给了我一个像这样的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!');

1 个答案:

答案 0 :(得分:1)

最简单的方法是进行连接,以便每次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工作。