我们在Web应用程序中使用Keith Palmer/Consolibyte Solutions' excellent PHP QuickBooks Framework通过QuickBooks Web Connector与QuickBooks Desktop版本进行通信。我们在代码中使用了QuickBooks_Server
和QuickBooks_Queue
,如下所示:
$this->myQBQueue = new QuickBooks_Queue($this->myDSN);
$mappedFunctions = array(
QUICKBOOKS_ADD_CUSTOMER,
QUICKBOOKS_ADD_SALESORDER,
QUICKBOOKS_ADD_SALESRECEIPT,
QUICKBOOKS_QUERY_CUSTOMER,
);
$map = array();
foreach($mappedFunctions as $function) {
$map[$function] = array(
array($this,"quickbooks{$function}Request"),
array($this,"quickbooks{$function}Response"),
);
}
$errmap = array('*' => array($this,'quickbooksErrorHandler'));
$hooks = array(
QUICKBOOKS_HANDLERS_HOOK_LOGINFAILURE => array(
array($this,'quickbooksLoginFailureHook')
),
QUICKBOOKS_HANDLERS_HOOK_LOGINSUCCESS => array(
array($this,'quickbooksLoginSuccessHook')
)
);
$soap_options = array();
$handler_options = array();
$driver_options = array();
$callback_options = array();
$this->myQBServer = new QuickBooks_Server($this->myDSN, $map, $errmap, $hooks, QUICKBOOKS_LOG_NORMAL, QUICKBOOKS_SOAPCLIENT_BUILTIN, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);
我们现在有一位客户要求我们在线添加对QuickBooks的支持。我们是否仍然可以在线使用Keith Palmer的QuickBooks框架QuickBooks_Server
和QuickBooks_Queue
,还是必须为QuickBooks在线部分编写新代码?
答案 0 :(得分:2)
你可以重新使用Queue的东西,但是框架本身并不支持它 - 你绝对可以轻易地破解它。
您肯定能够重用大部分(但不是全部)qbXML。
QuickBooks Online确实支持qbXML界面(虽然它并不是非常好--Intuit公开表示他们可能会在明年左右弃用它,并且他们不再添加功能)。您应该知道在不久的将来,很可能您将要开始考虑转向Intuit Anywhere / IDS - 特别是如果您是一个拥有大量QuickBooks Online客户的SaaS应用程序。
您可以在此处找到QuickBooks Online的qbXML文档: http://developer.intuit.com/qbsdk-current/common/newosr/index.html (确保勾选“OE”复选框并取消选中“US”复选框)
使用QuickBooks Online吸引很多人的一些事情:
如果您查看QuickBooks PHP DevKit库代码中包含的docs / example_online_edition.php(或docs / example_raw_online_edition.php)文件,您将看到它是如何工作的。基本上不是队列,而是直接通过HTTPS向Intuit的服务器发送直接qbXML请求,而不是将其包装在SOAP中并等待Web连接器接收它。
话虽如此,如果你真的想继续使用Queue,你可以 - 像往常一样排队填充,然后设置一个像cron一样运行的脚本:
(警告 - 完全未经测试的代码,您必须进行测试和调试)
<?php
// Do some setup stuff here as shown in the example...
$res = mysql_query("SELECT * FROM quickbooks_queue WHERE qb_username = 'the username' AND qb_status = 'q'");
while ($arr = mysql_fetch_array($res))
{
$request_function = $map[$arr['qb_action']][0];
$response_function = $map[$arr['qb_action']][1];
$requestID = null; // not relevant for QBO
$user = 'the username';
$ID = $arr['ident'];
$extra = null;
if($arr['extra']) $extra = unserialize($arr['extra']);
$err = null;
$last_action_time = null;
$last_actionident_time = null;
$version = '6.0'; // QBO only supports 6.0
$locale = 'US'; // QBO only supports US
$qbxml = $request_function($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale);
$xml = $API->qbxml($qbxml);
$idents = _extractIdentifiers($xml); // You can find this function in QuickBooks/Handlers.php and pull it into your app as a function instead of a method
$response_function($requestID, $user, $action, $ID, $extra, $err, $last_action_time, $last_actionident_time, $xml, $idents);
}