123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- import { userWithimage, userWithverified, userWithanonymous } from "../../utils/api/api";
- const app = getApp();
- const face = require("/utils/faceCheck/faceCheck");
- const date = require("/utils/index/index");
- import getAuthThree from '/utils/api/auth_api'
- import bus from 'iny-bus'
- Page({
- data: {
- certName1: "",
- certNo1: "",
- certName2: "",
- certNo2: "",
- image: "",
- isLoading: false,
- isLoading1: false,
- // 输入信息
- inputName: "",
- inputIdcard: "",
- phoneNumber: "",
- userId: null,
- eventId: null,
- fileList: []
- },
- upStorage() {
- let that = this
- if (!this.data.certName1 || !this.data.certNo1) {
- my.showToast({
- type: 'none',
- content: '姓名身份证必填'
- });
- return
- }
- my.showLoading({
- content: '加载中',
- })
- this.setData({
- isLoading: true
- })
- userWithimage({
- certName: this.data.certName1,
- certNo: this.data.certNo1,
- token: 'ab051195190b4623ea62f636ae747f53',
- vid: null
- }).then(() => {
- my.hideLoading()
- my.showToast({
- content: "入库成功",
- type: "success",
- duration: 1000,
- //显示透明蒙层,防止触摸穿透
- mask: true,
- success: function () {
- that.setData({
- certName1: "",
- certNo1: ""
- })
- }
- });
- }).catch(error => {
- my.hideLoading()
- }).finally(() => {
- // 无论请求成功或失败,都需要将 isLoading 设为 false
- this.setData({
- isLoading: false
- });
- my.hideLoading();
- });
- },
- upStorage2() {
- const taskId = `${date.formatTime(Date.now(), "YYYYMMDDHHNNSS")}${parseInt((Math.random() * 9 + 1) * 10000)}`
- my.setStorage({
- key: 'auth-taskId',
- data: taskId
- })
- my.navigateToMiniProgram({
- appId: app.globalData.authAppId, // 16 位
- path: 'pages/authorize_three/authorize_three',
- query: {
- name: 'HHFace出入库演示小程序',
- token: app.globalData.authAppToken,
- taskId
- },
- })
- },
- onAppShowHandler(options) {
- if (options && options.referrerInfo) {
- // 从三要素认证返回
- if (options.referrerInfo.appId === app.globalData.authAppId && options.referrerInfo.extraData) {
- const authStatus = options.referrerInfo.extraData.authStatus
- if (authStatus) {
- const authTaskId = my.getStorageSync({
- key: 'auth-taskId'
- })
- my.removeStorage({
- key: 'auth-taskId'
- })
- if (authTaskId && authTaskId.data) {
- bus.emit('appShowHandler', authTaskId.data)
- }
- } else {
- my.alert({
- title: '提示',
- content: '授权失败'
- })
- }
- }
- }
- },
- async zfbAuthCallback(authTaskId) {
- my.showLoading({
- content: "加载中..."
- })
- const result = await getAuthThree({
- taskId: authTaskId,
- token: app.globalData.authAppToken
- })
- /**
- * certNo 身份证号
- * certName 姓名
- * phone 手机号
- */
- if (result.errcode) {
- my.alert({
- title: "提示",
- content: "未查询到认证结果,请重新认证!"
- })
- return
- }
- if (!result.data || !result.data.token) {
- my.alert({
- title: "提示",
- content: result.msg
- })
- return
- }
- this.setData({
- inputName: result.data.certName,
- inputIdcard: result.data.certNo,
- phoneNumber: result.data.phone,
- userId: result.data.userId
- })
- my.setStorage({
- key: 'userInfo1',
- data: result.data
- })
- this.doZFBFaceCheck()
- my.hideLoading()
- },
- // 支付宝验证人脸
- async doZFBFaceCheck() {
- let that = this
- let {
- userId
- } = this.data;
- // let res = await face.getFace_wxrlxf("/api/user/userLogin", "post", {
- // zfbUserId: userId
- // })
- // if (res.data.token) {
- // my.setStorage({
- // key: 'token',
- // data: res.data
- // })
- // }
- that.setCertificationState()
- },
- // 设置授权状态
- setCertificationState(isSuccess) {
- // let token = my.getStorageSync({
- // key: 'token'
- // }).data
- // if (token) {
- my.alert({
- title: '提示',
- content: '授权成功',
- success() {
- my.reLaunch({
- url: '/pages/home/index',
- })
- let Info = my.getStorageSync({
- key: 'userInfo1',
- })
- userWithverified({
- certName: Info.data.certName,
- certNo: Info.data.certNo,
- token: 'ab051195190b4623ea62f636ae747f53',
- ftoken: Info.data.token
- }).then(() => {
- my.showToast({
- content: "入库成功",
- type: "success",
- duration: 1000,
- //显示透明蒙层,防止触摸穿透
- mask: true,
- success: function () {
- }
- }).catch()
- })
- }
- })
- // } else {
- // my.alert({
- // title: "提示",
- // content: "未查询到认证结果,请重新认证!"
- // })
- // }
- },
- // 匿名入库
- upStorage3() {
- let that = this
- if (!this.data.certName2 || !this.data.certNo2 || !this.data.image) {
- my.showToast({
- type: 'none',
- content: '姓名身份证照片必填'
- });
- return
- }
- my.showLoading({
- content: '加载中',
- })
- this.setData({
- isLoading1: true
- })
- userWithanonymous({
- certName: this.data.certName2,
- certNo: this.data.certNo2,
- image: this.data.image,
- token: 'ab051195190b4623ea62f636ae747f53',
- vid: null
- }).then(res => {
- my.hideLoading()
- my.showToast({
- content: "入库成功",
- type: "success",
- duration: 1000,
- //显示透明蒙层,防止触摸穿透
- mask: true,
- success: function () {
- that.setData({
- certName2: "",
- certNo2: "",
- image: '',
- fileList: []
- })
- }
- });
- }).catch(error => {
- my.hideLoading()
- }).finally(() => {
- // 无论请求成功或失败,都需要将 isLoading 设为 false
- this.setData({
- isLoading1: false
- });
- my.hideLoading();
- });
- },
- getUserName(e) {
- this.setData({
- certName1: e.detail.value
- })
- },
- getCardID(e) {
- this.setData({
- certNo1: e.detail.value
- })
- },
- getUserName2(e) {
- this.setData({
- certName2: e.detail.value
- })
- },
- getCardID2(e) {
- this.setData({
- certNo2: e.detail.value
- })
- },
- //选择照片//原生
- ChooseImage(e) {
- my.chooseImage({
- success: (res) => {
- const fs = my.getFileSystemManager();
- fs.readFile({
- // readFile 不传入 encodding 参数,则以 ArrayBuffer 方式读取
- filePath: `${res.tempFilePaths[0]}`,
- success: ({ data }) => {
- const base64 = my.arrayBufferToBase64(data);
- this.setData({
- form2: { certName: this.data.form2.certName, certNo: this.data.form2.certName.certNo, image: base64 }
- })
- },
- });
- },
- });
- },
- //组件的选择照片
- onChange(fileList) {
- if (fileList.length) {
- this.setData({ fileList: fileList })
- const fs = my.getFileSystemManager();
- fs.readFile({
- filePath: `${fileList[0].path}`,
- success: ({ data }) => {
- const base64 = my.arrayBufferToBase64(data);
- this.setData({
- image: base64,
- })
- },
- });
- }
- },
- onUpload(file) {
- return new Promise((resolve) => {
- resolve(file.path);
- });
- },
- onRemove(file) {
- return new Promise((resolve) => {
- this.setData({
- image: '',
- fileList: []
- })
- resolve(file);
- });
- },
- onLoad() {
- my.onAppShow(this.onAppShowHandler)
- this.data.eventId = bus.on('appShowHandler', (res) => {
- this.zfbAuthCallback(res)
- })
- },
- onShow() {
- const userInfo = my.getStorageSync({ key: "userInfo" });
- if (!userInfo.data) {
- my.navigateTo({
- url: '/pages/login/index',
- })
- }
- },
- onReady() {
- },
- onUnload() {
- bus.remove('appShowHandler', this.data.eventId)
- my.offAppShow(this.onAppShowHandler)
- // 页面被关闭
- },
- });
|