我为移动应用程序开发了Prestashop Web服务。
我可以连接用户,创建用户帐户,创建购物车,但我无法创建订单。
我有以下错误:
HTTP XML响应不可解析:array(0 => LibXMLError :: __ set_state(array('level'=> 3,'code'=> 9,'column'=> 64,'message' =>'输入不正确UTF-8,表示编码!字节:0x95 0x08 0x77 0xE2','file'=>'','line'=> 778,)),1 => LibXMLError :: __set_state(array('level'=> 3,'code'=> 9,'column'=> 65,'message'=>'PCDATA无效字符值8','file'=>'' ,'line'=> 778,)),2 => LibXMLError :: __ set_state(array('level'=> 3,'code'=> 9,'column'=> 77,'message' =>'PCDATA无效字符值12','文件'=>'','line'=> 778,)),3 => LibXMLError :: __ set_state(array('level'=> 3, 'code'=> 9,'column'=> 78,'message'=>'PCDATA无效字符值14','file'=>'','line'=> 778,)), 4 => LibXMLError :: __ set_state(array('level'=> 3,'code'=> 64,'column'=> 51,'message'=>'仅在开始时允许XML声明文件','file'=>'','l ine'=> 14954,)),5 => LibXMLError :: __ set_state(array('level'=> 3,'code'=> 64,'column'=> 51,'message'=>'仅在文档开头允许XML声明', 'file'=>'','line'=> 17864,)),6 => LibXMLError :: __ set_state(array('level'=> 3,'code'=> 64,'column'=> 51,'message'=>'仅在文档开头允许XML声明', 'file'=>'','line'=> 20773,)),7 => LibXMLError :: __ set_state(array('level'=> 3,'code'=> 64,'column'=> 33,'message'=>'仅在文档开头允许XML声明', 'file'=>'','line'=> 21368,)),)
我尝试在UTF-8中更改页面的编码,但无法做任何事情。
这是我的PHP:
<?php
// Here's how you create a webservice call:
define('PS_SHOP_PATH', 'localhost:8888/MON_SITE');
define('PS_WS_AUTH_KEY', 'MA_CLEF');
define('DEBUG', true);
require_once('PSWebServiceLibrary.php');
try {
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'orders');
$xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/orders?schema=synopsis'));
$xml->children()->children()->id_address_delivery = 6;
$xml->children()->children()->id_address_invoice = 6;
$xml->children()->children()->id_cart = 136;
$xml->children()->children()->id_currency = 1;
$xml->children()->children()->current_state = 1;
$xml->children()->children()->id_lang = 1;
$xml->children()->children()->id_customer = 1;
$xml->children()->children()->id_carrier = 0;
$xml->children()->children()->total_paid = '56973';
$xml->children()->children()->total_paid_real = '56973';
$xml->children()->children()->total_paid_tax_excl = '56973';
$xml->children()->children()->total_paid_tax_incl = '56977';
$xml->children()->children()->total_products = 1338;
$xml->children()->children()->total_products_wt = 1337;
$xml->children()->children()->conversion_rate = '1';
$xml->children()->children()->secure_key = md5('-1');
$xml->children()->children()->valid = 1;
$xml->children()->children()->module = 'Cheque';
$xml->children()->children()->payment = 'cheque';
$xml->children()->children()->current_state = 1;
unset($xml->children()->children()->id);
unset($xml->children()->children()->date_add);
unset($xml->children()->children()->date_upd);
unset($xml->children()->children()->associations);
unset($xml->children()->children()->delivery_date);
unset($xml->children()->children()->invoice_date);
unset($xml->children()->children()->total_discounts_tax_incl);
unset($xml->children()->children()->total_discounts_tax_excl);
$xml = $webService->add(array('resource' => 'orders',
'postXml' => $xml->asXML()
));
$resources = $xml->children()->children();
echo "Successfully added order.".$resources->id;
}
catch (PrestaShopWebserviceException $ex)
{
// Here we are dealing with errors
$trace = $ex->getTrace();
if ($trace[0]['args'][0] == 404) echo 'Bad ID';
else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error<br />'.$ex->getMessage();
}
?>
答案 0 :(得分:0)
亲爱的,尝试使用此代码获取xml响应。
$xml=simplexml_load_string($myXMLData) or die("Error: Cannot create object");
print_r($xml);