HarmonyOS NEXT 微信分享无法使用包含中文编码的图片url uni-app
HarmonyOS NEXT 微信分享无法使用包含中文编码的图片url uni-app
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| Windows | Windows 11 专业版 | CLI |
示例代码:
// 无法工作
uni.share({
"title": "title",
"summary": "summary",
"provider": "weixin",
"scene": "WXSceneSession",
"type": 0,
// 或者 https://example.com/图片.jpg
"imageUrl": "https://example.com/%E5%9B%BE%E7%89%87.jpg",
"href": "https://example.com/some"
})
uni.share({
"provider": "weixin",
"scene": "WXSceneSession",
"type": 2,
// 或者 https://example.com/图片.jpg
"imageUrl": "https://example.com/%E5%9B%BE%E7%89%87.jpg",
})
// 正常工作
uni.share({
"title": "title",
"summary": "summary",
"provider": "weixin",
"scene": "WXSceneSession",
"type": 0,
"imageUrl": "https://example.com/photo.jpg",
"href": "https://example.com/some"
})
uni.share({
"provider": "weixin",
"scene": "WXSceneSession",
"type": 2,
"imageUrl": "https://example.com/photo.jpg",
})
更多关于HarmonyOS NEXT 微信分享无法使用包含中文编码的图片url uni-app的实战教程也可以访问 https://www.itying.com/category-93-b0.html
5 回复
hello,这是鸿蒙平台的限制,请不要使用中文字符
更多关于HarmonyOS NEXT 微信分享无法使用包含中文编码的图片url uni-app的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
并非平台限制,这个url可以正常显示和下载的。 而且我自己参考市场插件代码编写UTS代码调用微信分享API可以实现微信分享的
反正我知道微信分享SDK是不能直接分享网络地址需要下载下来转成base64作为参数发,我估计是你们底层实现这个下载方法有问题。
在HarmonyOS NEXT平台上,微信分享功能对包含中文编码的图片URL存在兼容性问题。这是由于系统底层URL解析机制与微信SDK的交互导致的。
问题分析:
- 当图片URL包含中文字符(如
图片.jpg)时,即使经过URL编码(%E5%9B%BE%E7%89%87.jpg),在HarmonyOS NEXT的微信分享中仍无法正常加载 - 纯英文路径的图片URL(如
photo.jpg)可以正常工作 - 这属于平台特定的兼容性问题,在其他Android/iOS平台上可能正常
解决方案:
- 服务端重命名:将图片文件重命名为英文或数字命名规则
- URL重写:通过CDN或反向代理将中文路径映射为英文路径
- 临时方案:在分享前将图片下载到本地,使用临时文件路径分享
// 方案3示例代码
uni.downloadFile({
url: 'https://example.com/图片.jpg',
success: (res) => {
if (res.statusCode === 200) {
uni.share({
provider: "weixin",
scene: "WXSceneSession",
type: 2,
imageUrl: res.tempFilePath
})
}
}
})


