index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import {getWaterDrop, isCardID} from '../../utils/index/index'
  2. import {userInfoQuery} from '../../utils/api/api'
  3. import {encryptAndSign} from '../../utils/index/getSM4'
  4. import {viceBroadcast} from '../../utils/index/callAmpe'
  5. const app = getApp()
  6. Page({
  7. data: {
  8. toTitleRef: null,
  9. numVal: '',
  10. numList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 'X', 0, '退格'],
  11. isOk: true,
  12. startTimeStamp: 0,
  13. snDisposition: {},
  14. timer: null
  15. },
  16. onLoad() {
  17. my.hideBackHome();
  18. this.setData({
  19. snDisposition: app.globalData.snDisposition
  20. })
  21. viceBroadcast(app.globalData.snDisposition.inputIdcardVoice)
  22. },
  23. clickAudio() {
  24. getWaterDrop()
  25. },
  26. //操作倒计时结束
  27. finish(event) {
  28. if (event == 'finish') {
  29. this.backToSpecifiedPage('/pages/resultPage/index?result=结果页超时')
  30. }
  31. },
  32. getVal(e) {
  33. // console.log(new Date());
  34. // return
  35. let val = e.currentTarget.dataset.item
  36. let numVal = this.data.numVal
  37. if (this.data.numVal.length >= 18 && val != '退格') {
  38. return
  39. }
  40. if (!this.data.isOk) {
  41. this.setData({
  42. isOk: true,
  43. })
  44. }
  45. switch (val) {
  46. case '退格':
  47. this.setData({
  48. numVal: numVal.substr(0, numVal.length - 1)
  49. })
  50. break;
  51. default:
  52. this.setData({
  53. numVal: numVal + val
  54. });
  55. break;
  56. }
  57. // console.log(this.data.numVal);
  58. if (this.data.numVal.length == 18) {
  59. this.getIsOk()
  60. }
  61. },
  62. bindlongtap(e) {
  63. let val = e.currentTarget.dataset.item
  64. if (val == '退格') {
  65. this.setData({
  66. numVal: ''
  67. })
  68. }
  69. },
  70. getIsOk() {
  71. let data = isCardID(this.data.numVal)
  72. if (data.state) {
  73. this.setData({
  74. isOk: true,
  75. })
  76. } else {
  77. this.setData({
  78. isOk: false,
  79. })
  80. console.log(data);
  81. my.showToast({
  82. content: data.data,
  83. duration: 3000,
  84. });
  85. }
  86. },
  87. // 确认
  88. sure(e) {
  89. if (this.data.numVal.length != 18) {
  90. this.getIsOk()
  91. }
  92. if (!this.data.isOk) {
  93. return
  94. }
  95. let snDisposition = app.globalData.snDisposition
  96. app.data.inputIdCard = this.data.numVal
  97. // 联网查询用户信息
  98. this.userInfoQuery()
  99. // 是否开启输入手机号
  100. if (snDisposition.noIdcardInputPhone) {
  101. this.backToSpecifiedPage('/pages/inputPhone/index')
  102. } else {
  103. this.backToSpecifiedPage( '/pages/resultPage/index?result=联网查询')
  104. }
  105. },
  106. // 联网查询用户信息
  107. async userInfoQuery() {
  108. try {
  109. let appKey = app.globalData.appKey
  110. let appSecret = app.globalData.appSecret
  111. let privateKey = app.globalData.privateKey
  112. let content = {
  113. sfzh: app.data.inputIdCard
  114. }
  115. content = JSON.stringify(content)
  116. let sm4 = encryptAndSign(appKey, appSecret, privateKey, content, "encrypted")
  117. // console.log(sm4);
  118. let data = {
  119. "appId": app.globalData.appId,
  120. "bizContent": sm4.encrypted,
  121. "reqTimestamp": sm4.timestamp,
  122. "sign": sm4.sign
  123. }
  124. let res = await userInfoQuery(data)
  125. app.data.isNetworkQueryError = true
  126. // 解密
  127. let decryptedData = encryptAndSign(appKey, appSecret, privateKey, res.data.bizContent, "decrypt")
  128. if (!decryptedData.decrypted) {
  129. return
  130. }
  131. let decrypted = JSON.parse(decryptedData.decrypted)
  132. app.data.brushingCardUserIInfo = {
  133. name: decrypted.xm,
  134. idNum: decrypted.sfzh,
  135. photoBase64: decrypted.xp,
  136. }
  137. app.data.userInfo = decrypted
  138. app.data.userInfo.avatar = decrypted.xp
  139. app.data.userInfo.idCardPhoto = decrypted.xp
  140. } catch (error) {
  141. app.data.isNetworkQueryError = false
  142. console.log(error);
  143. // my.reLaunch({
  144. // url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout,
  145. // })
  146. }
  147. },
  148. saveRef(ref){
  149. // 将ref存起来,在想要调用的地方使用
  150. this.toTitleRef = ref
  151. },
  152. /**
  153. * 跳转指定页面 并清除顶部计时器
  154. */
  155. backToSpecifiedPage(url) {
  156. this.toTitleRef && this.toTitleRef.clearIntervalAll();
  157. my.reLaunch({
  158. url: url,
  159. })
  160. },
  161. });