iT邦幫忙

DAY 30
2

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

[老鷹之且戰且飛]後續實例4(AddMemberMessageRTQ)

最後一篇以回覆結尾~~!

感謝大家支持老鷹30天~~!

<?php
require_once('keys.php');
require_once('eBaySession.php');
        //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 = 'AddMemberMessageRTQ';
       
        ///Build the request Xml string
        $requestXmlBody = '<?xml version="1.0" encoding="utf-8"?>';
        $requestXmlBody .= '<AddMemberMessageRTQRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
        $requestXmlBody .= "<ItemID>{$_POST['ItemID']}</ItemID>";
        $requestXmlBody .= "<MemberMessage>";
        $requestXmlBody .= "<Body>{$_POST['body']}</Body>";
        $requestXmlBody .= "<ParentMessageID>{$_POST['ExternalMessageID']}</ParentMessageID>";
        $requestXmlBody .= "<RecipientID>{$_POST['Sender']}</RecipientID>";
        $requestXmlBody .= "</MemberMessage>";
        $requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>";
        $requestXmlBody .= "</AddMemberMessageRTQRequest>";
       

       
        //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
            $Ack = $responseDoc->getElementsByTagName('Ack');
            if($Ack->item(0)->nodeValue == "Success"){
                echo '<script>document.location.href="messages_list.php";</script>';
            }else{
                echo '<script>document.location.href="message_content.php";</script>';               
            }       
        }
?>
 

上一篇
[老鷹之且戰且飛]後續實例3(GetMyMessages)
系列文
[老鷹之且戰且飛]30

尚未有邦友留言

立即登入留言