var app = getApp(); //在page外面定义app
ycq: function () { //我的二维码生成
var that=this;
wx.request({
url: app.getRequestUrl + '/notify_url/QRCode', //官方接口,不用更改;app.getRequestUrl为app.js里面的http路径,需后台提供
data: {
Appid: app.globalData.appId,
Secret: app.globalData.secret,
page: 'pages/index/index', //扫码进入的页面,填写你小程序的页面
scene: app.globalData.openId + ',' + app.globalData.vid, //你跳传的页面需要什么参数就填什么参数
width: '430',
},
method: 'POST',
responseType: 'text',
success: function (res) {
var ImgUrl = app.ImgUrl + res.data.ImgUrl //app.ImgUrl为app.js里面的http地址,需要后台提供
wx.downloadFile({
url: ImgUrl,
success: function (res) {
console.log(res)
if(res.statusCode==200){
wx.hideLoading();
that.setData({
cordimg:res.tempFilePath,
})
}
},
fail: function (res) {
console.log(res)
}
})
},
})
},
// 长按保存二维码 bindlongpress="SaveImage"
SaveImage: function (e) {
wx.saveImageToPhotosAlbum({
filePath: this.data.cordimg,
success: function (res) {
wx.showToast({
title: '已保存',
icon: 'success',
duration: 2000
})
},
})
},
ps:基本有备注的地方需要注意还有稍微的修改,事件在wxml自己加,其余都不用更改