123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- const tip_en = require("../../international/ocr_scence/index")
- const app = getApp()
- const upload_image = require("../../utils/upload/upload_image")
- const {
- getPassportDetail, BaiDuFaceComparison
- } = require("../../utils/api/make_appointment")
- Page({
-
- data: {
-
- isChinese: true,
-
- tip: tip_en,
-
- type_list: [{
- name_ch: '护照',
- name_en: 'passport',
- type: 13
- },
-
-
-
- ],
- type_index: 0,
- type: 13,
- needPhoto: false,
- },
-
- chooseType(e) {
- this.setData({
- type_index: e.detail.value,
- type: this.data.type_list[e.detail.value].type
- })
- },
-
- doOCR() {
- var that = this;
- if (!this.data.type) {
- wx.showToast({
- title: this.data.isChinese ? '请先选择证件类型~' : 'Please select the id type~',
- icon: 'none'
- });
- return;
- }
- wx.chooseMedia({
- count: 1,
- mediaType: ['image'],
- sourceType: ['album', 'camera'],
- sizeType: ['original'],
- success(res) {
- var image = {
- url: res.tempFiles[0].tempFilePath
- }
- wx.showLoading({
- title: that.data.isChinese ? '上传中~' : 'uploading...',
- })
-
- upload_image(image).then((img) => {
- wx.hideLoading()
- var data = {
- passportUrl: img.url,
- type: that.data.type
- }
- that.checkInfo(data)
- }).catch(() => {
- wx.hideLoading()
- })
- }
- })
- },
-
- checkInfo(data) {
- let that = this;
- wx.showLoading({
- title: that.data.isChinese ? '识别中...' : 'recognizing..',
- })
-
- getPassportDetail(data).then(res => {
- wx.hideLoading();
-
- if (res.code != 200) {
- wx.showModal({
- content: res.msg,
- showCancel: false
- });
- return;
- }
-
- if (!res.data.avatar) {
- wx.showModal({
- content: 'Sorry, OCR Failed. Please make sure the photo is clear and complete, then try again。',
- showCancel: false,
- });
- return;
- }
-
- that.data.ocrInfo = res.data;
- that.data.ocrInfo.passportUrl = data.passportUrl;
-
- if (that.data.needRealname || that.data.needPhoto) {
- that.data.flag = 3;
- wx.navigateTo({
- url: '/pages/faceCheck/faceCheck'
- });
- return;
- }
-
- app.data.ocrInfo = that.data.ocrInfo;
- wx.navigateBack({
- delta: 1
- })
- }).catch(err => {
- wx.hideLoading()
- })
- },
-
- comparePhoto() {
- const that = this;
- let img = app.data.catchFaceUrl;
- app.data.catchFaceUrl = null;
-
- if(!img) {
- wx.showModal({
- content: that.data.isChinese ? '抓拍失败, 再试一次吧' : 'Sorry,failed to capture a profile picture,pleas try again。',
- showCancel: false,
- complete: (res) => {}
- })
- return;
- }
-
-
- if(!this.data.needRealname) {
- that.data.ocrInfo.faceImage = img
- app.data.ocrInfo = that.data.ocrInfo;
- wx.navigateBack({
- delta: 1
- })
- return;
- }
-
- let data = {
- faceImage: img,
- cardImage: that.data.ocrInfo.avatar || '',
- }
- BaiDuFaceComparison(data).then(res => {
-
- if(res.data) {
- that.data.ocrInfo.faceImage = img
- app.data.ocrInfo = that.data.ocrInfo;
- wx.navigateBack({
- delta: 1
- })
-
- } else {
- wx.showModal({
- content: that.data.isChinese ? '比对失败, 请保持光线良好,护照照片清晰,再试一次吧' : 'Sorry,the comparison failed,keep the light good and the passport clear,then try again。',
- showCancel: false,
- complete: (res) => {}
- })
- }
- })
- },
-
- onLoad: function (options) {
- this.setData({
- needPhoto: options.needPhoto === 'true' ? true:false,
- needRealname: options.needRealname === 'true'? true:false
- })
- if (app.data.language == 'ch') {
- this.setData({
- isChinese: true
- })
- } else {
- this.setData({
- isChinese: false
- })
- }
-
- app.data.fake = false
-
- },
-
- onReady: function () {
- },
-
- onShow: function () {
-
- if(this.data.flag == 3) {
- this.data.flag = null;
- this.comparePhoto()
- }
- },
-
- onHide: function () {
- },
-
- onUnload: function () {
- },
-
- onPullDownRefresh: function () {
- },
-
- onReachBottom: function () {
- },
-
- onShareAppMessage: function () {
- }
- })
|