demo里面的MsgSignature作为url参数一部分了,demo也不更新下 坑爹的微信!
解密信息部分
include_once "wxBizMsgCrypt.php"; $encodingAesKey = "spl6dEUAwsGWXrN9SkAfkMQ684b5d";//cuode
$token = "quhuodong";//cuode
$appId = "wxa5c3224";//cuode $timestamp = $_GET['timestamp'];
$nonce = $_GET['nonce'];
$msg_sign = $_GET['msg_signature']; $xml_tree = new DOMDocument();
$xml_tree->loadXML(file_get_contents("php://input"));
$array_e = $xml_tree->getElementsByTagName('Encrypt');
$encrypt = $array_e->item(0)->nodeValue; $format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";
$from_xml = sprintf($format, $encrypt); // 第三方收到公众号平台发送的消息
$msg = '';
$pc = new WXBizMsgCrypt($token, $encodingAesKey, $appId);
$errCode = $pc->decryptMsg($msg_sign, $timestamp, $nonce, $from_xml, $msg);
if ($errCode == 0) {
print("解密后: " . $msg . "\n");
} else {
print($errCode . "\n");
}
修改一下:利用simplexml_load_string解析xml
$xml = simplexml_load_string(file_get_contents('../reqest20150506032946'));
$encrypt = $xml->Encrypt;