我是这样解的,你可参考以下:
//解密获取ComponentVerifyTicket
$encodingAesKey = ''; //申请时填写的"消息加解密Key"
$token = ''; //申请时填写的"消息校验Token"
$appId = ''; //申请时填写的"消息校验Token"
$msg_signature = $request['msg_signature'];
$timestamp = $request['timestamp'];
$nonce = $request['nonce'];
$encryptMsg = file_get_contents('php://input');
libxml_disable_entity_loader(true);
$xml_obj = (array)simplexml_load_string($encryptMsg, 'SimpleXMLElement', LIBXML_NOCDATA);
// 重新拼接xml
$encrypt = $xml_obj['Encrypt'];
$encryptMsg = sprintf("", $encrypt);
// 解密
$pc = new WXBizMsgCrypt($token, $encodingAesKey, $appId);
$pc->WXBizMsgCrypt($token, $encodingAesKey, $appId);
$msg = '';
$errCode = $pc->decryptMsg($msg_signature, $timestamp, $nonce, $encryptMsg, $msg);
if ($errCode) {
return $errCode;
}
else {
libxml_disable_entity_loader(true);
$xml_obj = (array)simplexml_load_string($msg, 'SimpleXMLElement', LIBXML_NOCDATA);
// 返回ComponentVerifyTicket
return $xml_obj['ComponentVerifyTicket'];
}