123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- include_once "errorCode.php";
- class XMLParse
- {
-
- public function extract($xmltext)
- {
- try {
- $xml = new DOMDocument();
- $xml->loadXML($xmltext);
- $array_e = $xml->getElementsByTagName('Encrypt');
- $array_a = $xml->getElementsByTagName('ToUserName');
- $encrypt = $array_e->item(0)->nodeValue;
- $tousername = $array_a->item(0)->nodeValue;
- return array(0, $encrypt, $tousername);
- } catch (Exception $e) {
-
- return array(ErrorCode::$ParseXmlError, null, null);
- }
- }
-
- public function generate($encrypt, $signature, $timestamp, $nonce)
- {
- $format = "<xml>
- <Encrypt><![CDATA[%s]]></Encrypt>
- <MsgSignature><![CDATA[%s]]></MsgSignature>
- <TimeStamp>%s</TimeStamp>
- <Nonce><![CDATA[%s]]></Nonce>
- </xml>";
- return sprintf($format, $encrypt, $signature, $timestamp, $nonce);
- }
- }
- ?>
|