我正在使用基思的codeignitor示例从我的在线pos添加客户数据到quickbook桌面。
我从数据库中获取数据,并创建了XML,这是完美的,并显示所有5109记录。然而,在运行Web服务后,我只能导入165个条目。
请记住以下几点:1)XML没有断裂。XML很好2)Web服务时间设置为500分钟,所以没有中断。
附件是我的控制器和数据库文件的代码-
控制器-
http://quicktotals.com/quickbooks.txt
SQL -
http://quicktotals.com/phppos_people.sql
<?php
class QuickBooks extends CI_Controller
{
public function __construct()
{
parent::__construct();
// QuickBooks config
$this->load->config('quickbooks');
// Load your other models here...
//$this->load->model('yourmodel1');
//$this->load->model('yourmodel2');
//$this->load->model('yourmodel3');
}
/**
* Generate and return a .QWC Web Connector configuration file
*/
public function config()
{
$name = 'CodeIgniter QuickBooks Demo'; // A name for your server (make it whatever you want)
$descrip = 'CodeIgniter QuickBooks Demo'; // A description of your server
$appurl = 'https://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/qbwc'; // This *must* be httpS:// (path to your QuickBooks SOAP server)
$appsupport = $appurl; // This *must* be httpS:// and the domain name must match the domain name above
//$dsn = 'mysql://quicktot_admin:hunter2001@localhost/quicktot_pointofsale';
//QuickBooks_Utilities::createUser($dsn,'vijay','test@1234');
$username = $this->config->item('quickbooks_user'); // This is the username you stored in the 'quickbooks_user' table by using QuickBooks_Utilities::createUser()
$fileid = QuickBooks_WebConnector_QWC::fileID(); // Just make this up, but make sure it keeps that format
$ownerid = QuickBooks_WebConnector_QWC::ownerID(); // Just make this up, but make sure it keeps that format
$qbtype = QUICKBOOKS_TYPE_QBFS; // You can leave this as-is unless you're using QuickBooks POS
$readonly = false; // No, we want to write data to QuickBooks
$run_every_n_seconds = 600; // Run every 600 seconds (10 minutes)
// Generate the XML file
$QWC = new QuickBooks_WebConnector_QWC($name, $descrip, $appurl, $appsupport, $username, $fileid, $ownerid, $qbtype, $readonly, $run_every_n_seconds);
$xml = $QWC->generate();
// Send as a file download
header('Content-type: text/xml');
//header('Content-Disposition: attachment; filename="my-quickbooks-wc-file.qwc"');
print($xml);
exit;
}
/**
* SOAP endpoint for the Web Connector to connect to
*/
public function qbwc()
{
$user = $this->config->item('quickbooks_user');
$pass = $this->config->item('quickbooks_pass');
// Memory limit
ini_set('memory_limit', $this->config->item('quickbooks_memorylimit'));
// We need to make sure the correct timezone is set, or some PHP installations will complain
if (function_exists('date_default_timezone_set'))
{
// * MAKE SURE YOU SET THIS TO THE CORRECT TIMEZONE! *
// List of valid timezones is here: http://us3.php.net/manual/en/timezones.php
date_default_timezone_set($this->config->item('quickbooks_tz'));
}
// Map QuickBooks actions to handler functions
$map = array(
QUICKBOOKS_ADD_CUSTOMER => array( array( $this, '_addCustomerRequest' ), array( $this, '_addCustomerResponse' )
),
);
// Catch all errors that QuickBooks throws with this function
$errmap = array(
'*' => array( $this, '_catchallErrors' ),
);
// Call this method whenever the Web Connector connects
$hooks = array(
QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => array( array( $this, '_loginSuccess' ) ), // Run this function whenever a successful login occurs
);
// An array of callback options
$callback_options = array();
// Logging level
$log_level = $this->config->item('quickbooks_loglevel');
// What SOAP server you're using
$soapserver = QUICKBOOKS_SOAPSERVER_PHP; // The PHP SOAP extension, see: www.php.net/soap
//$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN; // A pure-PHP SOAP server (no PHP ext/soap extension required, also makes debugging easier)
$soap_options = array( // See http://www.php.net/soap
);
$handler_options = array(
'deny_concurrent_logins' => false,
'deny_reallyfast_logins' => false,
); // See the comments in the QuickBooks/Server/Handlers.php file
$driver_options = array( // See the comments in the QuickBooks/Driver/<YOUR DRIVER HERE>.php file ( i.e. 'Mysql.php', etc. )
'max_log_history' => 32000, // Limit the number of quickbooks_log entries to 1024
'max_queue_history' => 1024, // Limit the number of *successfully processed* quickbooks_queue entries to 64
);
// Build the database connection string
$dsn = 'mysql://' . $this->db->username . ':' . $this->db->password . '@' . $this->db->hostname . '/' . $this->db->database;
// Check to make sure our database is set up
if (!QuickBooks_Utilities::initialized($dsn))
{
//echo "aaa"; die;
// Initialize creates the neccessary database schema for queueing up requests and logging
QuickBooks_Utilities::initialize($dsn);
// This creates a username and password which is used by the Web Connector to authenticate
QuickBooks_Utilities::createUser($dsn, $user, $pass);
}
QuickBooks_Utilities::createUser($dsn, $user, $pass);
//echo "bbb"; die;
// Set up our queue singleton
QuickBooks_WebConnector_Queue_Singleton::initialize($dsn);
// Create a new server and tell it to handle the requests
//__construct($dsn_or_conn, $map, $errmap = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL, $soap = QUICKBOOKS_SOAPSERVER_PHP, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array(), $callback_options = array()
$Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level, $soapserver, QUICKBOOKS_WSDL, $soap_options,$handler_options, $driver_options, $callback_options);
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER);
$response = $Server->handle(true, true);
}
/**
* Issue a request to QuickBooks to add a customer
*/
public function _addCustomerRequest($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
// Do something to store the form data here
$this->load->model('Myquickbooks');
$data = $this->Myquickbooks->getCustomerData();
$xml ='';
$xml .= '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="11.0"?>';
$xml .= '<QBXML>';
$xml .= '<QBXMLMsgsRq onError="stopOnError">';
foreach ($data as $dta)
{
$xml .='<CustomerAddRq requestID="' . $requestID . '">
<CustomerAdd>
<Name>'.$dta['first_name'].'_'.$dta['person_id'].'</Name>
<CompanyName>'.$dta['company_name'].'</CompanyName>
<FirstName>'.$dta['first_name'].'</FirstName>
<LastName>'.$dta['last_name'].'</LastName>
<BillAddress>
<Addr1>'.$dta['address_1'].'</Addr1>
<Addr2>'.$dta['address_2'].'</Addr2>
<City>'.$dta['city'].'</City>
<State>'.$dta['state'].'</State>
<PostalCode>'.$dta['zip'].'</PostalCode>
<Country>'.$dta['country'].'</Country>
</BillAddress>
<Phone>'.$dta['phone_number'].'</Phone>
<AltPhone>'.$dta['phone_number'].'</AltPhone>
<Fax>'.$dta['phone_number'].'</Fax>
<Email>'.$dta['email'].'</Email>
<Contact>'.$dta['phone_number'].'</Contact>
</CustomerAdd>
</CustomerAddRq>';
}
$xml .='</QBXMLMsgsRq>';
$xml .='</QBXML>';
$xml = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $xml);
return $xml;
}
/**
* Handle a response from QuickBooks indicating a new customer has been added
*/
public function _addCustomerResponse($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
return true;
}
/**
* Catch and handle errors from QuickBooks
*/
public function _catchallErrors($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{
if ($action == QUICKBOOKS_ADD_CUSTOMER and $errnum == 3100)
{
return true; // Ignore this error, all is OK - customer already exists
}
// Some other error occurred, stop processing
return false;
}
/**
* Whenever the Web Connector connects, do something (e.g. queue some stuff up if you want to)
*/
public function _loginSuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config)
{
return true;
}
}
?>
2条答案
按热度按时间gblwokeq1#
你的代码有很多问题,如果有人想帮助你,你必须先解决这些问题。详细信息:
您使用的是13年前版本的qbXML。为什么?您应该使用QuickBooks支持的最高版本:
<?qbxml version="2.0"?>
您将多个客户捆绑到一个qbXML请求中。这很糟糕--它破坏了您实际跟踪和报告错误的能力。别这样每个客户添加请求都应该是自己的单独请求,在队列中有自己的特定条目。请参阅文档。
foreach ($data as $dta)
您特意绕过了所有错误检查和错误报告。为什么?这使得它 * 不可能 * 知道是否出了问题。
return true;
修复你的代码,然后重新发布 * 实际代码 * 而不是
.txt
文件。vc9ivgsu2#
这对我很有效。