码迷,mamicode.com
首页 > 微信 > 详细

微信公众号-加解密数据demo坑

时间:2015-05-06 12:33:05      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:

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;

  

微信公众号-加解密数据demo坑

标签:

原文地址:http://www.cnblogs.com/jdhu/p/4481442.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!