- base64转本地图片?
根据这种base64转本地图片的方法在真机上,canvas画布中不显示这个二维码的图片,是什么原因? const fsm = wx.getFileSystemManager(); const FILE_BASE_NAME = 'tmp_base64src'; //自定义文件名 function base64src(base64data, cb) { const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || []; if (!format) { return (new Error('ERROR_BASE64SRC_PARSE')); } const filePath = `${wx.env.USER_DATA_PATH}/${FILE_BASE_NAME}.${format}`; const buffer = wx.base64ToArrayBuffer(bodyData); fsm.writeFile({ filePath, data: buffer, encoding: 'binary', success() { cb(filePath); }, fail() { return (new Error('ERROR_BASE64SRC_WRITE')); }, }); }; export { base64src }; import { base64src } from '../../utils/base64src.js' Page({ data: { shareQrImg: "data:image/jpeg;base64,/9j/4AAQSkZJRgA........GASDFKGKF=" //base64图片 }, onLoad: function (options) { base64src(this.data.shareQrImg, res => { console.log(res) // 返回图片地址,直接赋值到image标签即可 }); }, })
2019-12-20 - 分享到朋友圈?
分享到朋友圈,画布中的二维码不显示是什么原因,后台给返回的图片的路径是base64,代码如下: //base64转本地 const fsm = wx.getFileSystemManager(); constFILE_BASE_NAME = 'tmp_base64src'; //自定义文件名 function base64src(base64data, cb) { const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || []; if (!format) { return (newError'ERROR_BASE64SRC_PARSE')); } const filePath = ${wx.env.USER_DATA_PATH${FILE_BASE_NAME${format} const buffer = wx.base64ToArrayBuffer(bodyData); fsm.writeFile({ filePath, data: buffer, encoding: 'binary' success() { cb(filePath); }, fail() { return (newError'ERROR_BASE64SRC_WRITE')); }, }); }; //base64转本地 shareP:function(){ var that = this that.setData({ shareHide: false popup:true }) wx.request({ url: urls.urls() + 'front/wx/queryAccessToken.html' method: 'GET' data: { "aid"'wx531e717ad0dbeb56' "ast"'cfdc8121dfc43338eddb465a86ab066f' }, success: function (res) { var accessToken = res.data.data.accessToken console.log(that.data.refId) wx.request({ url: urls.urls() + 'front/wx/minProCreateQr.html' method: 'POST' header: { // "conter-type": "application.json", //get "Content-Type": "application/x-www-form-urlencoded"//post }, // responseType: 'arraybuffer',//这个是转化成base64需要加的 data: { id: that.data.refId, path: 'pages/bargainDetail/bargainDetail?refid=' + that.data.refId + '&attendMemberId=' + that.data.attendMemberId, width: '280' // is_hyaline: true, access_token: accessToken, // autoColor: false, // lineColor: { "r": 0, "g": 0, "b": 0 }, // qrType: "bargain" }, success: function (res) { console.log(that.data.refId) console.log(res.data.data.qr.qrPath) var qrPath = res.data.data.qr.qrPath that.setData({ imgUrlur: qrPath.replace(/\r\n/g,""), imgUrl1: qrPath }) // 二维码 loginUtils.base64srcs(that.data.imgUrl1, res => { // 返回图片地址,直接赋值到image标签即可 that.setData({ imgUrl1: res }) console.log(res) }); }, fail: function (res) { console.log(res.data) } }) }, fail: function (res) { console.log(res.data) } }) }, saveImg:function(){ var that = this that.shareImg() }, shareImg: function (){ var that = this console.log(that.data.bargainDetail.goodsAlbumPath) console.log(that.data.imgUrl1) wx.downloadFile({ url: that.data.bargainDetail.goodsAlbumPath, success: function (res2) { //缓存二维码 that.setData({ qrcode_temp: res2.tempFilePath }) console.log(res2.tempFilePath) wx.downloadFile({ url:that.data.imgUrl1, success:function(res){ that.setData({ qrPathUrl: res.tempFilePath }) that.drawImage(); wx.hideLoading(); setTimeout(function () { that.canvasToImage() }, 2000 } }) }, fail: function (res) { console.log(res) } }) }, drawImage() { var that = this console.log(that.data.imgUrl1) const ctx = wx.createCanvasContext('myCanvas' var bgPath = '../../images/shareBg.png' var hostNickname = that.data.memberName1; var portraitPath = that.data.photoImg1; var qrPathUrl = that.data.qrPathUrl; console.log(qrPathUrl) var windowWidth = that.data.windowWidth; var windowHeight = that.data.windowHeight; console.log(qrPathUrl) //绘制背景图片 ctx.drawImage(bgPath, , , windowWidth, windowHeight) //绘制第一段文本 // ctx.setFillStyle('#ffffff') ctx.setFontSize(0.04 * windowWidth) ctx.setTextAlign('center' ctx.fillText( '您的好友邀请您一起参加塞上房砍价活动', windowWidth / , 0.25 * windowWidth) //绘制第二段文本 // ctx.setFillStyle('#ffffff') ctx.setFontSize(0.04 * windowWidth) ctx.setTextAlign('center' ctx.fillText('立即打开看看吧', windowWidth / , 0.30 * windowWidth) //绘制商品图片 var qrcode_temp = that.data.qrcode_temp; ctx.drawImage(qrcode_temp, 0.1 * windowWidth, 0.35 * windowWidth, 0.8 * windowWidth, 180); //绘制商品名称 const goodsTitle = that.data.bargainDetail.goodsName; console.log(that.data.bargainDetail.goodsName) let goodsTitleArray = []; //为了防止标题过长,分割字符串,每行18个 for (let i = ; i < goodsTitle.length / 27; i++) { if (i > ) { break } goodsTitleArray.push(goodsTitle.substr(i * 27, 27)); } goodsTitleArray.forEach(function (value) { ctx.setFontSize(0.04 * windowWidth) // ctx.setFillStyle('#ffffff'); ctx.setTextAlign('left'); ctx.fillText(value, 0.1 * windowWidth, 0.92* windowWidth); windowWidth += 25 }); // 商品价格 // 底价 var endPrice = that.data.bargainDetail.endPrice; // ctx.setFillStyle('#ffffff') ctx.setFontSize(0.05 * windowWidth) ctx.setTextAlign('left' ctx.fillText('底价:¥' + endPrice, 0.1 * windowWidth, 0.97 * windowWidth) // 原价 var goodsPrice = that.data.bargainDetail.goodsPrice; ctx.setFillStyle('#cccccc' ctx.setFontSize(0.037 * windowWidth) ctx.setTextAlign('left' ctx.fillText('原价:¥' + goodsPrice, 0.5 * windowWidth, 0.97 * windowWidth) //绘制二维码 ctx.drawImage(qrPathUrl, 0.64 * windowWidth / 2.5, 1.02 * windowWidth, 0.4 * windowWidth, 0.4 * windowWidth) //绘制第三段文本 // ctx.setFillStyle('#ffffff') ctx.setFontSize(0.037 * windowWidth) ctx.setTextAlign('center' ctx.fillText('长按识别二维码帮我砍价', windowWidth / 2.3, 1.5* windowWidth) ctx.draw(); }, canvasToImage() { var that = this // canvas画布转成图片 wx.canvasToTempFilePath({ quality: fileType: 'jpg' canvasId: 'myCanvas' success: function (res) { wx.hideLoading(); console.log('11' + res.tempFilePath); that.setData({ img_temp: res.tempFilePath }) wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success(res) { console.log(res); }, fail: function (res) { if (res.errMsg === "saveImageToPhotosAlbum:fail auth deny") { wx.openSetting({ success(settingdata) { if (settingdata.authSetting['scope.writePhotosAlbum']) { wx.showToast({ title: '保存图片失败,请重新保存' }) } else { console.log('获取权限失败,给出不给权限就无法正常使用的提示' } } }) } } }) }, fail: function (res) { console.log(res) } }, this },
2019-12-19 - 更新问题?
微信小程序更新版本发布上线之后,强制更新线上版本不起作用 // 检测是否可以调用getUpdateManager检查更新 if (!wx.canIUse("getUpdateManager")) return; console.log(wx.canIUse("getUpdateManager")) let updateManager = wx.getUpdateManager(); updateManager.onCheckForUpdate(function (res) { console.log("是否有新版本:" + res.hasUpdate); if (res.hasUpdate) { console.log('小程序更新了') updateManager.onUpdateReady(function () { updateManager.applyUpdate(); }) updateManager.onUpdateFailed(function () { wx.showModal({ title: '提示', content: '检查到有新版本,但下载失败,请稍后尝试', showCancel: false, }) }) }else{ console.log('小程序没有没有没有没有没有没有没有没有更新') updateManager.applyUpdate(); } });
2019-12-18 - 微信内嵌h5页面?
微信小程序内嵌h5页面,页面中不显示二维码,但是打开的链接中有二维码 [图片][图片] wxml: <web-view src="{{wxUrl}}"></web-view> js: data: { wxConfigBindShopManager: { url: "https://open.weixin.qq.com/connect/qrconnect?appid=xxxxxx&state=bind&response_type=code&scope=snsapi_login&redirect_uri=http%3A%2F%2Fsaishangfang.com%2Ffront%2Fwx%2FwxBindEpy.html", redirectUrl: "http://saishangfang.com/front/wx/wxBindEpy.html", appID: "xxxxxxxxxxx", appSecret: "xxxxxxxxxxxx", href: "https://www.saishangfang.com/static/modules/front/bms/css/login.css" }, wxUrl: '', }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(options.storeId) var config = this.data.wxConfigBindShopManager; var url = config.url + '?storeId=' + options.storeId + "&href=" + config.href; this.setData({ wxUrl: url }) console.log(url) },
2019-12-16 - 微信登录的二维码?
微信小程序中怎么生成微信登录的二维码?
2019-12-14 - 微信小程序生成当前页面的小程序码?
小程序生成当前页面的小程序码,在本地和体验版中都是好的,但是在发布的版本中显示不出来,是什么原因? wx.request({ url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxxxxxxxxx&secret=xxxxxxxxxx', method: 'GET', success: function (res) { console.log(res) var access_token = res.data.access_token; // 获取二维码 wx.request({ url: 'https://api.weixin.qq.com/wxa/getwxacode?access_token=' + access_token, method: 'POST', responseType: 'arraybuffer',//这个是转化成base64需要加的 data: { path: 'pages/bargainDetail/bargainDetail?refid=' + that.data.refId + '&attendMemberId=' + that.data.attendMemberId, width: '200', }, success: function (res) { console.log('-----------******************************') var imgUrl2 = wx.arrayBufferToBase64(res.data) var imgUrl3 = 'data:image/png;base64,' + imgUrl2 console.log('---------------------------//////////////////////////////') that.setData({ imgUrl1: 'data:image/png;base64,' + imgUrl2, imgUrll: imgUrl3.replace(/\r\n/g,'') })
2019-12-12 - 微信小程序扫描普通二维码,生成普通二维码的地址是什么?
微信小程序扫描普通二维码,生成普通二维码的地址具体是什么?我的地址是https://www.saishangfang.com/pages/bargainDetail/bargainDetail这个,小程序后天配置好了,但是打开是网页
2019-12-07