想要将 quickbooks 桌面与 php 集成

我正在尝试使用以下 github 存储库集成 quickbook 桌面版本:


https://github.com/consolibyte/quickbooks-php


但是当我使用您的示例代码(即 mydomain.com/qb_desktop/docs/web_connector/customer.php)创建自定义新文件以从我们的网站将客户创建到 QB 桌面应用程序中时


在 Web 连接器中添加此文件并运行此文件后,它会继续运行并不断创建新的无限客户,直到我在 php 脚本中添加“die”以强制停止此操作。


你能看看我下面的代码,让我知道我在这里到底做错了什么吗?


提前致谢。


<?php

$primary_key_of_your_customer = 5;

require_once '../../QuickBooks.php';

$user = 'user';

$pass = 'password';

$map = array(QUICKBOOKS_ADD_CUSTOMER => array( '_quickbooks_customer_add_request', '_quickbooks_customer_add_response'));

$errmap = array( 3070 => '_quickbooks_error_stringtoolong');

$hooks = array();

$log_level = QUICKBOOKS_LOG_DEBUG;  

$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;

$soap_options = array();

$handler_options = array('deny_concurrent_logins' => false,

            'deny_reallyfast_logins' => false);

$driver_options = array();

$callback_options = array();

$dsn = 'mysqli://root:password@localhost/quickbooks';

$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);

$Queue = new QuickBooks_WebConnector_Queue($dsn);

$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);


function _quickbooks_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)

{

    $xml = '<?xml version="1.0" encoding="utf-8"?>

        <?qbxml version="2.0"?>

        <QBXML>

            <QBXMLMsgsRq onError="stopOnError">

                <CustomerAddRq requestID="' . $requestID . '">

                    <CustomerAdd>

                        <Name>ConsoliBYTE, LLC (' . mt_rand() . ')</Name>

慕容3067478
浏览 86回答 1
1回答

撒科打诨

Web 连接器是基于 SOAP 的,因此您实际上在这里所做的是设置 Web 连接器连接到的 SOAP 服务器。这里需要意识到的重要一点是,Web 连接器每次连接时都会对 SOAP 服务进行多次调用(例如,对您的 PHP 脚本进行许多独立的 HTTP 请求)。至少,即使没有要交换的实际数据,它也至少会进行 4 次调用:客户端版本服务器版本认证关闭连接这意味着每次 Web 连接器连接到您的服务以尝试与 QuickBooks 交换数据时,您在 PHP 脚本中放置的任何内容都至少运行 4 次。所以每次 Web 连接器连接时,这段代码至少运行 4 次:$Queue = new QuickBooks_WebConnector_Queue($dsn);$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);你不应该在这个文件中有这段代码。它应该在其他地方。从这个文件中删除它,你的问题就会消失。相反,请修改您的 Web 应用程序,以便在您的 Web 应用程序中创建新客户时,同时将 QuickBooks 请求排队。所以当你做这样的事情时,在你的应用程序的某个地方:// Person submitted the form, so save the data they submitted into my database$my_customer['first_name'] = $_POST['first_name'];$my_customer['last_name'] = $_POST['last_name'];$my_customer_id = $MyModelOrDatabase->insert('customer_table', $my_customer);你应该做这个:// Person submitted the form, so save the data they submitted into my database$my_customer['first_name'] = $_POST['first_name'];$my_customer['last_name'] = $_POST['last_name'];$my_customer_id = $MyModelOrDatabase->insert('customer_table', $my_customer);if ($my_customer_id){&nbsp; &nbsp; $Queue = new QuickBooks_WebConnector_Queue($dsn);&nbsp; &nbsp; $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $my_customer_id);}这会将一条记录放入 QuickBooks 的队列中。然后,当 Web 连接器连接时,它可以从您已经构建的队列中提取并处理它。如果您查看示例,则有一个示例可以说明这一点:https://github.com/consolibyte/quickbooks-php/tree/master/docs/web_connector/example_app_web_connector具体来说,这个例子:https://github.com/consolibyte/quickbooks-php/blob/master/docs/web_connector/example_app_web_connector/handler.php看起来像这样:// Handle the form postif (isset($_POST['submitted'])){&nbsp; &nbsp; // Save the record&nbsp; &nbsp; mysql_query("&nbsp; &nbsp; &nbsp; &nbsp; INSERT INTO&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; my_customer_table&nbsp; &nbsp; &nbsp; &nbsp; (&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fname,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lname&nbsp; &nbsp; &nbsp; &nbsp; ) VALUES (&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '" . mysql_escape_string($_POST['name']) . "',&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '" . mysql_escape_string($_POST['fname']) . "',&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '" . mysql_escape_string($_POST['lname']) . "'&nbsp; &nbsp; &nbsp; &nbsp; )");&nbsp; &nbsp; // Get the primary key of the new record&nbsp; &nbsp; $id = mysql_insert_id();&nbsp; &nbsp; // Queue up the customer add&nbsp;&nbsp; &nbsp; $Queue = new QuickBooks_WebConnector_Queue($dsn);&nbsp; &nbsp; $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $id);&nbsp; &nbsp; die('Great, queued up a customer!');}如果您查看文档,他们实际上明确警告您不要做到目前为止所做的事情:https://github.com/consolibyte/quickbooks-php/blob/master/docs/web_connector/example_web_connector.php#L284文件:&nbsp; &nbsp; // NOTE: You would normally *never* want to do this in this file! This is&nbsp;&nbsp; &nbsp; //&nbsp; meant as an initial test ONLY. See example_web_connector_queueing.php for more&nbsp;&nbsp; &nbsp; //&nbsp; details!&nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; // IMPORTANT NOTE: This particular example of queueing something up will&nbsp;&nbsp; &nbsp; //&nbsp; only ever happen *once* when these scripts are first run/used. After&nbsp;&nbsp; &nbsp; //&nbsp; this initial test, you MUST do your queueing in another script. DO NOT&nbsp;&nbsp; &nbsp; //&nbsp; DO YOUR OWN QUEUEING IN THIS FILE! See&nbsp;&nbsp; &nbsp; //&nbsp; docs/example_web_connector_queueing.php for more details and examples&nbsp;&nbsp; &nbsp; //&nbsp; of queueing things up.
打开App,查看更多内容
随时随地看视频慕课网APP