12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace Modules\Common\Support\Wechat\Crypt;
- 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('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);
- }
- }
|