php – 使用eBay Trading API在描述中插入html
作者:互联网
使用eBay Trading API AddFixedPrice Item调用,我尝试了以下内容:
$description = '<p>My Description</p>';
…
<?xml version="1.0" encoding="utf-8"?>
<AddFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
...
<Description><![CDATA[' . $description . ']]></Description>
和
<Description>' . htmlentities($description) . '</Description>
...
</AddFixedPriceItemRequest>
两者都不起作用.如何使用eBay Trading API将html插入描述XML字段?
更新:显然,当使用htmlentities()时,主要的Description字段正确处理html.但是,返回描述字段不会.
解决方法:
试试这个对我有用
$new_description = urldecode($new_description);
$new_description = "<![CDATA[" . $new_description . "]]>";
$feed = <<< EOD
<?xml version="1.0" encoding="utf-8"?>
<ReviseItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>$auth_token</eBayAuthToken>
</RequesterCredentials>
<Item ComplexType="ItemType">
<ItemID>$itemid</ItemID>
<DescriptionReviseMode>Replace</DescriptionReviseMode>
<Description>$new_description</Description>
</Item>
<MessageID>1</MessageID>
<WarningLevel>High</WarningLevel>
<Version>837</Version>
</ReviseItemRequest>
EOD;
$feed = trim($feed);
$site_id = 3;//3 For UK
$headers = array
(
'X-EBAY-API-COMPATIBILITY-LEVEL: 837',
'X-EBAY-API-DEV-NAME: ' . $dev_id,
'X-EBAY-API-APP-NAME: ' . $app_id,
'X-EBAY-API-CERT-NAME: ' . $cert_id,
'X-EBAY-API-CALL-NAME: ReviseItem',
'X-EBAY-API-SITEID: ' . $site_id,
);
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $api_endpoint);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $feed);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
标签:ebay,php,xml 来源: https://codeday.me/bug/20190831/1776847.html