Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SimpleXML问题_Php_Xml_Simplexml_Authorize.net - Fatal编程技术网

Php SimpleXML问题

Php SimpleXML问题,php,xml,simplexml,authorize.net,Php,Xml,Simplexml,Authorize.net,也许有人能帮我解决一个关于SimpleXML对象的问题 我正在与authorize.net CIM manager集成并发送客户配置文件。当我将其发送进来时,原始xml响应通过解析器传递,并转化为SimpleXML对象 以下是用于提交请求的代码: $content = "<?xml version=\"1.0\" encoding=\"utf-8\"?>". "<createCustomerProfileRequest xmlns=\"AnetA

也许有人能帮我解决一个关于SimpleXML对象的问题

我正在与authorize.net CIM manager集成并发送客户配置文件。当我将其发送进来时,原始xml响应通过解析器传递,并转化为SimpleXML对象

以下是用于提交请求的代码:

$content =
        "<?xml version=\"1.0\" encoding=\"utf-8\"?>".
        "<createCustomerProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">".
        MerchantAuthenticationBlock().
        "<profile>".
        //"<merchantCustomerId>".$userInsertedId."</merchantCustomerId>". // Your own identifier for the customer.
        "<description>'New User Purchase'</description>".
        "<email>" . $_GET["email"] . "</email>".
        "<paymentProfiles>".
        "<billTo>".
         "<firstName>".$_GET["firstname"]."</firstName>".
         "<lastName>".$_GET["lastname"]."</lastName>".
         "<address>".$_GET["street"]."</address>".
         "<city>".$_GET["city"]."</city>".
         "<state>".$_GET["state"]."</state>".
         "<zip>".$_GET["zip"]."</zip>".
         "<country>".$_GET["country"]."</country>".
         "<phoneNumber>".$_GET["phone"]."</phoneNumber>".
        "</billTo>".
        "<payment>".
         "<creditCard>".
          "<cardNumber>".$_GET["number"]."</cardNumber>".
          "<expirationDate>".$_GET["year"]."-".$_GET["month"]."</expirationDate>". // required format for API is YYYY-MM
          "<cardCode>".$_GET["code"]."</cardCode>".
         "</creditCard>".
         "</payment>".
        "</paymentProfiles>".
        "</profile>".
        "<validationMode>testMode</validationMode>". 
        "</createCustomerProfileRequest>";

        $CCresponse = send_xml_request($content);

        //echo($CCresponse);

        $parsedresponse = parse_api_response($CCresponse);

   function parse_api_response($content)
        {
            $parsedresponse = simplexml_load_string($content, "SimpleXMLElement", LIBXML_NOWARNING);
            if ("Ok" != $parsedresponse->messages->resultCode) 
            {
                echo "The operation failed with the following errors:<br>";
                foreach ($parsedresponse->messages->message as $msg) 
                {
                    echo "[" . htmlspecialchars($msg->code) . "] " . htmlspecialchars($msg->text) . "<br>";
                }
                    echo "<br>";
            }
            return $parsedresponse;
        }
我得到以下输出:

SimpleXMLElement Object
(
[messages] => SimpleXMLElement Object
    (
        [resultCode] => Ok
        [message] => SimpleXMLElement Object
            (
                [code] => I00001
                [text] => Successful.
            )
    )
[customerProfileId] => 15642446
[customerPaymentProfileIdList] => SimpleXMLElement Object
    (
        [numericString] => 13865552
    )
[customerShippingAddressIdList] => SimpleXMLElement Object
    (
    )
[validationDirectResponseList] => SimpleXMLElement Object
    (
        [string] => 1|1|1|(TESTMODE) This transaction has been approved.|000000|P|0|none|Test transaction for ValidateCustomerPaymentProfile.|1.00|CC|auth_only||*****|******||****|*******|******|******|USA|1234567890||email@email.com|none|none|none|none|none|none|none|none|0.00|0.00|0.00|FALSE|none|207BCBBF78E85CF174C87AE286B472D2|||||||||||||*******|*******||||||||||||||||
    )
)
 )
)
因此,从这一点来看,一切似乎都在发挥作用。但是当我尝试钻取SimpleXML对象并执行以下操作时:

echo $code = (string) $parsedresponse->messages->resultCode;
我得到了一个输出OK,它似乎在它上面运行了两次。这让我简直快疯了,我搞不懂这到底是怎么回事。有人能给我指一下正确的方向吗?这样我就可以工作了


谢谢

也许您可以尝试使用xpath方法导航SimpleXMLElement,如下所示:

$code = (string) $parsedresponse->xpath('messages/resultCode');
echo $code;

原因可能是代码中的其他地方。你用$code做什么?没什么,我只是创建了那个变量,以便将其返回。@Ackerches你能显示完整的代码吗?@Pekka原始问题编辑为显示完整的代码code@acker不管这行的想法如何,我意识到这是B.s.不管怎样,带回声的那行会被执行两次。我不相信你正在向我们展示你所有的代码。你有循环吗?
$code = (string) $parsedresponse->xpath('messages/resultCode');
echo $code;