手机型号 Samsung Galaxy S23 Ultra Samsung Galaxy S23+
地区 葡萄牙里斯本地区
// ============ 微信交流区提问代码片段 ============
// 问题:调用 wx.showShareImageMenu 后,点击发送给朋友圈"有时会显示"网络错误之类的提示"
// 场景:电商小程序,生成商品海报并分享
// 代码流程:
// 1. Canvas 绘制海报
const ctx = uni.createCanvasContext('poster', this);
ctx.fillRect(0, 0, 375, 667);
ctx.setFillStyle('#FFF');
ctx.fillRect(0, 0, 375, 667);
ctx.drawImage(productImagePath, 0, 0, 375, 375);
ctx.drawImage(qrcodeUrl, 255, 547, 120, 120);
// 2. Canvas 转临时文件
ctx.draw(true, () => {
uni.canvasToTempFilePath({
canvasId: 'poster',
width: 375,
height: 667,
success: async (res) => {
console.log('海报生成成功:', res.tempFilePath);
// 3. 关闭自定义 loading
uni.hideLoading();
// 4. 调用微信分享图片菜单
wx.showShareImageMenu({
path: res.tempFilePath, // 临时文件路径
needShowEntrance: true,
entrancePath: 'pages/category/index?scene=s=123,cuid=456,i=1',
success: () => {
console.log('打开分享菜单成功');
// 国内用户约 500ms,海外用户(葡萄牙)约 1-2s
// 有时出现"network error"
},
fail: (err) => {
console.error('失败:', err);
}
});
}
});
});
// ============ 环境信息 ============
// 图片大小:约 200-500KB
// 图片格式:PNG
// 图片尺寸:750x1334 (canvas) -> 375x667 (输出)
