【发布时间】:2012-02-14 15:17:38
【问题描述】:
所以我正在尝试使用我发现的一个类来解决我遇到的电子商务问题。
在华盛顿州的在线商店需要根据送货地址确定税率。
WA Sales Tax Rate Lookup URL Interface
类:
/**
* @author SmallDog
* @contact dustin@smalldo.gs
* @created 01-27-2011
**/
class destinationTax
{
private $dor_url = 'http://dor.wa.gov';
function __construct(){ }
function getTax($addr,$city,$zip)
{
$req = $this->dor_url."/AddressRates.aspx?output=xml&addr=$addr&city=$city&zip=$zip";
return $this->_get_decoded($req);
}
private function _get_decoded($url)
{
$url = urlencode($url);
if($xml = simplexml_load_file($url))
{
switch($xml->attributes()->code)
{
case 0:
// Code 0 means address was perfect
break;
case 1:
$xml->msg = "Warning: The address was not found, but the ZIP+4 was located.";
break;
case 2:
$xml->msg = "Warning: Neither the address or ZIP+4 was found, but the 5-digit ZIP was located.";
break;
case 3:
$xml->msg = "Error: The address, ZIP+4, and ZIP could not be found.";
break;
case 4:
$xml->msg = "Error: Invalid arguements.";
break;
case 5:
$xml->msg = "Error: Internal error.";
}
}
else $xml = "Error: Could not load XML.";
return $xml;
}
}
用途:
$tax = new destinationTax;
$tax = $tax->getTax("123 Main Street", "Kirkland", "98033");
echo $tax->attributes()->rate;
错误:
警告:simplexml_load_file() [function.simplexml-load-file]: URL 文件访问在服务器配置中被禁用 /.../.../classes.php
警告: simplexml_load_file(http://dor.wa.gov/AddressRates.aspx?output=xml&addr=123+Main+Street&city=Kirkland&zip=98033) [function.simplexml-load-file]:无法打开流:没有合适的 包装器可以在 /.../.../classes.php 中找到
警告:simplexml_load_file() [function.simplexml-load-file]:I/O 警告:无法加载外部实体 “http%3A%2F%2Fdor.wa.gov%2FAddressRates.aspx%3Foutput%3Dxml%26addr%3D123+Main+Street%26city%3DKirkland%26zip%3D98033” 在 /.../.../classes.php
致命错误:在非对象上调用成员函数 attributes() /.../.../tax.php
【问题讨论】:
-
URL file-access is disabled in the server configuration是比较明确的......请参阅php.net/manual/en/function.fopen.php 以获得解释