takePhoto() { const ctx = wx.createCameraContext() ctx.takePhoto({ quality: 'high', success: (res) => { this.setData({ src: res.tempImagePath }) wx.uploadFile({ url: "http://lichenlu.top/server/index.php/home/index/login", filePath: this.data.src, name: 'file', success: function (res) { console.log(res.data); wx.showToast({ title: res.data, icon: 'none', duration: 2000 }) } }) } }) }, error(e) { console.log(e.detAIl) },
chooseImage: function () { var that = this wx.chooseImage({ // // sourceType: sourceType[this.data.sourceTypeIndex], // sizeType: sizeType[this.data.sizeTypeIndex], // count: this.data.count[this.data.countIndex], count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { console.log(res) that.setData({ imageList: res.tempFilePaths }) } }) }, //预览图片 previewImage: function (e) { var current = e.target.dataset.src wx.previewImage({ current: current, urls: this.data.imageList }) }
前台调用接口打开手机摄像头,后台设置接口中的内容 上传拍照内容到阿里云服务器的uploads文件夹中,此外还要建立百度云人脸头像小组 以下为上传到百度云后台
private function face_group(){ //组名 $groupname = 'pingjiao'; $client = $this->init_face(); $ret = $client->getGroupList(); if($ret['eror_code']==0){ $grouplist = $ret['result']['group_id_list']; if(in_array($groupname, $grouplist)){ return $groupname; }else{ $ret = $client->groupAdd($groupname); if($ret['error_code'] == 0){ return $groupname; }else{ return false; } } }else{ return false; } }
上传照片时检查人脸可靠性等判断
if($ret['error_code']==0){//有人脸 $result = $ret['result']; $face_num = $result['face_num']; if(1 == $face_num){//人脸数量为1 $face_probability = $result['face_list'][0]['face_probability']; if(1 == $face_probability){ //可靠性为1 // $guid = myguid(); $group = $this->face_group(); $faces = $client->addUser($image,'BASE64',$group); // echo '人脸检测完成,并已入库'; if($faces['error_code']>0){ $client->addUser($image,'BASE6',$group,$no); }else{ // die('可靠性为:'. $face_probability); $client -> updateUser($image,'BASE64',$group,$no); } return true; }else{ // die('人脸数量大于1'); die('图片数量仅为:' . $face_probability . ',上传失败!'); } } }