1
我試圖使用發票快遞API在我的賬戶上創建新發票,並且由於該API調用,它不斷向我發送500錯誤。Invoice Express API 500錯誤
我的代碼是:
<?php
include_once('../libraries/spyc.php');
$APP_CONFIG = spyc_load_file('../libraries/config.yaml');
$screenname = $APP_CONFIG['screen_name'];
$api_key = $APP_CONFIG['api_key'];
$host = $APP_CONFIG['host'];
ob_start();
$db = new mysqli('localhost', 'user' , 'pass', 'db');
$id = $_GET['id'];
$result = mysqli_query($db,"SELECT * FROM orders WHERE id = '".$id."'");
$value = mysqli_fetch_assoc($result);
$date = date("d/m/Y", strtotime($value['post_date']));
$invoice_data = '
<?xml version="1.0" encoding="UTF-8"?>
<invoice>
<date>' . $date . '<date>
<due_date>' . $date . '</due_date>
<reference>25381g</reference>
<observations>0</observations>
<retention>0</retention>
<client>
<name>XX Bruce Norris</name>
<email>[email protected]</email>
<address>Badgad</address>
<postal_code>120213920139</postal_code>
<country>Germany</country>
<fiscal_id>12</fiscal_id>
<website> h</website>
<phone>2313423424</phone>
<fax>0</fax>
<observations> 0</observations>
</client>
<items type="array">
<item>
<name>Product 1</name>
<description>Cleaning product</description>
<unit_price>10.0</unit_price>
<quantity>1.0</quantity>
<unit>unit</unit>
<tax>
<name>IVA23</name>
</tax>
<discount>10.0</discount>
</item>
</items>
</invoice>';
$endpoint = "https://".$screenname.".".$host."/invoices.xml?api_key=".$api_key;
// Initialize handle and set options
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POSTFIELDS, $invoice_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
// Execute the request
$result_invoice = curl_exec($ch);
// Close the handle
curl_close($ch);
echo $result_invoice;
我知道這是不是與DB訪問一個問題,因爲我已經測試和查詢本身和它回來了完美。
我也嘗試設置錯誤報告給E_ALL並顯示錯誤,但我仍然只在網頁上發生500錯誤。
去看看你的網絡服務器的錯誤日誌。 500將充實更詳細的那裏。在PHP中,您可以通過添加'error_reporting(E_ALL); ini_set('display_errors',1);'到腳本的頂部。總是建議在開發中使用'display_errors'。 –
如果您使用php_cli,您也可以嘗試執行'php -l file.php'。 – ChoiZ
不幸的是我已經嘗試在我的文件開頭設置這些值,但我得到的仍然是500錯誤,我會更新我的問題。 也不能真的使用Php_cli,但是謝謝你們倆 – SaraVieira