1-在onLoad中,获取数字验证码,创建摄像上下文,不然放视频没声音。
this.getVoiceCode()
this.setData({
post: app.globalData.postion
})
this.ctx = wx.createCameraContext()
2-获取验证码
getVoiceCode(){
wx.showLoading({
title: '正在加载数据...',
})
let _this = this
wx.request({
url: 'http://192.168.30.112:7890/VoiceCode',
header:{
"content-type": "application/x-www-form-urlencoded"
},
method: "POST",
success: function (res) {
_this.setData({
VoiceCode: res.data.code,
session_id: res.data.session_id
})
wx.hideLoading()
}
})
},
3-开始录视频
startRecord2: function(){
let _this = this
wx.chooseVideo({
sourceType: ['camera'],
compressed: true,
maxDuration: 5,
camera: 'front',
success: function(res){
console.log(res);
let FM = wx.getFileSystemManager()
FM.readFile({
filePath: res.tempFilePath,
encoding: "base64",
success: function (data) {
wx.showLoading({
title: '正在验证数据...',
})
wx.request({
url: 'http://192.168.30.112:7890/Verify',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
data:{
session_id: _this.data.session_id,
video_base64: data.data
},
method: "POST",
success: function (res) {
console.log(res)
wx.hideLoading()
}
})
},
fail: function (err) {
console.log(err)
}
})
_this.setData({
videoSrc: res.tempFilePath
})
}
})
},