1 回答

TA貢獻(xiàn)1934條經(jīng)驗(yàn) 獲得超2個(gè)贊
Web 連接器是基于 SOAP 的,因此您實(shí)際上在這里所做的是設(shè)置 Web 連接器連接到的 SOAP 服務(wù)器。
這里需要意識(shí)到的重要一點(diǎn)是,Web 連接器每次連接時(shí)都會(huì)對(duì) SOAP 服務(wù)進(jìn)行多次調(diào)用(例如,對(duì)您的 PHP 腳本進(jìn)行許多獨(dú)立的 HTTP 請(qǐng)求)。至少,即使沒有要交換的實(shí)際數(shù)據(jù),它也至少會(huì)進(jìn)行 4 次調(diào)用:
客戶端版本
服務(wù)器版本
認(rèn)證
關(guān)閉連接
這意味著每次 Web 連接器連接到您的服務(wù)以嘗試與 QuickBooks 交換數(shù)據(jù)時(shí),您在 PHP 腳本中放置的任何內(nèi)容都至少運(yùn)行 4 次。所以每次 Web 連接器連接時(shí),這段代碼至少運(yùn)行 4 次:
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);
你不應(yīng)該在這個(gè)文件中有這段代碼。它應(yīng)該在其他地方。從這個(gè)文件中刪除它,你的問題就會(huì)消失。
相反,請(qǐng)修改您的 Web 應(yīng)用程序,以便在您的 Web 應(yīng)用程序中創(chuàng)建新客戶時(shí),同時(shí)將 QuickBooks 請(qǐng)求排隊(duì)。所以當(dāng)你做這樣的事情時(shí),在你的應(yīng)用程序的某個(gè)地方:
// 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);
你應(yīng)該做這個(gè):
// 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)
{
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $my_customer_id);
}
這會(huì)將一條記錄放入 QuickBooks 的隊(duì)列中。然后,當(dāng) Web 連接器連接時(shí),它可以從您已經(jīng)構(gòu)建的隊(duì)列中提取并處理它。
如果您查看示例,則有一個(gè)示例可以說明這一點(diǎn):
https://github.com/consolibyte/quickbooks-php/tree/master/docs/web_connector/example_app_web_connector
具體來說,這個(gè)例子:
https://github.com/consolibyte/quickbooks-php/blob/master/docs/web_connector/example_app_web_connector/handler.php
看起來像這樣:
// Handle the form post
if (isset($_POST['submitted']))
{
// Save the record
mysql_query("
INSERT INTO
my_customer_table
(
name,
fname,
lname
) VALUES (
'" . mysql_escape_string($_POST['name']) . "',
'" . mysql_escape_string($_POST['fname']) . "',
'" . mysql_escape_string($_POST['lname']) . "'
)");
// Get the primary key of the new record
$id = mysql_insert_id();
// Queue up the customer add
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $id);
die('Great, queued up a customer!');
}
如果您查看文檔,他們實(shí)際上明確警告您不要做到目前為止所做的事情:
https://github.com/consolibyte/quickbooks-php/blob/master/docs/web_connector/example_web_connector.php#L284
文件:
// NOTE: You would normally *never* want to do this in this file! This is
// meant as an initial test ONLY. See example_web_connector_queueing.php for more
// details!
//
// IMPORTANT NOTE: This particular example of queueing something up will
// only ever happen *once* when these scripts are first run/used. After
// this initial test, you MUST do your queueing in another script. DO NOT
// DO YOUR OWN QUEUEING IN THIS FILE! See
// docs/example_web_connector_queueing.php for more details and examples
// of queueing things up.
- 1 回答
- 0 關(guān)注
- 99 瀏覽
添加回答
舉報(bào)