企业微信开发url回调成功后的对xml解密出明文


include_once "callback/WXBizMsgCrypt.php";(文件自行去企业微信文档里下载(https://work.weixin.qq.com/api/doc/90000/90138/90307))
$inputXmlData = file_get_contents('php://input');
$p_params = $request->all();

$corpId = ""; //微信应用id

$token = $resMsgtoken['token']; // url验证token
$encodingAesKey = $resMsgtoken['encoding_aes_key']; // url验证key
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
$sReqMsgSig = $p_params['msg_signature'];
$sReqTimeStamp = $p_params['timestamp'];
$sReqNonce = $p_params['nonce'];
$sReqData = $inputXmlData;
$sMsg = ""; // 解析之后的明文
$errCode = $wxcpt->DecryptMsg($sReqMsgSig, $sReqTimeStamp, $sReqNonce, $sReqData, $sMsg);
if ($errCode == 0) {
//将获取到的xml数据全部转化为Array格式
$decodeMsg = json_decode(json_encode(simplexml_load_string($sMsg, 'SimpleXMLElement', LIBXML_NOCDATA)), true);

if (empty($decodeMsg)) {
Log::info('info', ['sMsg即为xml格式的明文' => $decodeMsg]);
die();
}
}
posted @ 2021-11-19 16:00  Smile☆  阅读(579)  评论(0编辑  收藏  举报