index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. import {
  2. viceBroadcast
  3. } from '../../utils/index/callAmpe'
  4. import {
  5. receiptPrinting
  6. } from '../../utils/index/receiptPrinting'
  7. import {
  8. encryptAndSign
  9. } from '../../utils/index/getSM4'
  10. import {
  11. desensitization,
  12. getWaterDrop
  13. } from '../../utils/index/index'
  14. import {
  15. userInfoQuery,
  16. } from '../../utils/api/api'
  17. const app = getApp()
  18. Page({
  19. data: {
  20. result: '',
  21. timer: 5,
  22. // 刷身份证信息
  23. brushingCardUserIInfo: {
  24. name: '',
  25. sex: '',
  26. nation: '',
  27. birthDate: '',
  28. address: '',
  29. idNum: '',
  30. photoBase64: '',
  31. },
  32. showFaceScan: false,
  33. // 签离成功信息
  34. signOffUserInfo: {},
  35. //刷脸倒计时
  36. intervalId1: null,
  37. count: 0,
  38. remainingTime: '',
  39. printVisitorList: false,
  40. timer1: null,
  41. timer2: null,
  42. clickRetryNum: 0,
  43. isShowRetry: false,
  44. },
  45. onLoad(e) {
  46. my.hideBackHome();
  47. this.setData({
  48. result: e.result || '结果页超时',
  49. resultText: e.resultText || '请重试',
  50. timer: e.timer ? parseInt(e.timer) : 5,
  51. clickRetryNum: app.data.clickRetryNum,
  52. isShowRetry: e.isShowRetry || false,
  53. })
  54. if (e.result && e.result == '刷脸登记') {
  55. this.setData({
  56. showFaceScan: true,
  57. remainingTime: '操作时间 ' + app.globalData.snDisposition.faceTimeout + ' 秒',
  58. timer: app.globalData.snDisposition.faceTimeout
  59. })
  60. this.startCountdown()
  61. this.clickFaceScan()
  62. return
  63. }
  64. if (e.result && e.result == '1:1比对') {
  65. this.setData({
  66. showFaceScan: true,
  67. remainingTime: '操作时间 ' + app.globalData.snDisposition.oneToOneTimeout + ' 秒',
  68. timer: app.globalData.snDisposition.oneToOneTimeout
  69. })
  70. this.startCountdown()
  71. this.getFaceInfoPersonCard(app.data.brushingCardUserIInfo)
  72. return
  73. }
  74. if (e.result && e.result == '联网查询') {
  75. console.log('联网查询');
  76. this.setData({
  77. timer: app.globalData.snDisposition.connectSearchTimeout
  78. })
  79. this.userInfoQuery()
  80. return
  81. }
  82. if (e.result && e.result == '签离成功') {
  83. this.setData({
  84. signOffUserInfo: app.data.signOffMsg
  85. })
  86. return
  87. }
  88. if (e.result && e.result == '首页刷证') {
  89. this.setData({
  90. timer: 15
  91. })
  92. this.showMsg(app.data.brushingCardUserIInfo)
  93. this.data.timer1 = setTimeout(function () {
  94. // 是否人证比对
  95. if (app.globalData.snDisposition.usePersonCard) {
  96. console.log('1:1比对-首页刷证');
  97. my.reLaunch({
  98. url: '/pages/resultPage/index?result=1:1比对',
  99. })
  100. } else {
  101. this.getUserInfo(app.data.brushingCardUserIInfo)
  102. }
  103. }, 1000)
  104. return
  105. }
  106. if (e.result && e.result == '登记成功') {
  107. switch (app.globalData.riskResult) {
  108. case 1:
  109. this.setData({
  110. printVisitorList: app.globalData.snDisposition.printVisitorList
  111. })
  112. if (app.globalData.snDisposition.printVisitorList) {
  113. this.printFun(app.data.visitoMsgData)
  114. }
  115. break;
  116. case 2:
  117. this.setData({
  118. result: '逃犯',
  119. })
  120. break;
  121. case 3:
  122. this.setData({
  123. result: '有前科',
  124. })
  125. break;
  126. default:
  127. break;
  128. }
  129. return
  130. }
  131. },
  132. // 倒计时
  133. startCountdown() {
  134. let that = this
  135. let {
  136. count
  137. } = that.data
  138. count = that.data.timer
  139. if (count) {
  140. if (that.data.intervalId1) {
  141. clearInterval(that.data.intervalId1);
  142. }
  143. that.data.intervalId1 = setInterval(() => {
  144. count--
  145. let remainingTime = '操作时间 ' + count + ' 秒'
  146. that.setData({
  147. remainingTime
  148. })
  149. if (count <= 0) {
  150. // 倒计时结束,清除定时器
  151. clearInterval(that.data.intervalId1)
  152. my.reLaunch({
  153. url: '/pages/home/index',
  154. })
  155. }
  156. }, 1000) // 每秒更新一次倒计时数字
  157. }
  158. },
  159. clickAudio() {
  160. getWaterDrop()
  161. },
  162. // 刷脸登记
  163. clickFaceScan() {
  164. let params1 = {
  165. "action": "getFaceInfo",
  166. "event": "open",
  167. "taskId": "2"
  168. }
  169. my.showLoading();
  170. try {
  171. my.call("ampeHHCommunication", params1, res => {
  172. console.log(res.data);
  173. // 倒计时结束1004 点击关闭1003 没认出来1001
  174. my.hideLoading()
  175. this.data.showFaceScan = false
  176. clearInterval(this.data.intervalId1);
  177. if (res.success && res.data.idNum) {
  178. let form = {
  179. xm: res.data.name,
  180. sfzh: res.data.idNum,
  181. phone: res.data.mobile,
  182. avatar: res.data.photoBase64,
  183. }
  184. app.data.userInfo = form
  185. viceBroadcast(app.globalData.snDisposition.successVoice)
  186. let isOpneTips = my.getStorageSync({
  187. key: 'isOpneTips'
  188. }).data;
  189. // 是否跳转到提示页
  190. if (isOpneTips) {
  191. my.reLaunch({
  192. url: '/pages/tipsPage/index'
  193. })
  194. } else {
  195. my.reLaunch({
  196. url: '/pages/interviewee/index'
  197. })
  198. }
  199. } else {
  200. if (!res.data || !res.data.originFaceInfo) {
  201. my.reLaunch({
  202. url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout,
  203. })
  204. return
  205. }
  206. let originFaceInfo = JSON.parse(res.data.originFaceInfo)
  207. console.log(originFaceInfo.code);
  208. // 1003关闭,1004超时
  209. if (originFaceInfo.code == '1003' || originFaceInfo.code == '1004') {
  210. my.reLaunch({
  211. url: '/pages/home/index',
  212. })
  213. } else {
  214. // 启用无证登记和刷脸失败跳转手输,跳转输入身份证页面
  215. if (app.globalData.snDisposition.faceFailHandInput && app.globalData.snDisposition.noIdcardRegister) {
  216. my.reLaunch({
  217. url: '/pages/inputIDCard/index',
  218. })
  219. } else {
  220. viceBroadcast(app.globalData.snDisposition.failVoice)
  221. my.reLaunch({
  222. url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout,
  223. })
  224. }
  225. }
  226. }
  227. });
  228. } catch (error) {
  229. my.hideLoading()
  230. clearInterval(this.data.intervalId1)
  231. my.reLaunch({
  232. url: '/pages/home/index',
  233. })
  234. this.setData({
  235. showFaceScan: false
  236. })
  237. }
  238. },
  239. // 联网查询获取用户信息
  240. async userInfoQuery() {
  241. var that = this;
  242. viceBroadcast(app.globalData.snDisposition.connectSearchVoice)
  243. try {
  244. that.handleValue(app.data.userInfo.xm)
  245. } catch (error) {
  246. console.log(error);
  247. }
  248. },
  249. handleValue(val) {
  250. clearTimeout(this.data.timer2)
  251. var that = this;
  252. // console.log(val);
  253. if (val) {
  254. let form = {
  255. name: app.data.userInfo.xm,
  256. idNum: app.data.userInfo.sfzh,
  257. photoBase64: app.data.userInfo.avatar,
  258. }
  259. app.data.brushingCardUserIInfo = form
  260. console.log('1:1比对-联网查询', val);
  261. my.reLaunch({
  262. url: '/pages/resultPage/index?result=1:1比对',
  263. })
  264. } else {
  265. that.data.timer2 = setTimeout(function () {
  266. clearTimeout(that.data.timer2)
  267. // 捕获到联网查询错误,跳转到重试页面
  268. if (app.data.isNetworkQueryError == false) {
  269. let resultText = app.data.clickRetryNum == 0 ? '查询超时,可点击重试' : '查询超时~'
  270. my.reLaunch({
  271. url: '/pages/resultPage/index?result=结果页超时&timer=' + app.globalData.snDisposition.resultPageTimeout + '&resultText=' + resultText + '&isShowRetry=' + true,
  272. })
  273. } else {
  274. that.handleValue(app.data.userInfo.xm)
  275. }
  276. }, 1000)
  277. }
  278. },
  279. // 重试
  280. retryFun() {
  281. this.getRetryUserInfo()
  282. app.data.clickRetryNum = app.data.clickRetryNum + 1
  283. app.data.isNetworkQueryError = null
  284. my.reLaunch({
  285. url: '/pages/resultPage/index?result=联网查询&timer=' + app.globalData.snDisposition.connectSearchTimeout,
  286. })
  287. },
  288. // 重试-联网查询用户信息
  289. async getRetryUserInfo() {
  290. try {
  291. let appKey = app.globalData.appKey
  292. let appSecret = app.globalData.appSecret
  293. let privateKey = app.globalData.privateKey
  294. let content = {
  295. sfzh: app.data.inputIdCard
  296. }
  297. content = JSON.stringify(content)
  298. let sm4 = encryptAndSign(appKey, appSecret, privateKey, content, "encrypted")
  299. // console.log(sm4);
  300. let data = {
  301. "appId": app.globalData.appId,
  302. "bizContent": sm4.encrypted,
  303. "reqTimestamp": sm4.timestamp,
  304. "sign": sm4.sign
  305. }
  306. let res = await userInfoQuery(data)
  307. app.data.isNetworkQueryError = true
  308. // 解密
  309. let decryptedData = encryptAndSign(appKey, appSecret, privateKey, res.data.bizContent, "decrypt")
  310. if (!decryptedData.decrypted) {
  311. return
  312. }
  313. let decrypted = JSON.parse(decryptedData.decrypted)
  314. app.data.userInfo = decrypted
  315. app.data.userInfo.avatar = decrypted.xp
  316. // this.handleValue(app.data.userInfo.xm)
  317. } catch (error) {
  318. app.data.isNetworkQueryError = false
  319. // this.handleValue(app.data.userInfo.xm)
  320. }
  321. },
  322. // 身份证信息展示
  323. showMsg(data) {
  324. let brushingCardUserIInfo = JSON.parse(JSON.stringify(data))
  325. brushingCardUserIInfo.sex = brushingCardUserIInfo.sex[0]
  326. var fruits = brushingCardUserIInfo.birthDate.split(".");
  327. brushingCardUserIInfo.year = fruits[0]
  328. brushingCardUserIInfo.month = fruits[1]
  329. brushingCardUserIInfo.day = fruits[2]
  330. app.data.brushingCardUserIInfo = brushingCardUserIInfo
  331. this.setData({
  332. brushingCardUserIInfo
  333. })
  334. },
  335. // 1:1比对
  336. getFaceInfoPersonCard(form) {
  337. let params1 = {
  338. "action": "getFaceInfoPersonCard",
  339. "event": "open",
  340. "taskId": "7",
  341. "params": {
  342. "certName": form.name,
  343. "certNo": form.idNum,
  344. "certPhotoBase64Str": form.photoBase64
  345. }
  346. }
  347. let that = this
  348. console.log(params1.params);
  349. try {
  350. my.call('ampeHHCommunication', params1, res => {
  351. clearInterval(that.data.intervalId1);
  352. // console.log(res.data);
  353. that.setData({
  354. showFaceScan: false
  355. })
  356. if (res.success) {
  357. that.getUserInfo(res.data)
  358. } else {
  359. if (!res.data || !res.data.originFaceInfo) {
  360. my.reLaunch({
  361. url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout,
  362. })
  363. return
  364. }
  365. let originFaceInfo = JSON.parse(res.data.originFaceInfo)
  366. console.log(originFaceInfo);
  367. if (originFaceInfo.code == '1001' || originFaceInfo.code == '2006') {
  368. my.reLaunch({
  369. url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout,
  370. })
  371. } else {
  372. my.reLaunch({
  373. url: '/pages/home/index',
  374. })
  375. my.showToast({
  376. content: (originFaceInfo && originFaceInfo.subMessage) ? originFaceInfo.subMessage : '请重试',
  377. duration: 2000
  378. });
  379. }
  380. }
  381. });
  382. } catch (error) {
  383. clearInterval(that.data.intervalId1);
  384. my.reLaunch({
  385. url: '/pages/home/index',
  386. })
  387. that.setData({
  388. showFaceScan: false
  389. })
  390. }
  391. },
  392. // 用户信息赋值
  393. getUserInfo(data) {
  394. app.data.userInfo.avatar = data.photoBase64 || ''
  395. app.data.userInfo.xm = data.name
  396. app.data.userInfo.sfzh = data.idNum
  397. my.reLaunch({
  398. url: '/pages/interviewee/index',
  399. })
  400. },
  401. // 打印小票
  402. printFun(form) {
  403. if (form.name) {
  404. form.name = desensitization(form.name, 1, 2)
  405. }
  406. if (form.phone) {
  407. form.phone = desensitization(form.phone, 3, 7)
  408. }
  409. let data = receiptPrinting(form)
  410. if (app.data.visitoMsgData.commonQrCode) {
  411. data.printList.push({
  412. "text": " " + app.globalData.snDisposition.generalQrcodeTitle,
  413. "textSize": 25,
  414. "bold": false,
  415. "algin": "center"
  416. }, {
  417. "width": 376,
  418. "height": 376,
  419. "qrCodeText": app.data.visitoMsgData.commonQrCode
  420. })
  421. }
  422. if (app.globalData.snDisposition.ethQrcode && app.data.visitoMsgData.ladderQrCode) {
  423. data.printList.push({
  424. "text": " " + app.globalData.snDisposition.ethQrcodeTitle,
  425. "textSize": 25,
  426. "bold": false,
  427. "algin": "center"
  428. }, {
  429. "width": 376,
  430. "height": 376,
  431. "qrCodeText": app.data.visitoMsgData.ladderQrCode
  432. })
  433. }
  434. let params = {
  435. "action": "receiptPrinting",
  436. "event": "open",
  437. "taskId": "10",
  438. "params": data
  439. }
  440. console.log(params);
  441. try {
  442. my.call('ampeHHCommunication', params, res => {
  443. console.log(res);
  444. if (!res.success) {
  445. my.showToast({
  446. content: res.message ? res.message : '打印失败,请重试',
  447. duration: 2000
  448. });
  449. }
  450. })
  451. } catch (error) {
  452. my.showToast({
  453. content: res.message ? res.message : '打印失败,请重试',
  454. duration: 2000
  455. });
  456. }
  457. },
  458. // 倒计时结束
  459. finish() {
  460. let {
  461. result
  462. } = this.data
  463. // 操作超时
  464. if (result == '扫码签离' || result == '刷身份证' || result == '联网查询' || result == '1:1比对') {
  465. my.reLaunch({
  466. url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout,
  467. })
  468. }
  469. // 结果页自动退回首页
  470. if (result == '签离成功' || result == '签离失败' || result == '结果页超时' || result == '逃犯' || result == '有前科' || result == '登记成功') {
  471. clearInterval(this.data.intervalId1)
  472. my.reLaunch({
  473. url: '/pages/home/index',
  474. })
  475. }
  476. },
  477. sure() {
  478. clearInterval(this.data.intervalId1)
  479. my.reLaunch({
  480. url: '/pages/home/index',
  481. })
  482. },
  483. });