1: <?php
2: include_once "errorCode.php";
3:
4: 5: 6: 7: 8:
9: class XMLParse
10: {
11:
12: 13: 14: 15: 16:
17: public function extract($xmltext)
18: {
19: try {
20: $xml = new DOMDocument();
21: $xml->loadXML($xmltext);
22: $array_e = $xml->getElementsByTagName('Encrypt');
23: $array_a = $xml->getElementsByTagName('ToUserName');
24: $encrypt = $array_e->item(0)->nodeValue;
25: $tousername = $array_a->item(0)->nodeValue;
26: return array(0, $encrypt, $tousername);
27: } catch (Exception $e) {
28:
29: return array(ErrorCode::$ParseXmlError, null, null);
30: }
31: }
32:
33: 34: 35: 36: 37: 38: 39:
40: public function generate($encrypt, $signature, $timestamp, $nonce)
41: {
42: $format = "<xml>
43: <Encrypt><![CDATA[%s]]></Encrypt>
44: <MsgSignature><![CDATA[%s]]></MsgSignature>
45: <TimeStamp>%s</TimeStamp>
46: <Nonce><![CDATA[%s]]></Nonce>
47: </xml>";
48: return sprintf($format, $encrypt, $signature, $timestamp, $nonce);
49: }
50:
51: }
52:
53:
54: ?>