index.js 15 KB

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