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();
}
}