1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace app\lib\wx_encode;
- use app\lib\wx_encode\ErrorCode;
- class XMLParse
- {
-
- public function extract($xmltext)
- {
- libxml_disable_entity_loader(true);
- try {
- $xml = new \DOMDocument();
- $xml->loadXML($xmltext);
- $array_e = $xml->getElementsByTagName('Encrypt');
- $array_a = $xml->getElementsByTagName('AppId');
- $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);
- }
- }
- ?>
|