index.js 4.2 KB

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