3

使用 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() 时正确处理 html。但是,返回描述字段没有。

4

1 回答 1

5

试试这个它对我有用

$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);
于 2014-11-06T12:49:37.160 回答