【发布时间】:2013-12-16 20:50:58
【问题描述】:
我正在尝试使用发票快递 api 在我的帐户上创建新发票,但由于该 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>foo@ar.com</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;
我知道数据库访问没有问题,因为我已经测试了它和查询本身,它完美地返回了。
我也尝试将错误报告设置为 E_ALL 并显示错误,但我仍然只在网页上收到 500 错误。
【问题讨论】:
-
去看看你的网络服务器的错误日志。 500 将在那里更加详细地充实。在 PHP 中,您可以通过在脚本顶部添加
error_reporting(E_ALL); ini_set('display_errors', 1);来启动错误报告。始终建议在开发中使用display_errors。 -
如果你使用php_cli,也可以尝试执行
php -l file.php。 -
不幸的是,我尝试在文件开头设置这些值,但得到的仍然是 500 错误,我将更新我的问题。也不能真正使用 Php_cli,但谢谢你们俩