0

我正在使用这里的 php 库,我有一个小问题。

要获取发票 118868 的一些信息,我可以这样做

<?php
$invoice_id=118868;

$invoice=$freshbooks->invoiceGet($invoice_id);
print_r($invoice);
?>

这是 print_r 的输出

Class Object ( [@attributes] => stdClass Object ( [status] => ok ) [invoice] => stdClass Object ( [invoice_id] => 00000219023 [estimate_id] => stdClass Object ( ) [number] => 8822 [client_id] => 83 [contacts] => stdClass Object ( [contact] => stdClass Object ( [contact_id] => 0 ) ) [recurring_id] => stdClass Object ( ) [organization] => Jimmy Thwart [first_name] => stdClass Object ( ) [last_name] => stdClass Object ( ) [p_street1] => stdClass Object ( ) [p_street2] => stdClass Object ( ) [p_city] => stdClass Object ( ) [p_state] => stdClass Object ( ) [p_country] => stdClass Object ( ) [p_code] => stdClass Object ( ) [po_number] => 10002 [status] => sent [amount] => 16.90 [amount_outstanding] => 16.90 [paid] => 0.00 [date] => 2013-01-31 00:00:00 [notes] => stdClass Object ( ) [terms] => Your slot can only be secured upon payment. Any reservation made before payment will only be guaranteed for 2 days. [discount] => 0 [url] => https://example.freshbooks.com/view/vgPb2TNGCR7n8JV [auth_url] => https://example.freshbooks.com/invoices/219023 [links] => stdClass Object ( [client_view] => https://example.freshbooks.com/view/vgPb2TNGCR7n8JV [view] => https://example.freshbooks.com/invoices/219023 [edit] => https://example.freshbooks.com/invoices/219023/edit ) [return_uri] => stdClass Object ( ) [updated] => 2013-01-31 02:25:13 [currency_code] => SGD [language] => en [vat_name] => stdClass Object ( ) [vat_number] => stdClass Object ( ) [folder] => active [staff_id] => 1 [lines] => stdClass Object ( [line] => stdClass Object ( [line_id] => 1 [name] => Lady 1pax [description] => Services (1 pax) [unit_cost] => 16.90 [quantity] => 1 [amount] => 16.90 [tax1_name] => stdClass Object ( ) [tax2_name] => stdClass Object ( ) [tax1_percent] => 0 [tax2_percent] => 0 [compound_tax] => 0 [type] => Item ) ) [gateways] => stdClass Object ( [gateway] => stdClass Object ( [name] => PayPal ) ) ) ) 

我希望输出只能是 URL 而不是整个代码块。想要的输出:

https://example.freshbooks.com/view/vgPb2TNGCR7n8JV

但是,它列出了发票的所有信息。如何仅获取发票 URL?

4

2 回答 2

0

发票是一个类的实例。您应该像对待所有实例一样对待它。

要获取 URL 值,您可以执行以下操作:

<?php
$invoice_id=118868;

$invoice=$freshbooks->invoiceGet($invoice_id);
print $invoice->url;
?>

或者您正在寻找另一个可能的值:

<?php
$invoice_id=118868;

$invoice=$freshbooks->invoiceGet($invoice_id);
print $invoice->links->client_view;
?>

根据官方 API doc <url>不再支持,因此您应该使用<links>“元素为您的客户提供发票的直接链接,以供编辑、客户查看和管理员查看”。

于 2013-01-31T07:56:42.273 回答
0

好吧,使用代码的输出,您可以看到其中的元素$invoice是什么。使用您需要的那个。

于 2013-01-31T07:06:01.247 回答