我正在使用Quickbooks PHP SDK。
我正在尝试运行下面的命令:
$res = $dataService->Add($customerObj);
我知道命令现在抛出了一个异常,但我不知道异常是什么,也不知道怎么知道哪里出了问题?
我该怎么做?
注意:我会找出什么是错误的customerObj在我自己,以节省你们的时间,只需要弄清楚如何找出什么错误是返回给我。
更新::这是一个id异常错误,但不知道这是什么意思?
下面是剩余的代码:$requestValidator = new OAuthRequestValidator(
gdizDecrypt($qbkeys->oauthtoken),
gdizDecrypt($qbkeys->oauthtokensecret),
OAUTH_CONSUMER_KEY,
OAUTH_CONSUMER_SECRET
);
$serviceContext = new ServiceContext($qbkeys->realmid, $qbkeys->datasource, $requestValidator);
$dataService = new DataService($serviceContext);
$customerObj = new IPPCustomer();
$customerObj->GivenName = $client->contactfirstname.' '.$client->contactlastname;
$customerObj->FamilyName = $client->contactlastname;
$customerObj->DisplayName = $client->contactfirstname.' '.$client->contactlastname;
$customerObj->PreferredDeliveryMethod = 'Print';
$customerObj->BillWithParent = 'false';
if($client->active == '')
{
$customerObj->Active = (bool)false;
}
else
{
$customerObj->Active = 'true';
}
$phoneObj = new IPPTelephoneNumber();
$phoneObj->FreeFormNumber = $client->contactphonenumber;
$emailObj = new IPPEmailAddress();
$emailObj->Address = $client->contactemail;
$addrObj = new IPPPhysicalAddress();
$addrObj->Line1 = $client->contactaddress;
$customerObj->PrimaryPhone = $phoneObj;
$customerObj->PrimaryEmailAddr = $emailObj;
$customerObj->BillAddr = $addrObj;
好了,我终于弄明白问题了。经过一番搜寻,我在这里找到了一篇文章。
https://intuitdeveloper.lc.intuit.com/questions/1016393-checknullresponseandthrowexception-response-null-or-empty你需要修改sdk。将配置文件转换为以下XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<intuit>
<ipp>
<!--Json serialization not supported in PHP SDK v2.0.5 -->
<message>
<request serializationFormat="Xml" compressionFormat="None"/>
<response serializationFormat="Xml" compressionFormat="None"/>
</message>
<service>
<baseUrl qbd="https://sandbox-quickbooks.api.intuit.com/" qbo="https://sandbox-quickbooks.api.intuit.com/" ipp="https://appcenter.intuit.com/api/" />
</service>
<logger>
<!-- To enable/disable Request and Response log-->
<requestLog enableRequestResponseLogging="false" requestResponseLoggingDirectory="/IdsLogs" />
</logger>
</ipp>
</intuit>
</configuration>
我以前工作的代码是在生产中,如果你正在使用开发沙箱,我是,你需要改变正确的引用。