我是这样实现的,开发者工具与真机都可以了, 你可以参考 function mapFileName() { const d = new Date().getTime() + ""; const str = `qwertyuiopasdfghjklzxcvbnm`; let res = ""; d.split("").forEach((d: any) => { res += str[d as number]; }); return res; } const fs = uni.getFileSystemManager(); const filePath = `${wx.env.USER_DATA_PATH}/${mapFileName()}`; console.log("filePath", filePath); fs.writeFile({ filePath, data: qrcodeString.substring(22), encoding: "base64", success(res) { const img = canvas.createImage(); img.src = filePath; img.onload = function () { console.log("img loaded"); resolve(img); }; img.onerror = function (err: any) { console.log("img load error", err); }; }, });
canvas.createImage()在真机环境无法加载base64图片在开发工具没问题但在ios客户端上就加载不出来,没有安卓机没测试安卓是否可行。
11-13我是这样实现的,开发者工具与真机都可以了, 你可以参考 function mapFileName() { const d = new Date().getTime() + ""; const str = `qwertyuiopasdfghjklzxcvbnm`; let res = ""; d.split("").forEach((d: any) => { res += str[d as number]; }); return res; } const fs = uni.getFileSystemManager(); const filePath = `${wx.env.USER_DATA_PATH}/${mapFileName()}`; console.log("filePath", filePath); fs.writeFile({ filePath, data: qrcodeString.substring(22), encoding: "base64", success(res) { const img = canvas.createImage(); img.src = filePath; img.onload = function () { console.log("img loaded"); resolve(img); }; img.onerror = function (err: any) { console.log("img load error", err); }; }, });
canvas.createImage在IOS上绘制base64图片,显示是空白,安卓和模拟器正常?微信版本 8.0.34 手机型号 XS MAX 手机系统IOS16.3.1 基础库版本2.30.3
11-13在微信公众平台接口调试工具中测试也是同样的结果
真机通过uploadImage 获取的server_id一直提示invalid media_id?微信公众号内通过wx.uploadImage获取server_id, 服务端使用server_id通过素材下载接口获取素材到服务器一直提示 { "errcode": 40007, "errmsg": "invalid media_id hint: [wSPr4a0102e384] rid: 65b318c6-7d3c1eb2-337603ab" } 请求地址: https://api.weixin.qq.com/cgi-bin/media/get?access_token=76_oaJXFq526K-C_uzFHfWJALv7cyYBC2EL08F-fs9QntNXNP5Wr85DtwnzK7-0Ikdc6LMRe9BDoG4BAs4ztNaSEPc0DUDpkWfiB-WZQeJjx7RZu2tPIgj-L5YsvwgECOaAIAHFR&media_id=WIrJaX7HAcEqt4tx2VQGbEdo_ZM9EZKRfjksglrLi0QDHDcjPqkk8Do0-3YOHunj
01-26