1. When publishing an article to WeChat, WeChat responded with a failure: error code: 45166, error message: invalid content hint: [pzRHda0286d228] rid: 61041ffe-5cefd269-6c9611ff.
2. The final analysis concluded that this was caused by the inclusion of the tag: mpvoice in the article content. The article content is as follows:
内容contentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontent
3. I finally decided to check whether the HTML contains the tag: mpvoice before calling the WeChat API. If it exists, the subsequent process is skipped to save the user’s waiting time.
4. The final implementation code is as follows:
$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. The results of printing $mpvoiceMatches and $audioMatches respectively are as follows:
内容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. When the content only contains text such as <mpvoice, /mpvoice>, and audio, rather than closed and complete HTML tags, the regex match is not triggered. See Figure 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"
)
