index.js 15 KB

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