这将是一个两部分的答案,因为您没有指定是否使用QuickBooks ONLINE或QuickBooks for WINDOWS。
该过程将根据您使用的不同而不同,因此请注意以下粗体:
对于QuickBooks在线:
您首先要做的是使用Intuit注册您的应用程序。当你这样做,Intuit会给你这些变量:
>应用程式令牌
>消费者秘密
>消费者钥匙
您将将这些变量替换为示例中包含的config.php文件。您还将更新这些值以指向您的应用程序:
> oauth网址(例如your-site.com/path/to/example/oauth.php)
>成功网址(例如your-site.com/path/to/example/success.php)
>菜单网址(例如your-site.com/path/to/example/menu.php)
> dsn(您的OAuth令牌存储的数据库凭据)
除此之外,您可以将config.php中的所有其他变量保留为默认值。
如果您访问index.php文件,它将提示您连接到QuickBooks。您可以连接,然后访问示例文件。以下是向QuickBooks在线添加客户/订单的一些示例:
代码最终看起来像:
$CustomerService = new QuickBooks_IPP_Service_Customer();
$Customer = new QuickBooks_IPP_Object_Customer();
$Customer->setTitle('Mr');
$Customer->setGivenName('Keith');
$Customer->setMiddleName('R');
$Customer->setFamilyName('Palmer');
$Customer->setDisplayName('Keith R Palmer Jr ' . mt_rand(0, 1000));
// Phone #
$PrimaryPhone = new QuickBooks_IPP_Object_PrimaryPhone();
$PrimaryPhone->setFreeFormNumber('860-532-0089');
$Customer->setPrimaryPhone($PrimaryPhone);
// Bill address
$BillAddr = new QuickBooks_IPP_Object_BillAddr();
$BillAddr->setLine1('72 E Blue Grass Road');
$BillAddr->setLine2('Suite D');
$BillAddr->setCity('Mt Pleasant');
$BillAddr->setCountrySubDivisionCode('MI');
$BillAddr->setPostalCode('48858');
$Customer->setBillAddr($BillAddr);
if ($resp = $CustomerService->add($Context, $realm, $Customer))
{
print('Our new customer ID is: [' . $resp . ']');
}
要实现其他功能,您将在代码中找到其他示例。
对于WINDOWS的QuickBooks:
这将引导您完成一个简单的Web连接器服务,它将测试客户添加到QuickBooks。
基本上,您将会将create a .QWC file加载到QuickBooks Web连接器(开始>所有程序> QuickBooks> Web连接器)中。那个.QWC文件将指向一个PHP script which negotiates the connection between QuickBooks and PHP.在这个示例脚本中你要做的就是交换这个变量:
> $ dsn(指向你自己的数据库)
你的代码最终会看起来像:
function _quickbooks_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
// You'd probably do some database access here to pull the record with
// ID = $ID from your database and build a request to add that particular
// customer to QuickBooks.
//
// So, when you implement this for your business, you'd probably do
// something like this...:
/*
// Fetch your customer record from your database
$record = mysql_fetch_array(mysql_query("SELECT * FROM your_customer_table WHERE your_customer_ID_field = " . (int) $ID));
// Create and return a qbXML request
$qbxml = '<?xml version="1.0" encoding="utf-8"?>
' . $record['your_customer_name_field'] . '
' . $record['your_customer_company_field'] . '
... lots of other customer related fields ...
';
return $qbxml;
*/
// But we're just testing, so we'll just use a static test request:
$xml = '<?xml version="1.0" encoding="utf-8"?>
ConsoliBYTE, LLC (' . mt_rand() . ')
ConsoliBYTE, LLC
Keith
Palmer
ConsoliBYTE, LLC
134 Stonemill Road
Mansfield
CT
06268
United States
860-634-1602
860-429-0021
860-429-5183
Keith@ConsoliBYTE.com
Keith Palmer
';
return $xml;
}
您可以使用QuickBooks OSR找到其他qbXML参考。