1、index.js
Page({
onLoad: function (options) {
console.log('test')
wx.cloud.callFunction({
name: "yhs1",
data: {},
success: res =>{
console.log('test2')
console.log('test1',res.result.buffer)
this.setData({
imaget:res.result.buffer
})
},
fail: err =>{
console.log()
}
})
},
check: function () {
var imaget=this.data.imaget
console.log('test1',imaget)
console.log('test')
wx.cloud.callFunction({
name: "yhs2",
data: {
demo:imaget
},
success: res =>{
console.log('test2')
console.log('test1',res.result)
this.setData({
imaget2:res.fiedId
})
},
fail: err =>{
console.log()
}
})
}
})
2、index.wxml
<image style="width: 200px; height: 200px; background-color: #eeeeee;" mode="{{item.mode}}" src="{{imaget2}}"></image>
<view class="crr">
<button class="ff" bindtap='check'>test</button>
</view>
3、云函数yhs1
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
env: 'testw-z6k1v'
})
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.wxacode.createQRCode({
path: 'page/index/index',
width: 430
})
return result
} catch (err) {
return err
}
}
4、云函数yhs2
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
env: 'testw-z6k1v',
})
exports.main = async (event, context) => {
return await cloud.uploadFile({
cloudPath: 'demo.jpg',
fileContent: event.demo
})
}
运行后:
{contentType: "image/jpeg", buffer: ArrayBuffer(55707), errMsg: "openapi.wxacode.createQRCode:ok", errCode: 0}buffer: ArrayBuffer(55707)[[Int8Array]]: Int8Array(55707) [-1, -40, -1, -32, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, -1, -37, 0, 67, 0, 3, 2, 2, 3, 2, 2, 3, 3, 3, 3, 4, 3, 3, 4, 5, 8, 5, 5, 4, 4, 5, 10, 7, 7, 6, 8, 12, 10, 12, 12, 11, 10, 11, 11, 13, 14, 18, 16, 13, 14, 17, 14, 11, 11, 16, 22, 16, 17, 19, 20, 21, 21, 21, 12, 15, 23, 24, 22, 20, 24, 18, 20, 21, 20, -1, -37, 0, 67, 1, 3, 4, 4, 5, 4, 5, …][[Uint8Array]]: Uint8Array(55707) [255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, 219, 0, 67, 0, 3, 2, 2, 3, 2, 2, 3, 3, 3, 3, 4, 3, 3, 4, 5, 8, 5, 5, 4, 4, 5, 10, 7, 7, 6, 8, 12, 10, 12, 12, 11, 10, 11, 11, 13, 14, 18, 16, 13, 14, 17, 14, 11, 11, 16, 22, 16, 17, 19, 20, 21, 21, 21, 12, 15, 23, 24, 22, 20, 24, 18, 20, 21, 20, 255, 219, 0, 67, 1, 3, 4, 4, 5, 4, 5, …]byteLength: (...)__proto__: ArrayBuffercontentType: "image/jpeg"errCode: 0errMsg: "openapi.wxacode.createQRCode:ok"__proto__: Object
index.js:28 test1 {contentType: "image/jpeg", buffer: ArrayBuffer(55707), errMsg: "openapi.wxacode.createQRCode:ok", errCode: 0}
cloud.init({
})
// 云函数入口文件
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.wxacode.createQRCode({
path: 'page/index/index?msessage='+message,
width: 430
})
const file = await cloud.uploadFile({
cloudPath: 'demo.jpg',
fileContent: result.buffer,
})
return file
} catch (err) {
return err
}
}
// 云函数入口文件
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.wxacode.createQRCode({
path:event.urlname,
width: 410
})
const file = await cloud.uploadFile({
cloudPath: 'ms.jpg',
fileContent: result.buffer,
})
return file
} catch (err) {
return err
}
}
--------------------------------------------------------
运行后,提示:页面不存在