index.js 15 KB

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