| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404 |
- import {
- postApprove,
- getOcrKey
- } from '../../services/index.js'
- import {
- uploadImg
- } from '../../services/uploadFile.js'
- import {
- apiUrl
- } from '../../config/config.js'
- import { url } from '../../api/api'
- import {
- imgServerUrl,
- imgServerUrl_new
- } from '../../config/config.js'
- import { isIDNum } from '../../utils/base'
- var app = getApp()
- const ocrSdk = require("../../ocrsdk/index");
- const fs = wx.getFileSystemManager()
- Page({
- data: {
- imgServerUrl: imgServerUrl,
- imgServerUrl_new: imgServerUrl_new,
- realName: '',
- idNum: '',
- nation: '',
- idFrontPic: '',
- idBackPic: '',
- idPersonPic: '',
- showMessage: false,
- showPass: false,
- message: '',
- canUpdate: false,
- from: '',
- tmpSecretId: '',
- tmpSecretKey: '',
- frontStatus: '',
- backStatus: ''
- },
- onLoad: function (options) {
- if (options.from) {
- this.setData({
- from: options.from
- })
- }
- },
- onShow: function () {
- getOcrKey().then(data => {
- this.setData({
- tmpSecretId: data.data.secretId,
- tmpSecretKey: data.data.secretKey,
- })
- })
- },
- changeShowMessage() {
- this.setData({
- showMessage: !this.data.showMessage
- })
- },
- changeShowPass() {
- this.setData({
- showPass: !this.data.showPass
- })
- },
- testCanUpdate() {
- let {
- realName,
- idNum,
- idFrontPic,
- idBackPic,
- // idPersonPic
- } = this.data;
- this.setData({
- canUpdate: false
- })
- if (realName == "") {
- return false;
- }
- if (!isIDNum(idNum)) {
- return false;
- }
- if (idFrontPic == "") {
- return false;
- }
- if (idBackPic == "") {
- return false;
- }
- this.setData({
- canUpdate: true
- })
- return true
- },
- callPhone() {
- wx.makePhoneCall({
- phoneNumber: '4006920099',
- success: () => {
- this.setData({
- showMessage: false
- })
- }
- })
- },
- async chooseImage(e) {
- let index = e.currentTarget.dataset.index
- const data = await this.ocrSdkStart(index)
- var up_type;
- switch (index) {
- case 1:
- up_type = '1';
- this.setData({
- idFrontPic: false
- }, _ => {
- fs.unlink({
- filePath: this.data.idFrontPic,
- complete: () => {
- const filePath = `${wx.env.USER_DATA_PATH}/identificationIdFrontPic${new Date().getTime()}.png`
- fs.writeFile({
- filePath,
- data: JSON.parse(data.AdvancedInfo).IdCard,
- encoding: 'base64',
- success: res => {
- this.setData({
- realName: data.Name,
- idNum: data.IdNum,
- nation: data.Nation,
- idFrontPic: filePath
- })
- this.testCanUpdate()
- },
- fail: (res) => {
- console.log(res)
- }
- })
- }
- })
- })
- break;
- case 2:
- up_type = '2';
- this.setData({
- idBackPic: false
- }, _ => {
- fs.unlink({
- filePath: this.data.idBackPic,
- complete: () => {
- const filePath = `${wx.env.USER_DATA_PATH}/identificationIdBackPic${new Date().getTime()}.png`
- fs.writeFile({
- filePath,
- data: JSON.parse(data.AdvancedInfo).IdCard,
- encoding: 'base64',
- success: res => {
- this.setData({
- idBackPic: filePath
- })
- this.testCanUpdate()
- },
- fail: (res) => {
- console.log(res)
- }
- })
- }
- })
- })
- break;
- case 3:
- up_type = '3';
- break;
- }
- // uploadImg(up_type).then(res => {
- // let image = res.data.imgUrl
- // if (index == 1) {
- // this.setData({
- // idFrontPic: image
- // }, _ => {
- // this.testCanUpdate()
- // })
- // } else if (index == 2) {
- // this.setData({
- // idBackPic: image
- // }, _ => {
- // this.testCanUpdate()
- // })
- // } else if (index == 3) {
- // this.setData({
- // idPersonPic: image
- // }, _ => {
- // this.testCanUpdate()
- // })
- // }
- // })
- },
- changeName(e) {
- this.setData({
- realName: e.detail.value.trim()
- }, _ => {
- this.testCanUpdate()
- })
- },
- changeId(e) {
- this.setData({
- idNum: e.detail.value.trim()
- }, _ => {
- this.testCanUpdate()
- })
- },
- async submit(e) {
- this.testCanUpdate();
- let {
- realName,
- idNum,
- idFrontPic,
- idBackPic,
- nation,
- // idPersonPic
- } = this.data;
- if (realName == "") {
- wx.showToast({
- title: '请输入姓名',
- icon: 'none'
- })
- return false;
- }
- if (!isIDNum(idNum)) {
- wx.showToast({
- title: '请输入18位身份证号码',
- icon: 'none'
- })
- return false;
- }
- if (idFrontPic == "") {
- wx.showToast({
- title: '请上传身份证正面照',
- icon: 'none'
- })
- return false;
- }
- if (idBackPic == "") {
- wx.showToast({
- title: '请上传身份证反面照',
- icon: 'none'
- })
- return false;
- }
- // if (idPersonPic == "") {
- // wx.showToast({
- // title: '请上传手持身份证照片',
- // icon: 'none'
- // })
- // return false;
- // }
- wx.showLoading({
- title: '正在创建...',
- mask: true
- })
- let paramsObj = {
- realName: realName,
- idCardNumber: idNum,
- idFrontPic: idFrontPic,
- idBackPic: idBackPic,
- nation: nation,
- // idPersonPic: idPersonPic,
- minaType: 1, //1:代表小程序
- user_id: app.globalData.userId,
- user_token: app.globalData.userToken,
- member_id: app.globalData.memberId
- }
- const idFrontPicPath = paramsObj.idFrontPic
- paramsObj.idFrontPic = await this.uploadFile(1, idFrontPicPath)
- fs.unlinkSync(idFrontPicPath)
- const idBackPicPath = paramsObj.idBackPic
- paramsObj.idBackPic = await this.uploadFile(2, idBackPicPath)
- fs.unlinkSync(idBackPicPath)
- wx.hideLoading()
- wx.showLoading({
- title: '正在提交...',
- mask: true
- })
- postApprove(paramsObj).then(data => {
- wx.hideLoading()
- wx.showToast({
- title: '提交成功',
- })
- if (this.data.from === 'clock') {
- wx.redirectTo({
- url: '../result/index?type=auth&status=2&from=clock',
- })
- // this.setData({
- // showPass: true,
- // message: '您的实名认证已通过'
- // })
- return
- }
- wx.redirectTo({
- url: '../result/index?type=auth&status=2',
- })
- }).catch(data => {
- wx.hideLoading()
- if (data.errcode === 2100) {
- this.setData({
- showMessage: true,
- message: '您的身份证已经被实名认证'
- })
- return
- }
- if (data.errcode === 2101) {
- this.setData({
- showMessage: true,
- message: '您已实名认证,无需重复认证'
- })
- return
- }
- })
- // 身份认证上报订阅信息
- wx.aldPushSubscribeMessage({
- eventId: '5ea25ae37739104342928e96'
- });
- },
- uploadFile(up_type, filePath) {
- return new Promise((reslove, reject) => {
- wx.uploadFile({
- url: apiUrl + url.imgUp,
- filePath,
- name: 'file',
- header: {},
- formData: {
- up_type,
- user_id: wx.getStorageSync("user_id"),
- user_token: wx.getStorageSync("user_token"),
- member_id: wx.getStorageSync("member_id")
- },
- success: (res) => {
- let data = JSON.parse(res.data)
- reslove(data.data.imgUrl)
- },
- fail: () => {
- reject()
- }
- })
- })
- },
- ocrSdkStart(type) {
- return new Promise((reslove, reject) => {
- ocrSdk.start({
- getAuthorization: () => {
- return new Promise((reslove, reject) => {
- reslove({
- tmpSecretId: this.data.tmpSecretId,
- tmpSecretKey: this.data.tmpSecretKey,
- })
- })
- },
- ocrType: type === 1 ? ocrSdk.OcrType.ID_CARD_FRONT : ocrSdk.OcrType.ID_CARD_BACK,
- ocrOption: {
- Config: {
- "CropIdCard": true,
- "CropPortrait": true,
- }
- },
- cameraConfig: {
- autoMode: false,
- maxTry: 3,
- disableAlbum: false
- },
- success: (res) => {
- reslove(res)
- if (type === 1) {
- this.setData({
- frontStatus: true
- })
- } else {
- this.setData({
- backStatus: true
- })
- }
- wx.navigateBack({
- delta: 1,
- })
- },
- fail: (error) => {
- reject(error)
- if (type === 1) {
- this.setData({
- frontStatus: false
- })
- } else {
- this.setData({
- backStatus: false
- })
- }
- }
- })
- })
- },
- onError(err) {
- app.aldstat.sendEvent('报错', {
- 'err': err
- });
- },
- })
|