iT邦幫忙

DAY 29
1

[老鷹之且戰且飛]系列 第 29

[老鷹之且戰且飛]後續實例3(GetMyMessages)

  • 分享至 

  • xImage
  •  

這是訂單詳細內容

<?php
/*  ?2013 eBay Inc., All Rights Reserved */
/* Licensed under CDDL 1.0 -  http://opensource.org/licenses/cddl1.php */
require_once('keys.php')
?>
<?php require_once('eBaySession.php') ?>

<HTML>
    <HEAD>
        <META http-equiv="Content-Type" content="text/html; charset=utf-8">
        <TITLE>GetItem</TITLE>
    </HEAD>
    <BODY>
        <?php
        if (isset($_GET['id'])) {
            //Get the ItemID inputted
            $id = $_GET['id'];


            //SiteID must also be set in the Request's XML
            //SiteID = 0  (US) - UK = 3, Canada = 2, Australia = 15, ....
            //SiteID Indicates the eBay site to associate the call with
            $siteID = 0;
            //the call being made:
            $verb = 'GetMyMessages';

            ///Build the request Xml string
            $requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
            $requestXmlBody .= '<GetMyMessagesRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
            $requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>";
            $requestXmlBody .= "<MessageIDs><MessageID>$id</MessageID></MessageIDs>";
            $requestXmlBody .= "<DetailLevel>ReturnMessages</DetailLevel>";
            $requestXmlBody .= '</GetMyMessagesRequest>';

            //Create a new eBay session with all details pulled in from included keys.php
            $session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $verb);

            //send the request and get response
            $responseXml = $session->sendHttpRequest($requestXmlBody);
            if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
                die('<P>Error sending request');

            //Xml string is parsed and creates a DOM Document object
            $responseDoc = new DomDocument();
            $responseDoc->loadXML($responseXml);


            //get any error nodes
            $errors = $responseDoc->getElementsByTagName('Errors');

            //if there are error nodes
            if ($errors->length > 0) {
                echo '<P><B>eBay returned the following error(s):</B>';
                //display each error
                //Get error code, ShortMesaage and LongMessage
                $code = $errors->item(0)->getElementsByTagName('ErrorCode');
                $shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
                $longMsg = $errors->item(0)->getElementsByTagName('LongMessage');
                //Display code and shortmessage
                echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", ">", str_replace("<", "<", $shortMsg->item(0)->nodeValue));
                //if there is a long message (ie ErrorLevel=1), display it
                if (count($longMsg) > 0)
                    echo '<BR>', str_replace(">", ">", str_replace("<", "<", $longMsg->item(0)->nodeValue));
            }

            else { //no errors
                //get the nodes needed
                $Messages = $responseDoc->getElementsByTagName('Messages');
                $Message = $responseDoc->getElementsByTagName('Message');
                $Content = $responseDoc->getElementsByTagName('Content');
                $ExternalMessageID = $responseDoc->getElementsByTagName('ExternalMessageID');
                $ItemID = $responseDoc->getElementsByTagName('ItemID');
                $Sender = $responseDoc->getElementsByTagName('Sender');
            }
        }
        ?>
        <INPUT type="button" onClick="javascript:history.back(1)" value="回上一頁" /><BR>
        <textarea name="textarea" id="textarea" cols="130" rows="20"><?= $Content->item(0)->nodeValue; ?></textarea>
        <hr>
        <FORM method="POST" action="messages_reply.php">
            <table>
                <tr>
                    <th>回覆</th>
                </tr>
                <tr>
                    <td>
                        <textarea name="body" id="textarea" cols="130" rows="20"></textarea>
                        <input type="hidden" name="ExternalMessageID" value="<?= $ExternalMessageID->item(0)->nodeValue; ?>">
                        <input type="hidden" name="ItemID" value="<?= $ItemID->item(0)->nodeValue; ?>">
                        <input type="hidden" name="Sender" value="<?= $Sender->item(0)->nodeValue; ?>">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="submit" value="回覆">
                    </td>
                </tr>
            </table>
        </FORM>
    </BODY>
</HTML>

上一篇
[老鷹之且戰且飛]後續實例2(GetMyMessages)
下一篇
[老鷹之且戰且飛]後續實例4(AddMemberMessageRTQ)
系列文
[老鷹之且戰且飛]30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言