add clear
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace officialaccount\dcaler;
|
||||
|
||||
|
||||
use officialaccount\NewsManager;
|
||||
|
||||
class XMLParse
|
||||
{
|
||||
/**
|
||||
* 提取出xml数据包中的加密消息
|
||||
* @param string $xmltext 待提取的xml字符串
|
||||
* @return array 提取出的加密消息字符串
|
||||
*/
|
||||
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 [0, $encrypt, $tousername];
|
||||
} catch (\Exception $e) {
|
||||
return [NewsManager::ParseXmlError, null, null];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $encrypt
|
||||
* @param $signature
|
||||
* @param $timestamp
|
||||
* @param $nonce
|
||||
* @return string
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user