上一篇介紹了通過官方接口工具和postman報文工具獲取小程序指定頁面的二維碼。
參數(shù)固定,總歸是不夠個性化。
今天給大家介紹下通過小程序云開發(fā)獲取帶參數(shù)二維碼。
1. 小程序服務(wù)端:獲取帶參數(shù)二維碼
(1)配置云函數(shù)config.json
"wxacode.get"

(2)云函數(shù)調(diào)用

2. 小程序客戶端:展示帶參數(shù)二維碼
??getQR:?function(){
????var?thePage?=?this;
????wx.cloud.callFunction({
??????//?要調(diào)用的云函數(shù)名稱
??????name:?'dbTest',
??????//?傳遞給云函數(shù)的event參數(shù)
??????data:?{
????????opt:?'getQrCode'
??????}
????}).then(res?=>?{
??????console.log("getQrCode?suc:",?res);
??????let?fileManager?=?wx.getFileSystemManager();//獲取文件管理器
??????let?filePath?=?wx.env.USER_DATA_PATH?+?'/inner.jpg';//設(shè)置臨時路徑
??????fileManager.writeFile({//獲取到的數(shù)據(jù)寫入臨時路徑
????????filePath:?filePath,//臨時路徑
????????encoding:?'binary',//編碼方式,二進(jìn)制
????????data:?res.result.buffer,//請求到的數(shù)據(jù)
????????success:?function(res)?{
??????????wx.previewImage({//圖片預(yù)覽
????????????urls:?[filePath],
??????????})
??????????wx.hideLoading();
????????},
????????fail:?function(res)?{
??????????console.log(res)
??????????wx.hideLoading();
????????},
??????});
????}).catch(err?=>?{
??????console.log("getQrCode?fail:",?err);
????})
??}
