人面识别(二)

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

})

}

})

},

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容