Repository navigation
fix(wechat-official): 修复临时素材上传时 img 媒体类型错误及解构崩溃 - #448
Open
VincentZyu233 wants to merge 4 commits into
Open
VincentZyu233 wants to merge 4 commits into
VincentZyu233 wants to merge 4 commits into
Conversation
Co-authored-by: gemini-code-assist <200291788+gemini-code-assist@users.noreply.github.com>
Co-authored-by: gemini-code-assist <200291788+gemini-code-assist@users.noreply.github.com>
Co-authored-by: gemini-code-assist <200291788+gemini-code-assist@users.noreply.github.com>
Co-authored-by: gemini-code-assist <200291788+gemini-code-assist@users.noreply.github.com>
VincentZyu233
marked this pull request as ready for review
November 7, 2026 05:56
Contributor
Author
实机验证通过 (Verified in Production)经过真实微信公众号环境实机测试,本次 PR 的各项功能均已验证生效:
实机测试截图1. 文本 / 图片 / 语音 实机测试效果 2. 超链接与小程序跳转 实机测试效果 |
Contributor
Author
💡 核心改动依据与业界成熟实践参考补充说明本 PR 的核心改动依据。除已通过真实微信公众号实机测试验证外,本 PR 的设计亦严格遵循微信官方规范并对齐业界成熟微信 SDK 的最佳实践: 1. 媒体类型映射 (
|
VincentZyu233
force-pushed
the
fix/wechat-official-media-type-img
branch
2 times, most recently
from
November 7, 2026 06:36
7381ba1 to
8a189fd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


问题描述
在
@satorijs/adapter-wechat-official中,当插件通过h.image(...)发送图片时(生成<img ...>元素,element.type === 'img'),微信公众号被动回复无法发出图片并报错崩溃。根因分析
在
uploadMedia(element)中,代码写为:audio -> voice进行了转换,而未将element.type === 'img'转换为微信要求的image。微信公众平台临时素材上传接口(
/cgi-bin/media/upload)仅支持image、voice、video、thumb,不支持img。当传入type=img时,微信直接返回错误:{ "errcode": 40004, "errmsg": "invalid media type hint: ..." }media_id,导致uploadMedia返回undefined。在
flushMedia(element)中:undefined进行数组解构,瞬间抛出TypeError: (intermediate value) is not iterable未捕获异常;导致本次 Webhook 请求未在 5 秒内返回 XML 响应,触发超时无应答。修复方案
uploadMedia中增加对img -> image的类型转换;flushMedia中对uploadMedia返回值进行存在性校验,避免解构undefined引发进程异常;40001Token 失效时自动刷新凭据重试;visit中支持type === 'a'并生成合规 HTML 标签,对未知元素 fallback 递归渲染兜底。