123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- import {
- isCardID,
- getWaterDrop
- } from '../../utils/index/index'
- import {
- userInfoQuery
- } from '../../utils/api/api'
- import {
- encryptAndSign
- } from '../../utils/index/getSM4'
- import {
- viceBroadcast
- } from '../../utils/index/callAmpe'
- const app = getApp()
- Page({
- data: {
- toTitleRef: null,
- numVal: '',
- numList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 'X', 0, '退格'],
- isOk: true,
- startTimeStamp: 0,
- snDisposition: {},
- timer: null
- },
- onLoad() {
- my.hideBackHome();
- this.setData({
- snDisposition: app.globalData.snDisposition
- })
- viceBroadcast(app.globalData.snDisposition.inputIdcardVoice)
- },
- clickAudio() {
- getWaterDrop()
- },
- //操作倒计时结束
- finish(event) {
- if (event == 'finish') {
- this.backToSpecifiedPage('/pages/resultPage/index?result=结果页超时')
- }
- },
- getVal(e) {
- // console.log(new Date());
- // return
- let val = e.currentTarget.dataset.item
- let numVal = this.data.numVal
- if (this.data.numVal.length >= 18 && val != '退格') {
- return
- }
- if (!this.data.isOk) {
- this.setData({
- isOk: true,
- })
- }
- switch (val) {
- case '退格':
- this.setData({
- numVal: numVal.substr(0, numVal.length - 1)
- })
- break;
- default:
- this.setData({
- numVal: numVal + val
- });
- break;
- }
- // console.log(this.data.numVal);
- if (this.data.numVal.length == 18) {
- this.getIsOk()
- }
- },
- bindlongtap(e) {
- let val = e.currentTarget.dataset.item
- if (val == '退格') {
- this.setData({
- numVal: ''
- })
- }
- },
- getIsOk() {
- let data = isCardID(this.data.numVal)
- if (data.state) {
- this.setData({
- isOk: true,
- })
- } else {
- this.setData({
- isOk: false,
- })
- console.log(data);
- my.showToast({
- content: data.data,
- duration: 3000,
- });
- }
- },
- // 确认
- sure(e) {
- if (this.data.numVal.length != 18) {
- this.getIsOk()
- }
- if (!this.data.isOk) {
- return
- }
- let snDisposition = app.globalData.snDisposition
- app.data.inputIdCard = this.data.numVal
- // 联网查询用户信息
- this.userInfoQuery()
- // 是否开启输入手机号
- if (snDisposition.noIdcardInputPhone) {
- this.backToSpecifiedPage('/pages/inputPhone/index')
- } else {
- this.backToSpecifiedPage( '/pages/resultPage/index?result=联网查询')
- }
- },
- // 联网查询用户信息
- async userInfoQuery() {
- try {
- let appKey = app.globalData.appKey
- let appSecret = app.globalData.appSecret
- let privateKey = app.globalData.privateKey
- let content = {
- sfzh: app.data.inputIdCard
- }
- content = JSON.stringify(content)
- let sm4 = encryptAndSign(appKey, appSecret, privateKey, content, "encrypted")
- // console.log(sm4);
- let data = {
- "appId": app.globalData.appId,
- "bizContent": sm4.encrypted,
- "reqTimestamp": sm4.timestamp,
- "sign": sm4.sign
- }
- let res = await userInfoQuery(data)
- app.data.isNetworkQueryError = true
- // 解密
- let decryptedData = encryptAndSign(appKey, appSecret, privateKey, res.data.bizContent, "decrypt")
- if (!decryptedData.decrypted) {
- return
- }
- let decrypted = JSON.parse(decryptedData.decrypted)
- let brushingCardUserIInfo = {
- name: decrypted.xm,
- idNum: decrypted.sfzh,
- photoBase64: decrypted.xp,
- }
- app.data.brushingCardUserIInfo = brushingCardUserIInfo
- app.data.userInfo = decrypted
- app.data.userInfo.avatar = decrypted.xp
- } catch (error) {
- app.data.isNetworkQueryError = false
- console.log(error);
- // my.reLaunch({
- // url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout,
- // })
- }
- },
- saveRef(ref){
- // 将ref存起来,在想要调用的地方使用
- this.toTitleRef = ref
- },
- /**
- * 跳转指定页面 并清除顶部计时器
- */
- backToSpecifiedPage(url) {
- this.toTitleRef && this.toTitleRef.clearIntervalAll();
- my.reLaunch({
- url: url,
- })
- },
- });
|