1、将一篇文稿发布至微信的时候,微信响应失败:错误代码:45166,错误信息:invalid content hint: [pzRHda0286d228] rid: 61041ffe-5cefd269-6c9611ff。
2、最终分析得出,文稿内容中包含标签:mpvoice 所导致。文稿内容如下:
内容contentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontent
3、最终决定在调用微信接口之前,先检测 HTML 中是否存在标签:mpvoice,如果存在,则不在走后续的流程,以节省用户等待时间
4、最终实现代码如下:
$mpvoicePattern = "/]+)>(?:(?!<\/mpvoice>)[\s\S])*<\/mpvoice>/s";
$audioPattern = "/]+)>(?:(?!<\/audio>)[\s\S])*<\/audio>/s";
preg_match($mpvoicePattern, $item['content'], $mpvoiceMatches);
preg_match($audioPattern, $item['content'], $audioMatches);
if (!empty($mpvoiceMatches)) {
$this->addError($attribute, Yii::t('error', Yii::t('error', Yii::t('error', '202247'), ['tag' => 'mpvoice'])));
break;
}
if (!empty($audioMatches)) {
$this->addError($attribute, Yii::t('error', Yii::t('error', Yii::t('error', '202247'), ['tag' => 'audio'])));
break;
}
5、分别打印 $mpvoiceMatches、$audioMatches 结果如下
内容contentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentListen to the T-Rex:Your browser does not support theaudio element.
Array
(
[0] =>
[1] => class="js_editor_audio audio_iframe js_uneditable" src="/cgi-bin/readtemplate?t=tmpl/audio_tmpl&name=%E4%B8%80%E4%B8%AA%E4%BA%BA%EF%BC%8C%E4%B9%9F%E6%8C%BA%E5%A5%BD&play_length=05:22" isaac2="1" low_size="612.81" source_size="612.8" high_size="2524.76" name="一个人,也挺好" play_length="322000" voice_encode_fileid="MzI1NjA0MDg2M18yNjUwNzYzNTcz" data-topic_id="1693506805106065417" data-topic_name="夜听精选" data-pluginname="insertaudio" style="margin-top: 50px; margin-right: 0px; margin-bottom: 0px; max-width: 100%;"
)
Array
(
[0] => Your browser does not support theaudio element.
[1] => controls src="/media/cc0-audio/t-rex-roar.mp3"
)
6、当仅在内容中包含 <mpvoice、/mpvoice>、audio 等文本内容时,而不是封闭且完整的 HTML 标签,则不会触发正则的匹配。如图1

内容contentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontent/mpvoice>Listen to the T-Rex:audio controls src=\"/media/cc0-audio/t-rex-roar.mp3\">Your browser does not support theaudio element.
Array
(
[0] =>
[1] => class="js_editor_audio audio_iframe js_uneditable" src="/cgi-bin/readtemplate?t=tmpl/audio_tmpl&name=%E4%B8%80%E4%B8%AA%E4%BA%BA%EF%BC%8C%E4%B9%9F%E6%8C%BA%E5%A5%BD&play_length=05:22" isaac2="1" low_size="612.81" source_size="612.8" high_size="2524.76" name="一个人,也挺好" play_length="322000" voice_encode_fileid="MzI1NjA0MDg2M18yNjUwNzYzNTcz" data-topic_id="1693506805106065417" data-topic_name="夜听精选" data-pluginname="insertaudio" style="margin-top: 50px; margin-right: 0px; margin-bottom: 0px; max-width: 100%;"
)
Array
(
[0] => Your browser does not support theaudio element.
[1] => controls src="/media/cc0-audio/t-rex-roar.mp3"
)
需要长期技术维护或远程问题排查?
我是拥有 15+ 年经验的 PHP / Go 后端工程师,长期关注已有系统维护、Bug 修复、性能优化、服务器排查、WordPress 网站维护和小功能迭代。
如果你的项目遇到以下情况,可以先从一次小问题排查开始合作:
- ✅ PHP / Laravel / Yii2 老项目无人维护
- ✅ Go / Gin 后端接口需要排查或优化
- ✅ WordPress 网站访问慢、报错或插件冲突
- ✅ Nginx / MySQL / Redis / Linux 服务器异常
- ✅ CDN / Cloudflare / DNS / HTTPS 配置问题
- ✅ 需要长期远程技术支持或兼职维护
更多介绍请查看:关于我 & 合作
微信:13980074657
邮箱:shuijingwanwq@gmail.com
Telegram:@shuijingwan
GitHub:https://github.com/shuijingwan

发表回复