weapps-plugin-jingtong-verify 1.3.9 → 1.4.1-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +2 -1
  2. package/app.json +33 -33
  3. package/package.json +20 -20
  4. package/sdk.js +289 -289
  5. package/weapps-plugin-jingtong-verify/components/card-modal/card-modal.js +31 -31
  6. package/weapps-plugin-jingtong-verify/components/card-modal/card-modal.json +3 -3
  7. package/weapps-plugin-jingtong-verify/components/card-modal/card-modal.wxml +9 -9
  8. package/weapps-plugin-jingtong-verify/components/card-modal/card-modal.wxss +65 -65
  9. package/weapps-plugin-jingtong-verify/components/face-error-modal/face-error-modal.js +37 -37
  10. package/weapps-plugin-jingtong-verify/components/face-error-modal/face-error-modal.json +3 -3
  11. package/weapps-plugin-jingtong-verify/components/face-error-modal/face-error-modal.wxml +30 -30
  12. package/weapps-plugin-jingtong-verify/components/face-error-modal/face-error-modal.wxss +79 -79
  13. package/weapps-plugin-jingtong-verify/components/face-modal/face-modal.js +32 -32
  14. package/weapps-plugin-jingtong-verify/components/face-modal/face-modal.json +3 -3
  15. package/weapps-plugin-jingtong-verify/components/face-modal/face-modal.wxml +16 -16
  16. package/weapps-plugin-jingtong-verify/components/face-modal/face-modal.wxss +57 -57
  17. package/weapps-plugin-jingtong-verify/components/gsd-lib/anim/anim.min.js +1 -1
  18. package/weapps-plugin-jingtong-verify/components/gsd-lib/crypto/crypto.js +37 -37
  19. package/weapps-plugin-jingtong-verify/components/gsd-lib/crypto/index.js +44 -44
  20. package/weapps-plugin-jingtong-verify/components/gsd-lib/dayjs/index.js +351 -351
  21. package/weapps-plugin-jingtong-verify/components/gsd-lib/event/index.js +117 -117
  22. package/weapps-plugin-jingtong-verify/components/gsd-lib/index.js +63 -63
  23. package/weapps-plugin-jingtong-verify/components/gsd-lib/map/index.js +10 -10
  24. package/weapps-plugin-jingtong-verify/components/gsd-lib/map/qmap.js +6 -6
  25. package/weapps-plugin-jingtong-verify/components/gsd-lib/storage/index.js +114 -114
  26. package/weapps-plugin-jingtong-verify/components/gsd-lib/utils/index.js +218 -218
  27. package/weapps-plugin-jingtong-verify/components/gsd-ui/behaviors/formCheck.js +72 -72
  28. package/weapps-plugin-jingtong-verify/components/gsd-ui/behaviors/formController.js +47 -47
  29. package/weapps-plugin-jingtong-verify/components/gsd-ui/behaviors/icon.js +11 -11
  30. package/weapps-plugin-jingtong-verify/components/gsd-ui/behaviors/list.js +16 -16
  31. package/weapps-plugin-jingtong-verify/components/gsd-ui/behaviors/navigator.js +33 -33
  32. package/weapps-plugin-jingtong-verify/components/gsd-ui/behaviors/primarySecondButton.js +18 -18
  33. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-agree/index.js +12 -12
  34. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-agree/index.json +5 -5
  35. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-agree/index.wxml +15 -15
  36. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-badge/index.js +47 -0
  37. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-badge/index.json +4 -0
  38. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-badge/index.wxml +13 -0
  39. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-badge/index.wxss +1 -0
  40. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-button-group/index.js +44 -44
  41. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-button-group/index.json +5 -5
  42. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-button-group/index.wxml +28 -28
  43. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-cell/index.js +30 -0
  44. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-cell/index.json +7 -0
  45. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-cell/index.wxml +42 -0
  46. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-cell/index.wxss +1 -0
  47. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-date-picker-en/index.js +418 -414
  48. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-date-picker-en/index.json +5 -5
  49. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-date-picker-en/index.wxml +29 -29
  50. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-dropdown/index.js +11 -11
  51. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-dropdown/index.json +3 -3
  52. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-dropdown/index.wxml +4 -4
  53. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-form/index.js +179 -179
  54. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-form/index.json +6 -6
  55. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-form/index.wxml +16 -16
  56. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-form-cell/index.js +92 -92
  57. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-form-cell/index.json +6 -6
  58. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-form-cell/index.wxml +12 -12
  59. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-form-cell/index.wxss +2 -2
  60. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-form-item/index.js +49 -48
  61. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-form-item/index.json +3 -3
  62. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-form-item/index.wxml +14 -13
  63. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-icon/index.js +33 -33
  64. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-icon/index.json +3 -3
  65. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-icon/index.wxml +2 -2
  66. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-index-list/index.js +108 -108
  67. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-index-list/index.json +6 -6
  68. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-index-list/index.wxml +53 -53
  69. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-input/index.js +237 -233
  70. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-input/index.json +8 -8
  71. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-input/index.wxml +49 -49
  72. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-picker/index.js +328 -324
  73. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-picker/index.json +6 -6
  74. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-picker/index.wxml +26 -26
  75. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-popover/index.js +159 -159
  76. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-popover/index.json +3 -3
  77. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-popover/index.wxml +10 -10
  78. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-search/index.js +112 -112
  79. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-search/index.json +5 -5
  80. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-search/index.wxml +21 -21
  81. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-switch/index.js +21 -0
  82. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-switch/index.json +7 -0
  83. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-switch/index.wxml +16 -0
  84. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-switch/index.wxss +1 -0
  85. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-tips/index.js +50 -50
  86. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-tips/index.json +5 -5
  87. package/weapps-plugin-jingtong-verify/components/gsd-ui/g-tips/index.wxml +27 -27
  88. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/image/add.svg +13 -13
  89. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/image/arrow.svg +14 -14
  90. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/image/delete.svg +16 -16
  91. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/image/preview.svg +21 -21
  92. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/image/user.svg +13 -13
  93. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-agree.wxss +147 -147
  94. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-badge.wxss +41 -0
  95. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-button-group.wxss +244 -244
  96. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-cell.wxss +220 -0
  97. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-dropdown.wxss +115 -115
  98. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-form-cell.wxss +101 -101
  99. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-form-item.wxss +174 -167
  100. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-form.wxss +101 -101
  101. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-icon.wxss +268 -268
  102. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-index-list.wxss +206 -206
  103. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-input.wxss +206 -206
  104. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-picker.wxss +139 -139
  105. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-popover.wxss +129 -129
  106. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-search.wxss +171 -171
  107. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-switch.wxss +176 -0
  108. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/components/g-tips.wxss +173 -173
  109. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/icon/iconfont.wxss +160 -160
  110. package/weapps-plugin-jingtong-verify/components/gsd-ui/static/style/main.wxss +283 -283
  111. package/weapps-plugin-jingtong-verify/components/gsd-ui/utils/helper.js +55 -55
  112. package/weapps-plugin-jingtong-verify/components/gsd-ui/utils/validType.js +117 -117
  113. package/weapps-plugin-jingtong-verify/components/gsd-ui/utils/validator.js +106 -106
  114. package/weapps-plugin-jingtong-verify/components/lock-face-modal/lock-face-modal.js +32 -32
  115. package/weapps-plugin-jingtong-verify/components/lock-face-modal/lock-face-modal.json +3 -3
  116. package/weapps-plugin-jingtong-verify/components/lock-face-modal/lock-face-modal.wxml +8 -8
  117. package/weapps-plugin-jingtong-verify/components/lock-face-modal/lock-face-modal.wxss +57 -57
  118. package/weapps-plugin-jingtong-verify/components/modal/modal.js +32 -32
  119. package/weapps-plugin-jingtong-verify/components/modal/modal.json +3 -3
  120. package/weapps-plugin-jingtong-verify/components/modal/modal.wxml +28 -28
  121. package/weapps-plugin-jingtong-verify/components/modal/modal.wxss +84 -84
  122. package/weapps-plugin-jingtong-verify/components/my-modal/my-modal.js +82 -82
  123. package/weapps-plugin-jingtong-verify/components/my-modal/my-modal.json +3 -3
  124. package/weapps-plugin-jingtong-verify/components/my-modal/my-modal.wxml +18 -18
  125. package/weapps-plugin-jingtong-verify/components/my-modal/my-modal.wxss +72 -71
  126. package/weapps-plugin-jingtong-verify/components/tip-modal/tip-modal.js +39 -35
  127. package/weapps-plugin-jingtong-verify/components/tip-modal/tip-modal.json +3 -3
  128. package/weapps-plugin-jingtong-verify/components/tip-modal/tip-modal.wxml +9 -9
  129. package/weapps-plugin-jingtong-verify/components/tip-modal/tip-modal.wxss +51 -51
  130. package/weapps-plugin-jingtong-verify/i18n/index.js +7 -7
  131. package/weapps-plugin-jingtong-verify/i18n/logout.js +10 -10
  132. package/weapps-plugin-jingtong-verify/i18n/rules.js +202 -189
  133. package/weapps-plugin-jingtong-verify/images/close-circle.png +0 -0
  134. package/weapps-plugin-jingtong-verify/pages/bind-phone/bind-phone.js +86 -86
  135. package/weapps-plugin-jingtong-verify/pages/bind-phone/bind-phone.json +6 -6
  136. package/weapps-plugin-jingtong-verify/pages/bind-phone/bind-phone.wxml +20 -17
  137. package/weapps-plugin-jingtong-verify/pages/bind-phone/bind-phone.wxss +51 -38
  138. package/weapps-plugin-jingtong-verify/pages/confirm-phone/confirm-phone.js +167 -167
  139. package/weapps-plugin-jingtong-verify/pages/confirm-phone/confirm-phone.json +3 -3
  140. package/weapps-plugin-jingtong-verify/pages/confirm-phone/confirm-phone.wxml +30 -30
  141. package/weapps-plugin-jingtong-verify/pages/confirm-phone/confirm-phone.wxss +91 -91
  142. package/weapps-plugin-jingtong-verify/pages/face-error-reason/face-error-reason.js +79 -79
  143. package/weapps-plugin-jingtong-verify/pages/face-error-reason/face-error-reason.json +5 -5
  144. package/weapps-plugin-jingtong-verify/pages/face-error-reason/face-error-reason.wxml +19 -19
  145. package/weapps-plugin-jingtong-verify/pages/face-error-reason/face-error-reason.wxss +44 -44
  146. package/weapps-plugin-jingtong-verify/pages/face-verify/face-verify.js +1382 -1286
  147. package/weapps-plugin-jingtong-verify/pages/face-verify/face-verify.json +16 -15
  148. package/weapps-plugin-jingtong-verify/pages/face-verify/face-verify.wxml +494 -410
  149. package/weapps-plugin-jingtong-verify/pages/face-verify/face-verify.wxss +116 -76
  150. package/weapps-plugin-jingtong-verify/pages/log-off/log-off.js +127 -126
  151. package/weapps-plugin-jingtong-verify/pages/log-off/log-off.json +5 -5
  152. package/weapps-plugin-jingtong-verify/pages/log-off/log-off.wxml +36 -36
  153. package/weapps-plugin-jingtong-verify/pages/log-off/log-off.wxss +60 -60
  154. package/weapps-plugin-jingtong-verify/pages/login-manage/login-manage.js +106 -106
  155. package/weapps-plugin-jingtong-verify/pages/login-manage/login-manage.json +3 -3
  156. package/weapps-plugin-jingtong-verify/pages/login-manage/login-manage.wxml +29 -29
  157. package/weapps-plugin-jingtong-verify/pages/login-manage/login-manage.wxss +68 -68
  158. package/weapps-plugin-jingtong-verify/pages/logoff-success/logoff-success.js +24 -24
  159. package/weapps-plugin-jingtong-verify/pages/logoff-success/logoff-success.json +3 -3
  160. package/weapps-plugin-jingtong-verify/pages/logoff-success/logoff-success.wxml +12 -12
  161. package/weapps-plugin-jingtong-verify/pages/logoff-success/logoff-success.wxss +33 -33
  162. package/weapps-plugin-jingtong-verify/pages/nation-list/nation-list.js +110 -97
  163. package/weapps-plugin-jingtong-verify/pages/nation-list/nation-list.json +6 -6
  164. package/weapps-plugin-jingtong-verify/pages/nation-list/nation-list.wxml +9 -9
  165. package/weapps-plugin-jingtong-verify/pages/nation-list/nation-list.wxss +1 -1
  166. package/weapps-plugin-jingtong-verify/pages/passport-verify/passport-verify.js +641 -641
  167. package/weapps-plugin-jingtong-verify/pages/passport-verify/passport-verify.json +10 -10
  168. package/weapps-plugin-jingtong-verify/pages/passport-verify/passport-verify.wxml +152 -152
  169. package/weapps-plugin-jingtong-verify/pages/passport-verify/passport-verify.wxss +47 -47
  170. package/weapps-plugin-jingtong-verify/pages/setting/setting.js +328 -328
  171. package/weapps-plugin-jingtong-verify/pages/setting/setting.json +5 -5
  172. package/weapps-plugin-jingtong-verify/pages/setting/setting.wxml +91 -91
  173. package/weapps-plugin-jingtong-verify/pages/setting/setting.wxss +69 -69
  174. package/weapps-plugin-jingtong-verify/pages/user-info/user-info.js +306 -159
  175. package/weapps-plugin-jingtong-verify/pages/user-info/user-info.json +7 -6
  176. package/weapps-plugin-jingtong-verify/pages/user-info/user-info.wxml +142 -61
  177. package/weapps-plugin-jingtong-verify/pages/user-info/user-info.wxss +110 -64
  178. package/weapps-plugin-jingtong-verify/style/page.wxss +13 -13
  179. package/weapps-plugin-jingtong-verify/utils/QDTrackerNew/QDTracker.js +15 -15
  180. package/weapps-plugin-jingtong-verify/utils/QDTrackerNew/QDTrackerMain.js +59 -59
  181. package/weapps-plugin-jingtong-verify/utils/country.js +209 -203
  182. package/weapps-plugin-jingtong-verify/utils/index.js +306 -306
  183. package/weapps-plugin-jingtong-verify/utils/jsencrypt.min.js +1 -1
  184. package/weapps-plugin-jingtong-verify/utils/request.js +89 -24
  185. package/weapps-plugin-jingtong-verify/utils/rules.js +258 -162
  186. package/weapps-plugin-jingtong-verify/utils/tifadmin_config.js +61 -61
  187. package/weapps-plugin-jingtong-verify/utils/validate.js +772 -754
@@ -1,1287 +1,1383 @@
1
- // weapps-plugin-jingtong-verify/pages/face-verify/index.js
2
- const jingtongVerifyRequest = require('../../utils/request')
3
- const utils = require("../../utils/index")
4
- const { flow } = require("@wecity/weda-plugin-utils");
5
- const rulesConfig = require("../../utils/rules")
6
- import { SDKTrack, setAccountInfo } from '../../utils/QDTrackerNew/QDTrackerMain'
7
- let cidType = '111'
8
-
9
- Page({
10
- /**
11
- * 页面的初始数据
12
- */
13
- data: {
14
- language: 'zh_CN', // 语言环境:默认中文
15
- formData: {
16
- cid_type: '111', // 证件类型
17
- strName: '', // 身份证姓名(脱敏)
18
- name: '',
19
- strCid: '', // 身份证号码(脱敏)
20
- id_card_number: '', // 证件号码
21
- strBankCount: '', // 银行卡卡号(脱敏)
22
- bank_account: '',
23
- nation: 'CHN', // 国籍
24
- nation_name: '中国',
25
- sur_name: '', // 姓
26
- first_name: '', //
27
- sex: '', // 性别
28
- birthday: '', // 出生日期
29
- cid_expire_date: '', // 护照有效期
30
- validity_period: '', // 证件生效日期
31
- passport_number: '', // 通行证号码
32
- phone: '',
33
- verify_expire_time: '', // 登录有效期
34
- agree: false,
35
- isbind: 1
36
- },
37
- needUnite: '', // 是否需要串联起来
38
- agreeInfo: '我同意北京市大数据中心使用我所提交的信息注册京通小程序,以及登录北京市统一身份认证平台,以便使用京通相关服务。',
39
- cidTypeRange: [
40
- // 微信人脸识别
41
- { name: '中华人民共和国居民身份证', value: '111' },
42
- // 移民局接口
43
- { name: '港澳居民来往内地通行证', value: '516' },
44
- { name: '台湾居民来往大陆通行证', value: '511' },
45
- { name: '外国人永久居留身份证', value: '553' },
46
- { name: '华侨护照(国内签发)', value: '414' },
47
- // 银行卡接口
48
- { name: '港澳居民居住证', value: '17' },
49
- { name: '台湾居民居住证', value: '18' },
50
- // 外国护照
51
- { name: 'International passport', value: '700' }
52
- ],
53
- sexRange: [
54
- { name: 'Male', value: 1 },
55
- { name: 'Female', value: 2 }
56
- ],
57
- loginTimeRangeEn: [
58
- { name: 'Keep me logged in for 1 day', value: 24 },
59
- { name: 'Keep me logged in for 7 days', value: 168 },
60
- { name: 'Keep me logged in for 30 days', value: 720 }
61
- ],
62
- loginTimeRange: [
63
- { name: '1天免登录', value: 24 },
64
- { name: '7天免登录', value: 168 },
65
- { name: '30天免登录', value: 720 }
66
- ],
67
- validateType: {
68
- id_card_number(value) {
69
- return utils.validate.checkCid(value, cidType).data
70
- },
71
- name(value) {
72
- return utils.validate.checkName(value, cidType).data
73
- },
74
- sur_name(value) {
75
- return utils.validate.checkName(value, cidType).data
76
- },
77
- first_name(value) {
78
- return utils.validate.checkName(value, cidType).data
79
- },
80
- passport_number(value) {
81
- return utils.validate.checkHmtPassport(value, cidType).data
82
- },
83
- },
84
- rulesMap: {
85
- '111': {
86
- currentAuthType: 'wxFace',
87
- rules: rulesConfig.chinaRules('zh_CN')
88
- },
89
- '516': {
90
- currentAuthType: 'faceReceptionAuth',
91
- rules: rulesConfig.yiMinJuRules('zh_CN')
92
- },
93
- '511': {
94
- currentAuthType: 'faceReceptionAuth',
95
- rules: rulesConfig.yiMinJuRules('zh_CN')
96
- },
97
- '553': {
98
- currentAuthType: 'faceReceptionAuth',
99
- rules: rulesConfig.yiMinJuRules('zh_CN')
100
- },
101
- '414': {
102
- currentAuthType: 'faceReceptionAuth',
103
- rules: rulesConfig.yiMinJuRules('zh_CN')
104
- },
105
- '17': {
106
- currentAuthType: 'faceReceptionAuth',
107
- // rules: rulesConfig.cardRules('zh_CN'),
108
- rules: rulesConfig.residenceAuthRules('zh_CN'),
109
- tip: '请填写本人在办理银联银行卡时登记的姓名、港澳居民居住证证件号、手机号、银行卡号。'
110
- },
111
- '18': {
112
- currentAuthType: 'faceReceptionAuth',
113
- // rules: rulesConfig.cardRules('zh_CN'),
114
- rules: rulesConfig.residenceAuthRules('zh_CN'),
115
- tip: '请填写本人在办理银联银行卡时登记的姓名、台湾居民居住证证件号、手机号、银行卡号。'
116
- },
117
- '700': {
118
- currentAuthType: 'ForeignPassortAuth',
119
- rules: rulesConfig.ForeignPassortRules('en')
120
- }
121
- },
122
- rules: rulesConfig.chinaRules('zh_CN'),
123
- // 核验类别
124
- currentAuthType: 'wxFace',
125
- // 打开文档的防抖操作
126
- canOpenPdf: true,
127
- // 外国人护照核验状态 '1'(通过) '4'(审核中) ''(无审核单) 其它值(审核失败)
128
- passportAuthStatus: '',
129
- passportAuthPersonCode: '',
130
- // 核验单数据
131
- passportOldData: {},
132
- // 弹窗
133
- showModal: false,
134
- modalStatus: 'info',
135
- // 定义日期边界值
136
- birthdayMaxDate: [new Date().getFullYear(), (new Date().getMonth() + 1), new Date().getDate()],
137
- cidExpireMinDate: [new Date().getFullYear(), (new Date().getMonth() + 1), new Date().getDate()],
138
- // 老/小6次、成人3次 人脸报错提示弹窗
139
- showFaceModal: false,
140
- isKidsOrOld: false,
141
- // 老/小18次、成人6次 人脸报错提示弹窗
142
- showLockFaceModal: false,
143
- // 银行卡认证弹窗
144
- showCardModal: false,
145
- // 姓名和证件号码弹窗
146
- showTipModal: false,
147
- // cidType转化为certType
148
- certTypeMap: {
149
- '111': 1,
150
- '516': 78,
151
- '511': 4,
152
- '17': 5,
153
- '18': 6,
154
- '414': 2,
155
- '553': 9,
156
- '700': 3
157
- },
158
- // 记录是否已经登录成功
159
- hadSuccessLogin: false,
160
- // 该操作会触发小程序的销毁回调
161
- exitedState: true,
162
- // 扫脸失败温馨提示弹窗
163
- faceErrorModal: false,
164
- // 扫脸失败原因
165
- faceErrorType: '2'
166
- },
167
-
168
- /**
169
- * 生命周期函数--监听页面加载
170
- */
171
- onLoad(options) {
172
- console.log('onLoad', options)
173
- this.setData({
174
- needUnite: options.needUnite || 'true'
175
- })
176
-
177
- // 初始化操作,回填证件类型为身份证的身份信息
178
- this.initUserInfo()
179
- },
180
-
181
- // 初始化操作,回填证件类型为身份证的身份信息
182
- initUserInfo() {
183
- // 默认身份证号码
184
- cidType = '111'
185
-
186
- wx.showLoading({
187
- title: '加载中…',
188
- })
189
- // 清空本地Temp数据
190
- wx.setStorageSync('tif.formDataTemp', '')
191
-
192
- jingtongVerifyRequest.getSession({
193
- success: res => {
194
- let { cid_type, cid, name, star_name, star_cid, verify_expire_time } = res
195
-
196
- // 设置用户账号信息
197
- setAccountInfo(res.openid)
198
-
199
- if (cid_type === '111' && cid && name) {
200
- // 回填身份证类型
201
- this.setData({
202
- 'formData.strName': star_name,
203
- 'formData.name': name,
204
- 'formData.strCid': star_cid,
205
- 'formData.id_card_number': cid,
206
- 'formData.cid_type': cid_type,
207
- 'formData.verify_expire_time': verify_expire_time || ''
208
- })
209
- }
210
- wx.hideLoading()
211
- },
212
- fail: fail => {
213
- console.log('getSession-fail', fail)
214
- wx.hideLoading()
215
- }
216
- })
217
- },
218
-
219
- // 生命周期函数--监听页面显示
220
- onShow: function () {
221
- wx.hideShareMenu()
222
-
223
- // 获取国籍
224
- let pages = getCurrentPages()
225
- let currentPage = pages[pages.length - 1]
226
- let hadChoseNation = currentPage.data.hadChoseNation || false
227
-
228
- if (hadChoseNation) {
229
- let cid_type = currentPage.data.formData.cid_type
230
- // 回传数据
231
- this.reFullFormDataTemp(cid_type)
232
- }
233
- },
234
-
235
- // 年龄≤18岁或年龄≥60岁的用户
236
- isCarePeople(age) {
237
- return age <= 18 || age >= 60
238
- },
239
-
240
- /**
241
- * 获取/设置人脸失败次数
242
- * @param {*} count
243
- * count:true 设置次数+1
244
- * count:false 获取次数
245
- */
246
- fetchFaceFailCount(count, errCode) {
247
- const { id_card_number: cid } = this.data.formData
248
- const age = utils.parseIDCard(cid).age
249
- const isKidsOrOld = this.isCarePeople(age) || false
250
- console.log('获取/设置人脸失败', count)
251
- console.log('年龄', age)
252
- console.log('是否是老人/小孩', isKidsOrOld)
253
-
254
- this.setData({
255
- isKidsOrOld
256
- })
257
-
258
- return new Promise((resolve, reject) => {
259
- jingtongVerifyRequest.operateFaceFailCount({
260
- count,
261
- cid,
262
- age
263
- }).then(res => {
264
- console.log('获取人脸失败次数res', res)
265
- const times = Number(res.times) || 0
266
-
267
- // 老人/小孩:累计刷脸失败6次后,弹长窗提示
268
- if (count && isKidsOrOld && times === 6) {
269
- console.log('==============老人/小孩 -- 累计刷脸失败6次:弹长窗===============')
270
- this.setData({
271
- showFaceModal: true
272
- })
273
- }
274
-
275
- // 成人:累计刷脸失败3次后,弹长窗提示
276
- if (count && !isKidsOrOld && times === 3) {
277
- console.log('==============成人 -- 累计刷脸失败3次:弹长窗===============')
278
- this.setData({
279
- showFaceModal: true
280
- })
281
- }
282
-
283
- // 老/小18次、成人6次 锁定人脸
284
- if (isKidsOrOld && times >= 18) {
285
- console.log('==============老人/小孩 -- 累计刷脸失败18次:弹短窗===============')
286
- wx.hideLoading()
287
- this.setData({
288
- showLockFaceModal: true
289
- })
290
- // 人脸识别异常温馨提示弹窗
291
- count && this.handleFaceError(errCode)
292
- return
293
- } else if (!isKidsOrOld && times >= 6) {
294
- console.log('==============成人 -- 累计刷脸失败6次:弹短窗===============')
295
- wx.hideLoading()
296
- this.setData({
297
- showLockFaceModal: true
298
- })
299
- // 人脸识别异常温馨提示弹窗
300
- count && this.handleFaceError(errCode)
301
- return
302
- }
303
- resolve()
304
- }).catch(err => {
305
- console.log(err, '获取人脸失败次数err')
306
- wx.showToast({
307
- title: '初始化有误,请稍后再试',
308
- icon: 'none'
309
- })
310
- reject()
311
- })
312
- })
313
- },
314
-
315
- // 判断是否是PC端登录
316
- getDevice() {
317
- return new Promise((resolve, reject) => {
318
- const systemInfo = wx.getDeviceInfo();
319
- console.log('systemInfo', systemInfo)
320
- if (['windows', 'mac'].includes(systemInfo.platform)) {
321
- console.log('当前为电脑端微信');
322
- wx.showToast({
323
- title: '请您使用移动端京通小程序',
324
- icon: 'none',
325
- duration: 3000
326
- })
327
- return
328
- } else {
329
- console.log('当前为手机端');
330
- resolve()
331
- }
332
- })
333
- },
334
-
335
- // 根据证件类型匹配校验正则和校验类型
336
- toMatchRules() {
337
- let { cid_type, nation, nation_name } = this.data.formData
338
- let { rules, currentAuthType } = this.data.rulesMap[cid_type]
339
- console.log('核验源', currentAuthType)
340
- // 默认【中国】
341
- if (cid_type === '516' || cid_type === '511' || cid_type === '414') {
342
- nation = 'CHN'
343
- nation_name = 'CHN-中国'
344
- }
345
- this.setData({
346
- rules,
347
- currentAuthType,
348
- 'formData.nation': nation,
349
- 'formData.nation_name': nation_name,
350
- }, () => {
351
- wx.hideLoading()
352
- })
353
- console.log('匹配到的正则', rules, currentAuthType)
354
- },
355
-
356
- // 选择完国籍或认证失败后回传 -- 回传本地临时存储用户表单信息
357
- reFullFormDataTemp(cid_type) {
358
- const formDataTemp = wx.getStorageSync('tif.formDataTemp') || {}
359
- let formDataOld = this.data.formData
360
-
361
- if (formDataTemp && formDataTemp[cid_type]) {
362
- console.log('存在可回填的temp数据', formDataTemp[cid_type])
363
- let formData = Object.assign(formDataOld, formDataTemp[cid_type])
364
- this.setData({
365
- formData
366
- })
367
- }
368
- },
369
-
370
- // 同意协议和隐私政策
371
- viewPrivacy(e) {
372
- // 临时存储表单数据
373
- this.saveFormDataTemp()
374
- // 错误触发销毁回调函数处理
375
- this.handleExitedState()
376
-
377
- let canOpenPdf = this.data.canOpenPdf
378
- if (canOpenPdf) {
379
- this.setData({
380
- canOpenPdf: false
381
- })
382
- let { name, file } = e.currentTarget.dataset
383
- console.log('文件地址', `https://js.jt.beijing.gov.cn/jt/tiffile/${file}.pdf`)
384
- utils.openDoc({
385
- url: `https://js.jt.beijing.gov.cn/jt/tiffile/${file}.pdf`,
386
- fileType: 'pdf',
387
- name,
388
- successFn: () => {
389
- console.log('文档打开成功回调')
390
- setTimeout(() => {
391
- this.setData({
392
- canOpenPdf: true
393
- })
394
- }, 500)
395
- }
396
- })
397
- } else {
398
- setTimeout(() => {
399
- this.setData({
400
- canOpenPdf: true
401
- })
402
- }, 3500)
403
- }
404
- },
405
-
406
- // 选择事件
407
- handleChange(e) {
408
- let value = e.detail.value
409
- let formId = e.target.id
410
-
411
- // 删除前后空格
412
- if (typeof value === 'string' && formId !== 'cid_type') {
413
- value = value.trim()
414
- console.log('==删除前后空格==', value, '==删除前后空格==')
415
- }
416
-
417
- let starId = e.target.dataset.star
418
- // 切换“证件类型”
419
- let oldCidType = this.data.formData.cid_type
420
- if (formId === 'cid_type' && oldCidType !== value) {
421
- cidType = value
422
- wx.showLoading({
423
- title: '加载中…',
424
- })
425
-
426
- // 若是港澳台,则证件类别默认为居住证核验
427
- if (value == 17 || value == 18) {
428
- this.setData({
429
- currentAuthType: 'faceReceptionAuth',
430
- rules: rulesConfig.residenceAuthRules('zh_CN')
431
- })
432
- }
433
-
434
- // 语言环境
435
- this.setData({
436
- language: value === '700' ? 'en' : 'zh_CN'
437
- })
438
-
439
- // 临时存储用户填写的表单信息、是否需要回显
440
- this.saveFormDataTemp(true, value, oldCidType)
441
- } else {
442
- // 临时存储表单数据
443
- this.saveFormDataTemp()
444
-
445
- this.setData({
446
- [`formData.${formId}`]: value
447
- })
448
- if (starId) {
449
- this.setData({
450
- [`formData.${starId}`]: ''
451
- })
452
- }
453
- }
454
- },
455
-
456
- // 临时存储用户填写的表单信息
457
- saveFormDataTemp(needFull = false, newCidType = '', oldCidType = '') {
458
- console.log('临时存储用户填写的表单信息', needFull, newCidType, oldCidType)
459
- let {
460
- formData
461
- } = this.data
462
-
463
- let formDataTemp = wx.getStorageSync('tif.formDataTemp') || {}
464
- formDataTemp[formData.cid_type] = formData
465
- wx.setStorageSync('tif.formDataTemp', formDataTemp)
466
- if (needFull) {
467
- // 是否需要回传
468
- this.setData({
469
- formData: {
470
- cid_type: newCidType,
471
- name: '',
472
- id_card_number: '',
473
- bank_account: '',
474
- nation: '',
475
- nation_name: '',
476
- sur_name: '',
477
- first_name: '',
478
- sex: '',
479
- birthday: '',
480
- cid_expire_date: '',
481
- validity_period: '',
482
- passport_number: '',
483
- phone: '',
484
- verify_expire_time: '',
485
- agree: false,
486
- isbind: 1
487
- }
488
- })
489
- if (newCidType === '700') {
490
- // 获取外国护照核验结果
491
- this.fetchPassortAuthResult()
492
- } else {
493
- // 回传 Temp => Success => 空
494
- this.restartInitChange(newCidType)
495
- }
496
- wx.hideLoading()
497
- }
498
- },
499
-
500
- // 回传 Temp => Success => 空
501
- restartInitChange(cid_type) {
502
- console.log('根据证件类型匹配校验正则,回填本地Temp数据')
503
- wx.showLoading({
504
- title: '加载中…',
505
- })
506
- // 根据证件类型匹配校验正则
507
- this.toMatchRules()
508
- // 数据回传
509
- this.reFullFormDataTemp(cid_type)
510
- },
511
-
512
- // 获取外国人护照核验结果、是否需要返回状态
513
- fetchPassortAuthResult(needStatus = false) {
514
- // 根据证件类型匹配校验正则
515
- !needStatus && this.toMatchRules()
516
- let formData = this.data.formData
517
-
518
- return new Promise((resolve) => {
519
- jingtongVerifyRequest.getPassportInfo({
520
- success: res => {
521
- console.log('外国人护照核验接口获取成功', res)
522
-
523
- this.setData({
524
- passportAuthStatus: res.status,
525
- passportAuthPersonCode: res.person_code
526
- })
527
-
528
- if (needStatus) {
529
- // 需要返回状态
530
- resolve(res.status)
531
- } else {
532
- let {
533
- id_card_number,
534
- nation,
535
- sur_name,
536
- first_name,
537
- sex,
538
- birthday,
539
- cid_expire_date,
540
- phone,
541
- verify_expire_time,
542
- nation_name
543
- } = res
544
- let passportOldData = {
545
- id_card_number,
546
- nation,
547
- nation_name,
548
- sur_name,
549
- first_name,
550
- sex: sex ? sex : '',
551
- birthday,
552
- cid_expire_date,
553
- phone,
554
- verify_expire_time: verify_expire_time && Number(verify_expire_time) || ''
555
- }
556
- formData = Object.assign(formData, res, passportOldData)
557
- this.setData({
558
- formData,
559
- passportOldData
560
- })
561
- }
562
- },
563
- fail: err => {
564
- console.log('外国人护照核验接口获取失败', err)
565
- let { errmsg } = JSON.parse(err)
566
- wx.showToast({
567
- title: errmsg || '获取核验信息接口失败',
568
- icon: 'none',
569
- duration: 3000
570
- })
571
- }
572
- })
573
- })
574
- },
575
-
576
- // 选择国籍
577
- handleNationTap() {
578
- // 临时存储表单数据
579
- this.saveFormDataTemp()
580
- flow.navigateTo({
581
- url: `../nation-list/nation-list?cid_type=${this.data.formData.cid_type}`,
582
- })
583
- },
584
-
585
- async handleFormSubmit(e) {
586
- if (!e.detail.validStatus) {
587
- return
588
- }
589
- wx.showLoading({
590
- title: '加载中…',
591
- mask: true
592
- })
593
-
594
- console.log('删除“姓名、证件号码、护照号码、手机号码”的前后空格')
595
- let { name, id_card_number, sur_name, first_name, passport_number, phone, cid_type } = this.data.formData
596
-
597
- this.setData({
598
- ['formData.name']: name.trim(),
599
- ['formData.sur_name']: sur_name.trim(),
600
- ['formData.first_name']: first_name.trim(),
601
- ['formData.passport_number']: passport_number.trim(),
602
- ['formData.phone']: phone.trim(),
603
- ['formData.id_card_number']: id_card_number.trim()
604
- })
605
-
606
- if (cid_type === '700') {
607
- console.log('删除“外国人护照号码”中间空格')
608
- this.setData({
609
- ['formData.id_card_number']: id_card_number.replace(/\s+/g, '')
610
- })
611
- }
612
-
613
- console.log('入参', this.data.formData)
614
-
615
- let currentAuthType = this.data.currentAuthType
616
- console.log('当前认证类型', currentAuthType)
617
-
618
- if (currentAuthType === 'wxFace') {
619
- console.log('微信人脸识别认证')
620
-
621
- // 判断是否是PC端登录
622
- await this.getDevice()
623
-
624
- // 判断人脸失败次数
625
- await this.fetchFaceFailCount(false)
626
-
627
- // 错误触发销毁回调函数处理
628
- this.handleExitedState()
629
-
630
- // 开启人脸识别认证
631
- this.toFaceVerify()
632
- } else if (currentAuthType === 'faceReceptionAuth') {
633
- console.log('出入境微信人脸识别接口认证')
634
- // 错误触发销毁回调函数处理
635
- this.handleExitedState()
636
-
637
- // 判断是否是PC端登录
638
- await this.getDevice()
639
-
640
- // 出入境微信人脸识别接口
641
- this.toFaceReceptionAuth()
642
- } else if(currentAuthType === 'cardAuth') {
643
- console.log('银行卡接口认证')
644
- // 银行卡身份核验接口
645
- this.bankCardAuth()
646
- } else if(currentAuthType === 'ForeignPassortAuth') {
647
- console.log('外国人护照核验')
648
- // 外国人护照核验
649
- this.handlePassortAuth()
650
- }
651
- },
652
-
653
- // 开启人脸识别认证
654
- async toFaceVerify() {
655
- const [err, session] = await utils.awaitTo(jingtongVerifyRequest.faceVerifyWithIdCard(this.data.formData))
656
-
657
- const cidType = this.data.formData.cid_type
658
-
659
- if (err) {
660
- // 埋点上报事件:刷脸认证
661
- this.faceTracker(2, cidType)
662
-
663
- // 埋点上报事件:自然人登录
664
- this.loginTracker(3, cidType)
665
-
666
- console.log('微信人脸识别失败', err)
667
- let { errmsg, errMsg, errCode } = JSON.parse(err)
668
- if (errCode) {
669
- let errCodeArr = [10002, 10003, 10004, 10005, 10012, 10057, 90002, 90003, 90004, 90005, 90006, 90100, 90023, 90024, 90025]
670
- if (errCodeArr.indexOf(errCode) >= 0) {
671
- console.log('在指定的错误码范围内,人脸失败次数+1')
672
- // 设置人脸失败次数
673
- await this.fetchFaceFailCount(true, errCode)
674
- }
675
- // 人脸识别异常温馨提示弹窗
676
- this.handleFaceError(errCode)
677
- }
678
-
679
- if (errCode && errCode === 90100) {
680
- wx.showToast({
681
- title: '您已取消人脸识别',
682
- icon: 'none',
683
- duration: 3000
684
- })
685
- } else if (errCode && errCode === 10004) {
686
- wx.showToast({
687
- title: '人脸与身份信息不匹配',
688
- icon: 'none',
689
- duration: 3000
690
- })
691
- } else if (errCode && errCode === 10003) {
692
- wx.showToast({
693
- title: '姓名或证件号码有误',
694
- icon: 'none',
695
- duration: 3000
696
- })
697
- } else {
698
- wx.showToast({
699
- title: errmsg || errMsg || '认证失败,请稍后再试',
700
- icon: 'none',
701
- duration: 3000
702
- })
703
- }
704
- } else {
705
- // 埋点上报事件:刷脸认证
706
- this.faceTracker(1, cidType)
707
-
708
- console.log('认证成功返回页面数据:', session)
709
- // 保存刷脸成功时间戳
710
- let timeStamp = new Date().getTime()
711
- wx.setStorageSync('tif.faceTimeStamp', timeStamp)
712
-
713
- this.authSuccess(session)
714
- }
715
- },
716
-
717
- // 人脸识别异常温馨提示弹窗
718
- handleFaceError(code) {
719
- let errCode1 = [10009, 10026, 10032, 10072, 10076, 10084, 10086, 10089, 10092, 10049, 10107, 10095]
720
- let errCode2 = [10002, 10004, 10005, 10010, 10012, 10027, 10028, 10057]
721
- if (errCode1.indexOf(code) >= 0) {
722
- // 1: 未办理过身份证/新办理身份证的
723
- this.setData({
724
- faceErrorModal: true,
725
- faceErrorType: '1'
726
- })
727
- } else if (errCode2.indexOf(code) >= 0) {
728
- const age = utils.parseIDCard(this.data.formData.id_card_number).age
729
- console.log('年龄', age)
730
- if (age >= 60) {
731
- // 3: 刷脸没刷过,60岁以上的
732
- this.setData({
733
- faceErrorModal: true,
734
- faceErrorType: '3'
735
- })
736
- } else {
737
- // 2: 刷脸没刷过,60岁以下的
738
- this.setData({
739
- faceErrorModal: true,
740
- faceErrorType: '2'
741
- })
742
- }
743
- }
744
- },
745
-
746
- // 出入境微信人脸识别接口
747
- async toFaceReceptionAuth() {
748
- // 临时存储表单数据
749
- this.saveFormDataTemp()
750
-
751
- // 数据加密
752
- const [err, res] = await utils.awaitTo(jingtongVerifyRequest.caEncrypt(this.data.formData))
753
- if (err) {
754
- console.log('CA加密失败', err)
755
- let { errmsg } = JSON.parse(err)
756
- wx.showToast({
757
- title: errmsg || 'CA加密失败,请重试',
758
- icon: 'none',
759
- duration: 3500
760
- })
761
- } else {
762
- wx.hideLoading()
763
- console.log('CA加密成功:', res)
764
- this.toFaceReceptionVerify(res.user_id_key)
765
- }
766
- },
767
-
768
- // 开启出入境微信人脸识别认证
769
- async toFaceReceptionVerify(userIdKey) {
770
- const params = Object.assign(this.data.formData, {
771
- userIdKey
772
- })
773
- const { cid_type } = this.data.formData
774
- const [err, session] = await utils.awaitTo(jingtongVerifyRequest.faceVerifyWithUserIdKey(params))
775
- if (err) {
776
- console.log('出入境-微信人脸识别失败', err)
777
-
778
- // 埋点上报事件:刷脸认证
779
- this.faceTracker(2, cid_type)
780
-
781
- // 埋点上报事件:自然人登录
782
- this.loginTracker(3, cid_type)
783
-
784
- try {
785
- let { errmsg = '', errMsg = '', errCode = '' } = JSON.parse(err) || ''
786
- if (errCode && errCode === 90100) {
787
- wx.showToast({
788
- title: '您已取消人脸识别',
789
- icon: 'none',
790
- duration: 3000
791
- })
792
- } else if (errCode && errCode === 10004) {
793
- wx.showToast({
794
- title: '人脸与身份信息不匹配',
795
- icon: 'none',
796
- duration: 3000
797
- })
798
- } else if (errCode && errCode === 10003) {
799
- wx.showToast({
800
- title: '姓名或证件号码有误',
801
- icon: 'none',
802
- duration: 3000
803
- })
804
- } else if (errCode && errCode === 10111 && (cid_type === '17' || cid_type === '18')) {
805
- // 若是“港澳台居住证”且错误码是10111,则触发银行卡核验
806
- this.setData({
807
- showCardModal: true
808
- })
809
- } else {
810
- wx.showToast({
811
- title: errmsg || errMsg || '认证失败,请稍后再试',
812
- icon: 'none',
813
- duration: 3000
814
- })
815
- }
816
- } catch {
817
- wx.showToast({
818
- title: '人脸识别不支持电脑端,请使用真机',
819
- icon: 'none',
820
- duration: 3000
821
- })
822
- }
823
- } else {
824
- // 埋点上报事件:刷脸认证
825
- this.faceTracker(1, cid_type)
826
-
827
- console.log('认证成功返回页面数据:', session)
828
- this.authSuccess(session)
829
- }
830
- },
831
-
832
- // 港澳台居住证核验接口
833
- async HmtResidenceAuth() {
834
- const [err, session] = await utils.awaitTo(jingtongVerifyRequest.residenceAuth(this.data.formData))
835
- if (err) {
836
- console.log('港澳台居住证核验接口认证失败', err)
837
- let { errmsg, errcode } = JSON.parse(err)
838
- if (errcode == 4048) {
839
- this.setData({
840
- showCardModal: true
841
- })
842
- } else {
843
- wx.showToast({
844
- title: errmsg || '认证失败',
845
- icon: 'none',
846
- duration: 3000
847
- })
848
- }
849
- } else {
850
- console.log('认证成功返回页面数据:', session)
851
- this.authSuccess(session)
852
- }
853
- },
854
-
855
- // 银行卡身份核验接口
856
- async bankCardAuth() {
857
- const [err, session] = await utils.awaitTo(jingtongVerifyRequest.bankCardAuth(this.data.formData))
858
- if (err) {
859
- // 埋点上报事件:自然人登录
860
- this.loginTracker(2, this.data.formData.cid_type)
861
-
862
- console.log('银行卡身份核验接口认证失败', err)
863
- let { errmsg } = JSON.parse(err)
864
- wx.showToast({
865
- title: errmsg || '认证失败',
866
- icon: 'none',
867
- duration: 3000
868
- })
869
- } else {
870
- console.log('认证成功返回页面数据:', session)
871
- this.authSuccess(session)
872
- }
873
- },
874
-
875
- // 外国人护照核验处理逻辑
876
- handlePassortAuth() {
877
- let authStatus = this.data.passportAuthStatus
878
- let newData = this.data.formData
879
- let oldData = this.data.passportOldData
880
-
881
- console.log('当前核验单状态', authStatus)
882
-
883
- if (!authStatus) {
884
- console.log('无审核单', authStatus)
885
- // 外国人护照核验,提交核验单
886
- this.passportAuth()
887
- } else {
888
- // 查上一单的状态
889
- this.fetchPassortAuthResult(true).then(status => {
890
- console.log('====查上一单的状态====', status)
891
- if (status === '1') {
892
- // 核验通过,弹窗提示
893
- console.log('外国人护照核验通过')
894
- this.passportAuthSuccess()
895
- } else {
896
- // 比对表单数据是否有修改
897
- console.log('新旧表单数据比对', newData, oldData)
898
- if (utils.objIsEqual(newData, oldData)) {
899
- console.log('表单数据没有修改')
900
- if (status === '4') {
901
- // 核验中
902
- this.fetchPassortAuthResult(true).then(status => {
903
- console.log('再次获取外国人护照核验状态', status)
904
- if (status === '1') {
905
- console.log('外国人护照核验通过')
906
- this.passportAuthSuccess()
907
- } else if (status === '4') {
908
- console.log('外国人护照核验中,弹窗提示')
909
- this.handleShowModal(status)
910
- } else {
911
- // 核验不通过,弹窗提示
912
- this.passportAuthFail(status)
913
- }
914
- })
915
- } else {
916
- // 核验不通过,弹窗提示
917
- this.passportAuthFail(status)
918
- }
919
- } else {
920
- console.log('表单数据存在修改')
921
- // 外国人护照核验,提交核验单
922
- this.passportAuth()
923
- }
924
- }
925
- })
926
- }
927
- },
928
-
929
- // 外国人护照核验不通过逻辑
930
- passportAuthFail(status) {
931
- console.log('===外国人护照核验不通过,弹窗提示===')
932
- // 判断当前person_code是否已失效
933
- const personCode = this.data.passportAuthPersonCode
934
- const localPersonCode = wx.getStorageSync('tif.fail.person_code') || ''
935
- if (personCode === localPersonCode) {
936
- // 提交核验单
937
- this.passportAuth()
938
- } else {
939
- // 埋点上报事件:自然人登录
940
- this.loginTracker(2, this.data.formData.cid_type)
941
-
942
- this.handleShowModal(status)
943
- // 记录这个person_code是失效的
944
- wx.setStorageSync('tif.fail.person_code', this.data.passportAuthPersonCode)
945
- }
946
- },
947
-
948
- // 外国人护照核验接口
949
- async passportAuth() {
950
- console.log('===========提交核验单============')
951
- let formData = this.data.formData
952
-
953
- const isLegalDate = utils.greaterCurrentTime(formData.cid_expire_date)
954
- console.log('isLegalDate', isLegalDate)
955
- if (!isLegalDate) {
956
- console.log('护照有效期日期不合法')
957
- wx.showToast({
958
- title: 'Please select the passport expiration date',
959
- icon: 'none',
960
- duration: 3000
961
- })
962
- this.setData({
963
- 'formData.cid_expire_date': ''
964
- })
965
- return
966
- }
967
-
968
- const [err, res] = await utils.awaitTo(jingtongVerifyRequest.passportAuth(formData))
969
- if (err) {
970
- console.log('外国人护照核验接口认证失败', err)
971
- let { errmsg } = JSON.parse(err)
972
- wx.showToast({
973
- title: errmsg || '认证失败',
974
- icon: 'none',
975
- duration: 3000
976
- })
977
- return
978
- }
979
- console.log('弹窗提示等待10分钟', res)
980
- this.setData({
981
- passportAuthStatus: '4',
982
- passportOldData: JSON.parse(JSON.stringify(formData)),
983
- passportAuthPersonCode: ''
984
- })
985
- wx.setStorageSync('tif.fail.person_code', '')
986
- this.handleShowModal('4')
987
- },
988
-
989
- // 外国人护照核验通过
990
- passportAuthSuccess() {
991
- // 调用删除接口/静默登录并返回session信息
992
- jingtongVerifyRequest.deletePassportAuth({
993
- success: session => {
994
- console.log('返回session信息', session)
995
-
996
- // 删除缓存信息
997
- console.log('删除缓存信息')
998
- let formDataTemp = wx.getStorageSync('tif.formDataTemp')
999
- formDataTemp['700'] = {}
1000
- wx.setStorageSync('tif.formDataTemp', formDataTemp)
1001
- this.setData({
1002
- passportOldData: {}
1003
- })
1004
-
1005
- this.authSuccess(session, true)
1006
- },
1007
- fail: err => {
1008
- // 埋点上报事件:自然人登录
1009
- this.loginTracker(2, this.data.formData.cid_type)
1010
-
1011
- let { errmsg } = JSON.parse(err)
1012
- wx.showToast({
1013
- title: errmsg || 'auth fail',
1014
- icon: 'none',
1015
- duration: 3000
1016
- })
1017
- }
1018
- })
1019
- },
1020
-
1021
- // 认证成功后续操作
1022
- authSuccess(session, isEn = false) {
1023
- console.log('====判断是否真的登录成功=====')
1024
- if (!session) {
1025
- wx.showToast({
1026
- title: '登录态失效,请重试',
1027
- icon: 'none',
1028
- duration: 2000
1029
- })
1030
- return
1031
- }
1032
- const { face_time, realname_time, cid, has_phone, certType } = session
1033
- if ((!face_time && !realname_time) || !cid) {
1034
- wx.showToast({
1035
- title: `登录态失效请重试: ${this.data.formData.cid_type}`,
1036
- icon: 'none',
1037
- duration: 2000
1038
- })
1039
- return
1040
- }
1041
-
1042
- wx.showToast({
1043
- title: isEn ? 'Verification successful, redirecting...': '验证成功, 跳转中…',
1044
- icon: 'none',
1045
- duration: 5000,
1046
- mask: true
1047
- })
1048
-
1049
- const cidType = session.cid_type
1050
-
1051
- // 本地存储表单核验成功数据
1052
- wx.setStorageSync('tif.formDataSuccess', this.data.formData)
1053
-
1054
- // 将弹窗标识设置为不需要弹窗
1055
- jingtongVerifyRequest.setUserReadStatus(false).then(() => {
1056
- console.log('设置弹窗标识成功')
1057
- }).catch(err => {
1058
- console.log('设置弹窗标识失败', err)
1059
- })
1060
-
1061
- setTimeout(() => {
1062
- if (this.data.needUnite === "true") {
1063
- // this.setData({
1064
- // needUnite: ''
1065
- // })
1066
-
1067
- console.log('进入业务总入口, 判断是否有手机号码', has_phone)
1068
-
1069
- // 登录成功回调 => 业务侧操作事项
1070
- wx.$_ServiceConfiguration && wx.$_ServiceConfiguration.methods && wx.$_ServiceConfiguration.methods._loginSuccessCallBack && wx.$_ServiceConfiguration.methods._loginSuccessCallBack(session)
1071
-
1072
- if (has_phone) {
1073
- const realPhone = wx.getStorageSync('tif.realPhone') || ''
1074
- const caPhone = wx.getStorageSync('tif.caPhone') || ''
1075
- const confirmTime = wx.getStorageSync('tif.tel_confirm_time') || ''
1076
-
1077
- console.log('realPhone', realPhone)
1078
- console.log('caPhone', caPhone)
1079
- console.log('confirmTime', confirmTime)
1080
-
1081
- if (realPhone !== caPhone && confirmTime && (!utils.completeDate(new Date(Number(confirmTime + '000')), 6))) {
1082
- // 埋点上报事件:自然人登录
1083
- this.loginTracker(1, cidType)
1084
-
1085
- this.setData({
1086
- hadSuccessLogin: true
1087
- })
1088
-
1089
- // 【phone与caPhone不同】且【tel_confirm_time大于6个月】
1090
- // 数据库手机号码有效期大于6个月
1091
- flow.redirectTo({
1092
- url: '../confirm-phone/confirm-phone'
1093
- })
1094
- } else {
1095
- jingtongVerifyRequest.personToken({
1096
- source: '11'
1097
- }).then(async data => {
1098
- // 设置用户账号信息
1099
- setAccountInfo(session.openid)
1100
-
1101
- // 埋点上报事件:自然人登录
1102
- this.loginTracker(1, cidType)
1103
-
1104
- this.setData({
1105
- hadSuccessLogin: true
1106
- })
1107
-
1108
- // 埋点 - 个人用户实体全属性上报
1109
- let last_login_time = utils.getCurrentTime()
1110
- wx.setStorageSync('tif.lastLoginTime', last_login_time)
1111
- const userEntityReportData = Object.assign(session, {
1112
- user_status: '1',
1113
- last_login_time,
1114
- user_date_of_birth: session.cid_type === '111' ? utils.getBirthByIDCard(session.cid) : ''
1115
- })
1116
- await utils.awaitTo(jingtongVerifyRequest.userEntityReport(userEntityReportData))
1117
-
1118
- setTimeout(() => {
1119
- flow.resolve({
1120
- token: data
1121
- })
1122
- }, 1200)
1123
- })
1124
- }
1125
- } else {
1126
- // 埋点上报事件:自然人登录
1127
- this.loginTracker(1, cidType)
1128
-
1129
- this.setData({
1130
- hadSuccessLogin: true
1131
- })
1132
-
1133
- flow.redirectTo({
1134
- url: '../bind-phone/bind-phone?source=3'
1135
- })
1136
- }
1137
- } else {
1138
- console.log('返回主包')
1139
- flow.resolve()
1140
- }
1141
- }, 800)
1142
- },
1143
-
1144
- // 埋点上报事件:刷脸认证
1145
- faceTracker(recognition_status = 1, cidType) {
1146
- SDKTrack('face_recognition_login', {
1147
- recognition_status, // 1: 人脸识别成功 2:人脸识别失败
1148
- login_certificate: this.data.certTypeMap[cidType] || 1, // 证件类型
1149
- invoke_location: '' // 调起位置
1150
- })
1151
- },
1152
-
1153
- // 埋点上报事件:自然人登录
1154
- loginTracker(login_status = 1, cidType) {
1155
- SDKTrack('nature_person_login', {
1156
- // 1 登录成功;2 登录失败-身份信息核验失败;3 登录失败-人脸核验失败
1157
- // 4 登录失败-电子营业执照核验失败;5 登录失败-账号密码输入错误
1158
- // 6 取消登录(包含点击温馨提示的“取消”,点击请法人登录的×,在登录页面点击左上角返回按钮退出登录)
1159
- // 7 退出小程序终止登录;old_1 历史数据:除登录成功之外的所有情况
1160
- login_status,
1161
- login_certificate: this.data.certTypeMap[cidType] || 1, // 证件类型
1162
- invoke_location: '', // 调起位置
1163
- login_validity_period: this.data.formData.verify_expire_time / 24 || '' // 免登录时间
1164
- })
1165
- },
1166
-
1167
- // 显示弹窗
1168
- handleShowModal(status) {
1169
- let modalStatus = ''
1170
- if (status === '3') {
1171
- // 未找到信息
1172
- modalStatus = 'warning'
1173
- } else if (status === '4') {
1174
- // 核验中
1175
- modalStatus = 'info'
1176
- } else {
1177
- // 信息有误
1178
- modalStatus = 'error'
1179
- }
1180
- this.setData({
1181
- modalStatus,
1182
- showModal: true
1183
- },() => {
1184
- wx.hideLoading()
1185
- })
1186
- },
1187
-
1188
- // modal确认事件
1189
- handleModalOk() {
1190
- // this.fetchPassortAuthResult()
1191
- this.setData({
1192
- showModal: false,
1193
- showFaceModal: false,
1194
- showLockFaceModal: false,
1195
- showCardModal: false,
1196
- showTipModal: false
1197
- })
1198
- },
1199
-
1200
- // 调起银行卡认证
1201
- toCardAuth() {
1202
- console.log('====调起银行卡认证====')
1203
- this.setData({
1204
- currentAuthType: 'cardAuth',
1205
- rules: rulesConfig.cardRules('zh_CN'),
1206
- showCardModal: false
1207
- })
1208
- },
1209
-
1210
- // 触发问号弹出
1211
- showQuestionTip() {
1212
- this.setData({
1213
- showTipModal: true
1214
- })
1215
- },
1216
-
1217
- onUnload: function() {
1218
- // 页面卸载时的逻辑处理
1219
- console.log('======页面即将卸载======', this.data.hadSuccessLogin);
1220
- if (!this.data.hadSuccessLogin) {
1221
- // 埋点上报事件:自然人登录
1222
- this.loginTracker(6, this.data.formData.cid_type)
1223
- }
1224
- },
1225
-
1226
- // 有些操作程序会触发销毁回调函数,该操作不是真正的小程序销毁操作
1227
- handleExitedState() {
1228
- this.setData({
1229
- exitedState: false
1230
- })
1231
- setTimeout(() => {
1232
- this.setData({
1233
- exitedState: true
1234
- })
1235
- }, 2000)
1236
- },
1237
-
1238
- onSaveExitState: function() {
1239
- // 小程序可能被销毁之前的逻辑处理
1240
- if (!this.data.hadSuccessLogin && this.data.exitedState) {
1241
- console.log('======小程序可能被销毁======')
1242
- // 埋点上报事件:自然人登录
1243
- this.loginTracker(7, this.data.formData.cid_type)
1244
- }
1245
- },
1246
-
1247
- // 关闭 - 扫脸失败温馨提示弹窗
1248
- cancelFaceErrorModal() {
1249
- this.setData({
1250
- faceErrorModal: false
1251
- })
1252
- },
1253
-
1254
- // 扫脸失败温馨提示弹窗-跳转到失败原因
1255
- okFaceErrorModal() {
1256
- this.setData({
1257
- faceErrorModal: false
1258
- })
1259
- flow.navigateTo({
1260
- url: `../face-error-reason/face-error-reason?type=${this.data.faceErrorType}`,
1261
- })
1262
- },
1263
-
1264
- openEye(e) {
1265
- console.log(e)
1266
- const isOpen = e.detail.isOpen
1267
- const key = e.currentTarget.id
1268
- const strKey = e.currentTarget.dataset.star
1269
- console.log('isOpen', isOpen)
1270
- console.log('key', key)
1271
- console.log('strKey', strKey)
1272
- if (isOpen) {
1273
- console.log('显示脱敏')
1274
- const { name, id_card_number } = this.data.formData
1275
- const value = key === 'name' ? utils.hideName(name) : utils.hideIdCard(id_card_number, '111')
1276
- console.log('value', value)
1277
- this.setData({
1278
- [`formData.${strKey}`]: value
1279
- })
1280
- } else {
1281
- console.log('删除脱敏,显示明文')
1282
- this.setData({
1283
- [`formData.${strKey}`]: ''
1284
- })
1285
- }
1286
- }
1
+ // weapps-plugin-jingtong-verify/pages/face-verify/index.js
2
+ const jingtongVerifyRequest = require('../../utils/request')
3
+ const utils = require("../../utils/index")
4
+ const { flow } = require("@wecity/weda-plugin-utils");
5
+ const rulesConfig = require("../../utils/rules")
6
+ import { SDKTrack, setAccountInfo } from '../../utils/QDTrackerNew/QDTrackerMain'
7
+ let cidType = '111'
8
+ let Nation = 'CHN'
9
+
10
+ Page({
11
+ /**
12
+ * 页面的初始数据
13
+ */
14
+ data: {
15
+ language: 'zh_CN', // 语言环境:默认中文
16
+ formData: {
17
+ cid_type: '111', // 证件类型
18
+ strName: '', // 身份证姓名(脱敏)
19
+ name: '',
20
+ strCid: '', // 身份证号码(脱敏)
21
+ id_card_number: '', // 证件号码
22
+ strBankCount: '', // 银行卡卡号(脱敏)
23
+ bank_account: '',
24
+ nation: 'CHN', // 国籍
25
+ nation_name: '中国',
26
+ sur_name: '', //
27
+ first_name: '', //
28
+ sex: '', // 性别
29
+ birthday: '', // 出生日期
30
+ cid_expire_date: '', // 护照有效期
31
+ validity_period: '', // 证件生效日期
32
+ passport_number: '', // 通行证号码
33
+ phone: '',
34
+ verify_expire_time: '', // 登录有效期
35
+ agree: false,
36
+ isbind: 1,
37
+ sbSwitch: true
38
+ },
39
+ needUnite: '', // 是否需要串联起来
40
+ agreeInfo: '我同意北京市大数据中心使用我所提交的信息注册京通小程序,以及登录北京市统一身份认证平台,以便使用京通相关服务。',
41
+ cidTypeRange: [
42
+ // 微信人脸识别
43
+ { name: '中华人民共和国居民身份证', value: '111' },
44
+ // 移民局接口
45
+ { name: '港澳居民来往内地通行证', value: '516' },
46
+ { name: '台湾居民来往大陆通行证', value: '511' },
47
+ { name: '外国人永久居留身份证', value: '553' },
48
+ { name: '华侨护照(国内签发)', value: '414' },
49
+ // 银行卡接口
50
+ { name: '港澳居民居住证', value: '17' },
51
+ { name: '台湾居民居住证', value: '18' },
52
+ // 外国护照
53
+ { name: 'International passport', value: '700' }
54
+ ],
55
+ sexRange: [
56
+ { name: 'Male', value: 1 },
57
+ { name: 'Female', value: 2 }
58
+ ],
59
+ sexRangeZH: [
60
+ { name: '', value: 1 },
61
+ { name: '女', value: 2 }
62
+ ],
63
+ loginTimeRangeEn: [
64
+ { name: 'Keep me logged in for 1 day', value: 24 },
65
+ { name: 'Keep me logged in for 7 days', value: 168 },
66
+ { name: 'Keep me logged in for 30 days', value: 720 }
67
+ ],
68
+ loginTimeRange: [
69
+ { name: '1天免登录', value: 24 },
70
+ { name: '7天免登录', value: 168 },
71
+ { name: '30天免登录', value: 720 }
72
+ ],
73
+ validateType: {
74
+ id_card_number(value) {
75
+ return utils.validate.checkCid(value, cidType, Nation).data
76
+ },
77
+ name(value) {
78
+ return utils.validate.checkName(value, cidType).data
79
+ },
80
+ sur_name(value) {
81
+ return utils.validate.checkName(value, cidType).data
82
+ },
83
+ first_name(value) {
84
+ return utils.validate.checkName(value, cidType).data
85
+ },
86
+ passport_number(value) {
87
+ return utils.validate.checkHmtPassport(value, cidType, Nation).data
88
+ },
89
+ },
90
+ rulesMap: {
91
+ '111': {
92
+ currentAuthType: 'wxFace',
93
+ rules: rulesConfig.chinaRules('zh_CN')
94
+ },
95
+ '516': {
96
+ currentAuthType: 'faceReceptionAuth',
97
+ rules: rulesConfig.HMORules('zh_CN')
98
+ },
99
+ '511': {
100
+ currentAuthType: 'faceReceptionAuth',
101
+ rules: rulesConfig.HMORules('zh_CN')
102
+ },
103
+ '553': {
104
+ currentAuthType: 'faceReceptionAuth',
105
+ rules: rulesConfig.residenceRules('zh_CN')
106
+ },
107
+ '414': {
108
+ currentAuthType: 'faceReceptionAuth',
109
+ rules: rulesConfig.HMORules('zh_CN')
110
+ },
111
+ '17': {
112
+ currentAuthType: 'faceReceptionAuth',
113
+ // rules: rulesConfig.cardRules('zh_CN'),
114
+ rules: rulesConfig.residenceAuthRules('zh_CN'),
115
+ tip: '请填写本人在办理银联银行卡时登记的姓名、港澳居民居住证证件号、手机号、银行卡号。'
116
+ },
117
+ '18': {
118
+ currentAuthType: 'faceReceptionAuth',
119
+ // rules: rulesConfig.cardRules('zh_CN'),
120
+ rules: rulesConfig.residenceAuthRules('zh_CN'),
121
+ tip: '请填写本人在办理银联银行卡时登记的姓名、台湾居民居住证证件号、手机号、银行卡号。'
122
+ },
123
+ '700': {
124
+ currentAuthType: 'ForeignPassortAuth',
125
+ rules: rulesConfig.ForeignPassortRules('en')
126
+ }
127
+ },
128
+ rules: rulesConfig.chinaRules('zh_CN'),
129
+ // 核验类别
130
+ currentAuthType: 'wxFace',
131
+ // 打开文档的防抖操作
132
+ canOpenPdf: true,
133
+ // 外国人护照核验状态 '1'(通过) '4'(审核中) ''(无审核单) 其它值(审核失败)
134
+ passportAuthStatus: '',
135
+ passportAuthPersonCode: '',
136
+ // 核验单数据
137
+ passportOldData: {},
138
+ // 弹窗
139
+ showModal: false,
140
+ modalStatus: 'info',
141
+ // 定义日期边界值
142
+ birthdayMaxDate: [new Date().getFullYear(), (new Date().getMonth() + 1), new Date().getDate()],
143
+ cidExpireMinDate: [new Date().getFullYear(), (new Date().getMonth() + 1), new Date().getDate()],
144
+ // 老/小6次、成人3次 人脸报错提示弹窗
145
+ showFaceModal: false,
146
+ isKidsOrOld: false,
147
+ // 老/小18次、成人6次 人脸报错提示弹窗
148
+ showLockFaceModal: false,
149
+ // 银行卡认证弹窗
150
+ showCardModal: false,
151
+ // 姓名和证件号码弹窗
152
+ showTipModal: false,
153
+ // cidType转化为certType
154
+ certTypeMap: {
155
+ '111': 1,
156
+ '516': 78,
157
+ '511': 4,
158
+ '17': 5,
159
+ '18': 6,
160
+ '414': 2,
161
+ '553': 9,
162
+ '700': 3
163
+ },
164
+ // 记录是否已经登录成功
165
+ hadSuccessLogin: false,
166
+ // 该操作会触发小程序的销毁回调
167
+ exitedState: true,
168
+ // 扫脸失败温馨提示弹窗
169
+ faceErrorModal: false,
170
+ // 扫脸失败原因
171
+ faceErrorType: '2',
172
+ // 标记港澳居民来往内地通行证存在回显的session信息
173
+ // exitHmSession: false,
174
+ // HmSession: {}
175
+ showForeignTip: false
176
+ },
177
+
178
+ /**
179
+ * 生命周期函数--监听页面加载
180
+ */
181
+ onLoad(options) {
182
+ console.log('onLoad', options)
183
+ this.setData({
184
+ needUnite: options.needUnite || 'true'
185
+ })
186
+
187
+ // 初始化操作,回填证件类型为身份证的身份信息
188
+ this.initUserInfo()
189
+ },
190
+
191
+ // 初始化操作,回填证件类型为身份证的身份信息
192
+ initUserInfo() {
193
+ // 默认身份证号码
194
+ cidType = '111'
195
+
196
+ wx.showLoading({
197
+ title: '加载中…',
198
+ })
199
+ // 清空本地Temp数据
200
+ wx.setStorageSync('tif.formDataTemp', '')
201
+
202
+ jingtongVerifyRequest.getSession({
203
+ success: res => {
204
+ let { cid_type, cid, name, star_name, star_cid, verify_expire_time } = res
205
+
206
+ // 设置用户账号信息
207
+ setAccountInfo(res.openid)
208
+
209
+ const hideForeignTip = wx.getStorageSync('tif.hideForeignTip') || 0
210
+ console.log('hideForeignTip', hideForeignTip)
211
+ if (!cid && hideForeignTip !== '1') {
212
+ this.setData({
213
+ showForeignTip: true
214
+ })
215
+ }
216
+
217
+ if (cid_type === '111' && cid && name) {
218
+ // 回填身份证类型
219
+ this.setData({
220
+ 'formData.strName': star_name,
221
+ 'formData.name': name,
222
+ 'formData.strCid': star_cid,
223
+ 'formData.id_card_number': cid,
224
+ 'formData.cid_type': cid_type,
225
+ 'formData.verify_expire_time': verify_expire_time || ''
226
+ })
227
+ }
228
+ // if (cid_type === '516') {
229
+ // this.setData({
230
+ // exitHmSession: true,
231
+ // HmSession: res
232
+ // })
233
+ // console.log('HmSession', this.data.HmSession)
234
+ // } else {
235
+ // this.setData({
236
+ // exitHmSession: false
237
+ // })
238
+ // }
239
+ wx.hideLoading()
240
+ },
241
+ fail: fail => {
242
+ console.log('getSession-fail', fail)
243
+ wx.hideLoading()
244
+ }
245
+ })
246
+ },
247
+
248
+ // 生命周期函数--监听页面显示
249
+ onShow: function () {
250
+ wx.hideShareMenu()
251
+
252
+ // 获取国籍
253
+ let pages = getCurrentPages()
254
+ let currentPage = pages[pages.length - 1]
255
+ let hadChoseNation = currentPage.data.hadChoseNation || false
256
+
257
+ if (hadChoseNation) {
258
+ let cid_type = currentPage.data.formData.cid_type
259
+ // 回传数据
260
+ this.reFullFormDataTemp(cid_type)
261
+ }
262
+ },
263
+
264
+ // 三证照:港澳通行证、台湾通行证、华侨护照
265
+ matchOptionsRule () {
266
+ let { cid_type, nation, sbSwitch } = this.data.formData
267
+ Nation = nation
268
+
269
+ if (cid_type === '516' || cid_type === '511' || cid_type === '414') {
270
+ if (nation !== 'CHN' && cid_type === '516') {
271
+ // 港澳通行证-外籍
272
+ this.setData({
273
+ rules: rulesConfig.HMPassRulesForeign('zh_CN')
274
+ })
275
+ } else if (sbSwitch) {
276
+ // 姓名、出生日期必填
277
+ this.setData({
278
+ rules: rulesConfig.HMORulesMore('zh_CN')
279
+ })
280
+ } else {
281
+ // 姓名、出生日期非必填
282
+ this.setData({
283
+ rules: rulesConfig.HMORules('zh_CN')
284
+ })
285
+ }
286
+ console.log('三证照正则', this.data.rules)
287
+ }
288
+ },
289
+
290
+ // 年龄≤18岁或年龄≥60岁的用户
291
+ isCarePeople(age) {
292
+ return age <= 18 || age >= 60
293
+ },
294
+
295
+ /**
296
+ * 获取/设置人脸失败次数
297
+ * @param {*} count
298
+ * count:true 设置次数+1
299
+ * count:false 获取次数
300
+ */
301
+ fetchFaceFailCount(count, errCode) {
302
+ const { id_card_number: cid } = this.data.formData
303
+ const age = utils.parseIDCard(cid).age
304
+ const isKidsOrOld = this.isCarePeople(age) || false
305
+ console.log('获取/设置人脸失败', count)
306
+ console.log('年龄', age)
307
+ console.log('是否是老人/小孩', isKidsOrOld)
308
+
309
+ this.setData({
310
+ isKidsOrOld
311
+ })
312
+
313
+ return new Promise((resolve, reject) => {
314
+ jingtongVerifyRequest.operateFaceFailCount({
315
+ count,
316
+ cid,
317
+ age
318
+ }).then(res => {
319
+ console.log('获取人脸失败次数res', res)
320
+ const times = Number(res.times) || 0
321
+
322
+ // 老人/小孩:累计刷脸失败6次后,弹长窗提示
323
+ if (count && isKidsOrOld && times === 6) {
324
+ console.log('==============老人/小孩 -- 累计刷脸失败6次:弹长窗===============')
325
+ this.setData({
326
+ showFaceModal: true
327
+ })
328
+ }
329
+
330
+ // 成人:累计刷脸失败3次后,弹长窗提示
331
+ if (count && !isKidsOrOld && times === 3) {
332
+ console.log('==============成人 -- 累计刷脸失败3次:弹长窗===============')
333
+ this.setData({
334
+ showFaceModal: true
335
+ })
336
+ }
337
+
338
+ // 老/小18次、成人6次 锁定人脸
339
+ if (isKidsOrOld && times >= 18) {
340
+ console.log('==============老人/小孩 -- 累计刷脸失败18次:弹短窗===============')
341
+ wx.hideLoading()
342
+ this.setData({
343
+ showLockFaceModal: true
344
+ })
345
+ // 人脸识别异常温馨提示弹窗
346
+ count && this.handleFaceError(errCode)
347
+ return
348
+ } else if (!isKidsOrOld && times >= 6) {
349
+ console.log('==============成人 -- 累计刷脸失败6次:弹短窗===============')
350
+ wx.hideLoading()
351
+ this.setData({
352
+ showLockFaceModal: true
353
+ })
354
+ // 人脸识别异常温馨提示弹窗
355
+ count && this.handleFaceError(errCode)
356
+ return
357
+ }
358
+ resolve()
359
+ }).catch(err => {
360
+ console.log(err, '获取人脸失败次数err')
361
+ wx.showToast({
362
+ title: '初始化有误,请稍后再试',
363
+ icon: 'none'
364
+ })
365
+ reject()
366
+ })
367
+ })
368
+ },
369
+
370
+ // 判断是否是PC端登录
371
+ getDevice() {
372
+ return new Promise((resolve, reject) => {
373
+ const systemInfo = wx.getDeviceInfo();
374
+ console.log('systemInfo', systemInfo)
375
+ if (['windows', 'mac'].includes(systemInfo.platform)) {
376
+ console.log('当前为电脑端微信');
377
+ wx.showToast({
378
+ title: '请您使用移动端京通小程序',
379
+ icon: 'none',
380
+ duration: 3000
381
+ })
382
+ return
383
+ } else {
384
+ console.log('当前为手机端');
385
+ resolve()
386
+ }
387
+ })
388
+ },
389
+
390
+ // 根据证件类型匹配校验正则和校验类型
391
+ toMatchRules() {
392
+ let { cid_type, nation, nation_name } = this.data.formData
393
+ let { rules, currentAuthType } = this.data.rulesMap[cid_type]
394
+ console.log('核验源', currentAuthType)
395
+ Nation = nation
396
+ // 默认【中国】
397
+ if (cid_type === '516' || cid_type === '511' || cid_type === '414') {
398
+ nation = 'CHN'
399
+ nation_name = 'CHN-中国'
400
+ }
401
+ this.setData({
402
+ rules,
403
+ currentAuthType,
404
+ 'formData.nation': nation,
405
+ 'formData.nation_name': nation_name,
406
+ }, () => {
407
+ wx.hideLoading()
408
+ })
409
+ console.log('匹配到的正则', rules, currentAuthType)
410
+ },
411
+
412
+ // 选择完国籍或认证失败后回传 -- 回传本地临时存储用户表单信息
413
+ reFullFormDataTemp(cid_type) {
414
+ const formDataTemp = wx.getStorageSync('tif.formDataTemp') || {}
415
+ let formDataOld = this.data.formData
416
+
417
+ if (formDataTemp && formDataTemp[cid_type]) {
418
+ console.log('存在可回填的temp数据', formDataTemp[cid_type])
419
+ let formData = Object.assign(formDataOld, formDataTemp[cid_type])
420
+ Nation = formData.nation
421
+ this.setData({
422
+ formData
423
+ })
424
+ }
425
+ // else if (cid_type === '516' && this.data.exitHmSession) {
426
+ // console.log('存在可回显的HM数据', this.data.HmSession)
427
+ // const { star_name, name, star_cid, cid, verify_expire_time, nation } = this.data.HmSession
428
+ // this.setData({
429
+ // 'formData.strName': star_name,
430
+ // 'formData.name': name,
431
+ // 'formData.strCid': star_cid,
432
+ // 'formData.id_card_number': cid,
433
+ // 'formData.verify_expire_time': verify_expire_time || '',
434
+ // 'formData.nation': nation
435
+ // })
436
+ // }
437
+ // 处理三证照的正则问题
438
+ this.matchOptionsRule()
439
+ },
440
+
441
+ // 同意协议和隐私政策
442
+ viewPrivacy(e) {
443
+ // 临时存储表单数据
444
+ this.saveFormDataTemp()
445
+ // 错误触发销毁回调函数处理
446
+ this.handleExitedState()
447
+
448
+ let canOpenPdf = this.data.canOpenPdf
449
+ if (canOpenPdf) {
450
+ this.setData({
451
+ canOpenPdf: false
452
+ })
453
+ let { name, file } = e.currentTarget.dataset
454
+ console.log('文件地址', `https://js.jt.beijing.gov.cn/jt/tiffile/${file}.pdf`)
455
+ utils.openDoc({
456
+ url: `https://js.jt.beijing.gov.cn/jt/tiffile/${file}.pdf`,
457
+ fileType: 'pdf',
458
+ name,
459
+ successFn: () => {
460
+ console.log('文档打开成功回调')
461
+ setTimeout(() => {
462
+ this.setData({
463
+ canOpenPdf: true
464
+ })
465
+ }, 500)
466
+ }
467
+ })
468
+ } else {
469
+ setTimeout(() => {
470
+ this.setData({
471
+ canOpenPdf: true
472
+ })
473
+ }, 3500)
474
+ }
475
+ },
476
+
477
+ // 选择事件
478
+ handleChange(e) {
479
+ let value = e.detail.value
480
+ let formId = e.target.id
481
+
482
+ // 删除前后空格
483
+ if (typeof value === 'string' && formId !== 'cid_type') {
484
+ value = value.trim()
485
+ console.log('==删除前后空格==', value, '==删除前后空格==')
486
+ }
487
+
488
+ let starId = e.target.dataset.star
489
+ // 切换“证件类型”
490
+ let oldCidType = this.data.formData.cid_type
491
+ if (formId === 'cid_type' && oldCidType !== value) {
492
+ cidType = value
493
+ wx.showLoading({
494
+ title: '加载中…',
495
+ })
496
+
497
+ // 若是港澳台,则证件类别默认为居住证核验
498
+ if (value == 17 || value == 18) {
499
+ this.setData({
500
+ currentAuthType: 'faceReceptionAuth',
501
+ rules: rulesConfig.residenceAuthRules('zh_CN')
502
+ })
503
+ }
504
+
505
+ // 语言环境
506
+ this.setData({
507
+ language: value === '700' ? 'en' : 'zh_CN'
508
+ })
509
+
510
+ // 临时存储用户填写的表单信息、是否需要回显
511
+ this.saveFormDataTemp(true, value, oldCidType)
512
+ } else {
513
+ // 临时存储表单数据
514
+ this.saveFormDataTemp()
515
+
516
+ this.setData({
517
+ [`formData.${formId}`]: value
518
+ })
519
+ if (starId) {
520
+ this.setData({
521
+ [`formData.${starId}`]: ''
522
+ })
523
+ }
524
+ }
525
+ },
526
+
527
+ // 临时存储用户填写的表单信息
528
+ saveFormDataTemp(needFull = false, newCidType = '', oldCidType = '') {
529
+ console.log('临时存储用户填写的表单信息', needFull, newCidType, oldCidType)
530
+ let {
531
+ formData
532
+ } = this.data
533
+
534
+ let formDataTemp = wx.getStorageSync('tif.formDataTemp') || {}
535
+ formDataTemp[formData.cid_type] = formData
536
+ wx.setStorageSync('tif.formDataTemp', formDataTemp)
537
+ if (needFull) {
538
+ // 是否需要回传
539
+ Nation = ''
540
+ this.setData({
541
+ formData: {
542
+ cid_type: newCidType,
543
+ name: '',
544
+ id_card_number: '',
545
+ bank_account: '',
546
+ nation: '',
547
+ nation_name: '',
548
+ sur_name: '',
549
+ first_name: '',
550
+ sex: '',
551
+ birthday: '',
552
+ cid_expire_date: '',
553
+ validity_period: '',
554
+ passport_number: '',
555
+ phone: '',
556
+ verify_expire_time: '',
557
+ sbSwitch: true,
558
+ agree: false,
559
+ isbind: 1
560
+ }
561
+ })
562
+ if (newCidType === '700') {
563
+ // 获取外国护照核验结果
564
+ this.fetchPassortAuthResult()
565
+ } else {
566
+ // 回传 Temp => Success => 空
567
+ this.restartInitChange(newCidType)
568
+ }
569
+ wx.hideLoading()
570
+ }
571
+ },
572
+
573
+ // 回传 Temp => Success => 空
574
+ restartInitChange(cid_type) {
575
+ console.log('根据证件类型匹配校验正则,回填本地Temp数据')
576
+ wx.showLoading({
577
+ title: '加载中…',
578
+ })
579
+ // 根据证件类型匹配校验正则
580
+ this.toMatchRules()
581
+ // 数据回传
582
+ this.reFullFormDataTemp(cid_type)
583
+ },
584
+
585
+ // 获取外国人护照核验结果、是否需要返回状态
586
+ fetchPassortAuthResult(needStatus = false) {
587
+ // 根据证件类型匹配校验正则
588
+ !needStatus && this.toMatchRules()
589
+ let formData = this.data.formData
590
+
591
+ return new Promise((resolve) => {
592
+ jingtongVerifyRequest.getPassportInfo({
593
+ success: res => {
594
+ console.log('外国人护照核验接口获取成功', res)
595
+
596
+ this.setData({
597
+ passportAuthStatus: res.status,
598
+ passportAuthPersonCode: res.person_code
599
+ })
600
+
601
+ if (needStatus) {
602
+ // 需要返回状态
603
+ resolve(res.status)
604
+ } else {
605
+ let {
606
+ id_card_number,
607
+ nation,
608
+ sur_name,
609
+ first_name,
610
+ sex,
611
+ birthday,
612
+ cid_expire_date,
613
+ phone,
614
+ verify_expire_time,
615
+ nation_name
616
+ } = res
617
+ let passportOldData = {
618
+ id_card_number,
619
+ nation,
620
+ nation_name,
621
+ sur_name,
622
+ first_name,
623
+ sex: sex ? sex : '',
624
+ birthday,
625
+ cid_expire_date,
626
+ phone,
627
+ verify_expire_time: verify_expire_time && Number(verify_expire_time) || ''
628
+ }
629
+ formData = Object.assign(formData, res, passportOldData)
630
+ Nation = nation
631
+ this.setData({
632
+ formData,
633
+ passportOldData
634
+ })
635
+ }
636
+ },
637
+ fail: err => {
638
+ console.log('外国人护照核验接口获取失败', err)
639
+ let { errmsg } = JSON.parse(err)
640
+ wx.showToast({
641
+ title: errmsg || '获取核验信息接口失败',
642
+ icon: 'none',
643
+ duration: 3000
644
+ })
645
+ }
646
+ })
647
+ })
648
+ },
649
+
650
+ // 选择国籍
651
+ handleNationTap() {
652
+ const cid_type = this.data.formData.cid_type
653
+ if (cid_type === '414') {
654
+ // 华侨护照
655
+ return
656
+ }
657
+ // 临时存储表单数据
658
+ this.saveFormDataTemp()
659
+
660
+ flow.navigateTo({
661
+ url: `../nation-list/nation-list?cid_type=${cid_type}`,
662
+ })
663
+ },
664
+
665
+ async handleFormSubmit(e) {
666
+ if (!e.detail.validStatus) {
667
+ return
668
+ }
669
+ wx.showLoading({
670
+ title: '加载中…',
671
+ mask: true
672
+ })
673
+
674
+ console.log('删除“姓名、证件号码、护照号码、手机号码”的前后空格')
675
+ let { name, id_card_number, sur_name, first_name, passport_number, phone, cid_type } = this.data.formData
676
+
677
+ this.setData({
678
+ ['formData.name']: name.trim(),
679
+ ['formData.sur_name']: sur_name.trim(),
680
+ ['formData.first_name']: first_name.trim(),
681
+ ['formData.passport_number']: passport_number.trim(),
682
+ ['formData.phone']: phone.trim(),
683
+ ['formData.id_card_number']: id_card_number.trim()
684
+ })
685
+
686
+ if (cid_type === '700') {
687
+ console.log('删除“外国人护照号码”中间空格')
688
+ this.setData({
689
+ ['formData.id_card_number']: id_card_number.replace(/\s+/g, '')
690
+ })
691
+ }
692
+
693
+ console.log('入参', this.data.formData)
694
+
695
+ let currentAuthType = this.data.currentAuthType
696
+ console.log('当前认证类型', currentAuthType)
697
+
698
+ if (currentAuthType === 'wxFace') {
699
+ console.log('微信人脸识别认证')
700
+
701
+ // 判断是否是PC端登录
702
+ await this.getDevice()
703
+
704
+ // 判断人脸失败次数
705
+ await this.fetchFaceFailCount(false)
706
+
707
+ // 错误触发销毁回调函数处理
708
+ this.handleExitedState()
709
+
710
+ // 开启人脸识别认证
711
+ this.toFaceVerify()
712
+ } else if (currentAuthType === 'faceReceptionAuth') {
713
+ console.log('出入境微信人脸识别接口认证')
714
+ // 错误触发销毁回调函数处理
715
+ this.handleExitedState()
716
+
717
+ // 判断是否是PC端登录
718
+ await this.getDevice()
719
+
720
+ // 出入境微信人脸识别接口
721
+ this.toFaceReceptionAuth()
722
+ } else if(currentAuthType === 'cardAuth') {
723
+ console.log('银行卡接口认证')
724
+ // 银行卡身份核验接口
725
+ this.bankCardAuth()
726
+ } else if(currentAuthType === 'ForeignPassortAuth') {
727
+ console.log('外国人护照核验')
728
+ // 外国人护照核验
729
+ this.handlePassortAuth()
730
+ }
731
+ },
732
+
733
+ // 开启人脸识别认证
734
+ async toFaceVerify() {
735
+ const [err, session] = await utils.awaitTo(jingtongVerifyRequest.faceVerifyWithIdCard(this.data.formData))
736
+
737
+ const cidType = this.data.formData.cid_type
738
+
739
+ if (err) {
740
+ // 埋点上报事件:刷脸认证
741
+ this.faceTracker(2, cidType)
742
+
743
+ // 埋点上报事件:自然人登录
744
+ this.loginTracker(3, cidType)
745
+
746
+ console.log('微信人脸识别失败', err)
747
+ let { errmsg, errMsg, errCode } = JSON.parse(err)
748
+ if (errCode) {
749
+ let errCodeArr = [10002, 10003, 10004, 10005, 10012, 10057, 90002, 90003, 90004, 90005, 90006, 90100, 90023, 90024, 90025]
750
+ if (errCodeArr.indexOf(errCode) >= 0) {
751
+ console.log('在指定的错误码范围内,人脸失败次数+1')
752
+ // 设置人脸失败次数
753
+ await this.fetchFaceFailCount(true, errCode)
754
+ }
755
+ // 人脸识别异常温馨提示弹窗
756
+ this.handleFaceError(errCode)
757
+ }
758
+
759
+ if (errCode && errCode === 90100) {
760
+ wx.showToast({
761
+ title: '您已取消人脸识别',
762
+ icon: 'none',
763
+ duration: 3000
764
+ })
765
+ } else if (errCode && errCode === 10004) {
766
+ wx.showToast({
767
+ title: '人脸与身份信息不匹配',
768
+ icon: 'none',
769
+ duration: 3000
770
+ })
771
+ } else if (errCode && errCode === 10003) {
772
+ wx.showToast({
773
+ title: '姓名或证件号码有误',
774
+ icon: 'none',
775
+ duration: 3000
776
+ })
777
+ } else {
778
+ wx.showToast({
779
+ title: errmsg || errMsg || '认证失败,请稍后再试',
780
+ icon: 'none',
781
+ duration: 3000
782
+ })
783
+ }
784
+ } else {
785
+ // 埋点上报事件:刷脸认证
786
+ this.faceTracker(1, cidType)
787
+
788
+ console.log('认证成功返回页面数据:', session)
789
+ // 保存刷脸成功时间戳
790
+ let timeStamp = new Date().getTime()
791
+ wx.setStorageSync('tif.faceTimeStamp', timeStamp)
792
+
793
+ this.authSuccess(session)
794
+ }
795
+ },
796
+
797
+ // 人脸识别异常温馨提示弹窗
798
+ handleFaceError(code) {
799
+ let errCode1 = [10009, 10026, 10032, 10072, 10076, 10084, 10086, 10089, 10092, 10049, 10107, 10095]
800
+ let errCode2 = [10002, 10004, 10005, 10010, 10012, 10027, 10028, 10057]
801
+ if (errCode1.indexOf(code) >= 0) {
802
+ // 1: 未办理过身份证/新办理身份证的
803
+ this.setData({
804
+ faceErrorModal: true,
805
+ faceErrorType: '1'
806
+ })
807
+ } else if (errCode2.indexOf(code) >= 0) {
808
+ const age = utils.parseIDCard(this.data.formData.id_card_number).age
809
+ console.log('年龄', age)
810
+ if (age >= 60) {
811
+ // 3: 刷脸没刷过,60岁以上的
812
+ this.setData({
813
+ faceErrorModal: true,
814
+ faceErrorType: '3'
815
+ })
816
+ } else {
817
+ // 2: 刷脸没刷过,60岁以下的
818
+ this.setData({
819
+ faceErrorModal: true,
820
+ faceErrorType: '2'
821
+ })
822
+ }
823
+ }
824
+ },
825
+
826
+ // 出入境微信人脸识别接口
827
+ async toFaceReceptionAuth() {
828
+ // 临时存储表单数据
829
+ this.saveFormDataTemp()
830
+
831
+ // 数据加密
832
+ const [err, res] = await utils.awaitTo(jingtongVerifyRequest.caEncrypt(this.data.formData))
833
+ if (err) {
834
+ console.log('CA加密失败', err)
835
+ let { errmsg } = JSON.parse(err)
836
+ wx.showToast({
837
+ title: errmsg || 'CA加密失败,请重试',
838
+ icon: 'none',
839
+ duration: 3500
840
+ })
841
+ } else {
842
+ wx.hideLoading()
843
+ console.log('CA加密成功:', res)
844
+ this.toFaceReceptionVerify(res.user_id_key)
845
+ }
846
+ },
847
+
848
+ // 开启出入境微信人脸识别认证
849
+ async toFaceReceptionVerify(userIdKey) {
850
+ const params = Object.assign(this.data.formData, {
851
+ userIdKey
852
+ })
853
+ const { cid_type } = this.data.formData
854
+ const [err, session] = await utils.awaitTo(jingtongVerifyRequest.faceVerifyWithUserIdKey(params))
855
+ if (err) {
856
+ console.log('出入境-微信人脸识别失败', err)
857
+
858
+ // 埋点上报事件:刷脸认证
859
+ this.faceTracker(2, cid_type)
860
+
861
+ // 埋点上报事件:自然人登录
862
+ this.loginTracker(3, cid_type)
863
+
864
+ try {
865
+ let { errmsg = '', errMsg = '', errCode = '' } = JSON.parse(err) || ''
866
+ if (errCode && errCode === 90100) {
867
+ wx.showToast({
868
+ title: '您已取消人脸识别',
869
+ icon: 'none',
870
+ duration: 3000
871
+ })
872
+ } else if (errCode && errCode === 10004) {
873
+ wx.showToast({
874
+ title: '人脸与身份信息不匹配',
875
+ icon: 'none',
876
+ duration: 3000
877
+ })
878
+ } else if (errCode && errCode === 10003) {
879
+ wx.showToast({
880
+ title: '姓名或证件号码有误',
881
+ icon: 'none',
882
+ duration: 3000
883
+ })
884
+ } else if (errCode && errCode === 10111 && (cid_type === '17' || cid_type === '18')) {
885
+ // 若是“港澳台居住证”且错误码是10111,则触发银行卡核验
886
+ this.setData({
887
+ showCardModal: true
888
+ })
889
+ } else {
890
+ wx.showToast({
891
+ title: errmsg || errMsg || '认证失败,请稍后再试',
892
+ icon: 'none',
893
+ duration: 3000
894
+ })
895
+ }
896
+ } catch {
897
+ wx.showToast({
898
+ title: '人脸识别不支持电脑端,请使用真机',
899
+ icon: 'none',
900
+ duration: 3000
901
+ })
902
+ }
903
+ } else {
904
+ // 埋点上报事件:刷脸认证
905
+ this.faceTracker(1, cid_type)
906
+
907
+ console.log('认证成功返回页面数据:', session)
908
+ this.authSuccess(session)
909
+ }
910
+ },
911
+
912
+ // 港澳台居住证核验接口
913
+ async HmtResidenceAuth() {
914
+ const [err, session] = await utils.awaitTo(jingtongVerifyRequest.residenceAuth(this.data.formData))
915
+ if (err) {
916
+ console.log('港澳台居住证核验接口认证失败', err)
917
+ let { errmsg, errcode } = JSON.parse(err)
918
+ if (errcode == 4048) {
919
+ this.setData({
920
+ showCardModal: true
921
+ })
922
+ } else {
923
+ wx.showToast({
924
+ title: errmsg || '认证失败',
925
+ icon: 'none',
926
+ duration: 3000
927
+ })
928
+ }
929
+ } else {
930
+ console.log('认证成功返回页面数据:', session)
931
+ this.authSuccess(session)
932
+ }
933
+ },
934
+
935
+ // 银行卡身份核验接口
936
+ async bankCardAuth() {
937
+ const [err, session] = await utils.awaitTo(jingtongVerifyRequest.bankCardAuth(this.data.formData))
938
+ if (err) {
939
+ // 埋点上报事件:自然人登录
940
+ this.loginTracker(2, this.data.formData.cid_type)
941
+
942
+ console.log('银行卡身份核验接口认证失败', err)
943
+ let { errmsg } = JSON.parse(err)
944
+ wx.showToast({
945
+ title: errmsg || '认证失败',
946
+ icon: 'none',
947
+ duration: 3000
948
+ })
949
+ } else {
950
+ console.log('认证成功返回页面数据:', session)
951
+ this.authSuccess(session)
952
+ }
953
+ },
954
+
955
+ // 外国人护照核验处理逻辑
956
+ handlePassortAuth() {
957
+ let authStatus = this.data.passportAuthStatus
958
+ let newData = this.data.formData
959
+ let oldData = this.data.passportOldData
960
+
961
+ console.log('当前核验单状态', authStatus)
962
+
963
+ if (!authStatus) {
964
+ console.log('无审核单', authStatus)
965
+ // 外国人护照核验,提交核验单
966
+ this.passportAuth()
967
+ } else {
968
+ // 查上一单的状态
969
+ this.fetchPassortAuthResult(true).then(status => {
970
+ console.log('====查上一单的状态====', status)
971
+ if (status === '1') {
972
+ // 核验通过,弹窗提示
973
+ console.log('外国人护照核验通过')
974
+ this.passportAuthSuccess()
975
+ } else {
976
+ // 比对表单数据是否有修改
977
+ console.log('新旧表单数据比对', newData, oldData)
978
+ if (utils.objIsEqual(newData, oldData)) {
979
+ console.log('表单数据没有修改')
980
+ if (status === '4') {
981
+ // 核验中
982
+ this.fetchPassortAuthResult(true).then(status => {
983
+ console.log('再次获取外国人护照核验状态', status)
984
+ if (status === '1') {
985
+ console.log('外国人护照核验通过')
986
+ this.passportAuthSuccess()
987
+ } else if (status === '4') {
988
+ console.log('外国人护照核验中,弹窗提示')
989
+ this.handleShowModal(status)
990
+ } else {
991
+ // 核验不通过,弹窗提示
992
+ this.passportAuthFail(status)
993
+ }
994
+ })
995
+ } else {
996
+ // 核验不通过,弹窗提示
997
+ this.passportAuthFail(status)
998
+ }
999
+ } else {
1000
+ console.log('表单数据存在修改')
1001
+ // 外国人护照核验,提交核验单
1002
+ this.passportAuth()
1003
+ }
1004
+ }
1005
+ })
1006
+ }
1007
+ },
1008
+
1009
+ // 外国人护照核验不通过逻辑
1010
+ passportAuthFail(status) {
1011
+ console.log('===外国人护照核验不通过,弹窗提示===')
1012
+ // 判断当前person_code是否已失效
1013
+ const personCode = this.data.passportAuthPersonCode
1014
+ const localPersonCode = wx.getStorageSync('tif.fail.person_code') || ''
1015
+ if (personCode === localPersonCode) {
1016
+ // 提交核验单
1017
+ this.passportAuth()
1018
+ } else {
1019
+ // 埋点上报事件:自然人登录
1020
+ this.loginTracker(2, this.data.formData.cid_type)
1021
+
1022
+ this.handleShowModal(status)
1023
+ // 记录这个person_code是失效的
1024
+ wx.setStorageSync('tif.fail.person_code', this.data.passportAuthPersonCode)
1025
+ }
1026
+ },
1027
+
1028
+ // 外国人护照核验接口
1029
+ async passportAuth() {
1030
+ console.log('===========提交核验单============')
1031
+ let formData = this.data.formData
1032
+
1033
+ const isLegalDate = utils.greaterCurrentTime(formData.cid_expire_date)
1034
+ console.log('isLegalDate', isLegalDate)
1035
+ if (!isLegalDate) {
1036
+ console.log('护照有效期日期不合法')
1037
+ wx.showToast({
1038
+ title: 'Please select the passport expiration date',
1039
+ icon: 'none',
1040
+ duration: 3000
1041
+ })
1042
+ this.setData({
1043
+ 'formData.cid_expire_date': ''
1044
+ })
1045
+ return
1046
+ }
1047
+
1048
+ const [err, res] = await utils.awaitTo(jingtongVerifyRequest.passportAuth(formData))
1049
+ if (err) {
1050
+ console.log('外国人护照核验接口认证失败', err)
1051
+ let { errmsg } = JSON.parse(err)
1052
+ wx.showToast({
1053
+ title: errmsg || '认证失败',
1054
+ icon: 'none',
1055
+ duration: 3000
1056
+ })
1057
+ return
1058
+ }
1059
+ console.log('弹窗提示等待10分钟', res)
1060
+ this.setData({
1061
+ passportAuthStatus: '4',
1062
+ passportOldData: JSON.parse(JSON.stringify(formData)),
1063
+ passportAuthPersonCode: ''
1064
+ })
1065
+ wx.setStorageSync('tif.fail.person_code', '')
1066
+ this.handleShowModal('4')
1067
+ },
1068
+
1069
+ // 外国人护照核验通过
1070
+ passportAuthSuccess() {
1071
+ // 调用删除接口/静默登录并返回session信息
1072
+ jingtongVerifyRequest.deletePassportAuth({
1073
+ success: session => {
1074
+ console.log('返回session信息', session)
1075
+
1076
+ // 删除缓存信息
1077
+ console.log('删除缓存信息')
1078
+ let formDataTemp = wx.getStorageSync('tif.formDataTemp')
1079
+ formDataTemp['700'] = {}
1080
+ wx.setStorageSync('tif.formDataTemp', formDataTemp)
1081
+ this.setData({
1082
+ passportOldData: {}
1083
+ })
1084
+
1085
+ this.authSuccess(session, true)
1086
+ },
1087
+ fail: err => {
1088
+ // 埋点上报事件:自然人登录
1089
+ this.loginTracker(2, this.data.formData.cid_type)
1090
+
1091
+ let { errmsg } = JSON.parse(err)
1092
+ wx.showToast({
1093
+ title: errmsg || 'auth fail',
1094
+ icon: 'none',
1095
+ duration: 3000
1096
+ })
1097
+ }
1098
+ })
1099
+ },
1100
+
1101
+ // 认证成功后续操作
1102
+ authSuccess(session, isEn = false) {
1103
+ console.log('====判断是否真的登录成功=====')
1104
+ if (!session) {
1105
+ wx.showToast({
1106
+ title: '登录态失效,请重试',
1107
+ icon: 'none',
1108
+ duration: 2000
1109
+ })
1110
+ return
1111
+ }
1112
+ const { face_time, realname_time, cid, has_phone, certType } = session
1113
+ if ((!face_time && !realname_time) || !cid) {
1114
+ wx.showToast({
1115
+ title: `登录态失效请重试: ${this.data.formData.cid_type}`,
1116
+ icon: 'none',
1117
+ duration: 2000
1118
+ })
1119
+ return
1120
+ }
1121
+
1122
+ wx.showToast({
1123
+ title: isEn ? 'Verification successful, redirecting...': '验证成功, 跳转中…',
1124
+ icon: 'none',
1125
+ duration: 5000,
1126
+ mask: true
1127
+ })
1128
+
1129
+ const cidType = session.cid_type
1130
+
1131
+ // 本地存储表单核验成功数据
1132
+ wx.setStorageSync('tif.formDataSuccess', this.data.formData)
1133
+
1134
+ // 将弹窗标识设置为不需要弹窗
1135
+ jingtongVerifyRequest.setUserReadStatus(false).then(() => {
1136
+ console.log('设置弹窗标识成功')
1137
+ }).catch(err => {
1138
+ console.log('设置弹窗标识失败', err)
1139
+ })
1140
+
1141
+ setTimeout(() => {
1142
+ if (this.data.needUnite === "true") {
1143
+ // this.setData({
1144
+ // needUnite: ''
1145
+ // })
1146
+
1147
+ console.log('进入业务总入口, 判断是否有手机号码', has_phone)
1148
+
1149
+ // 登录成功回调 => 业务侧操作事项
1150
+ wx.$_ServiceConfiguration && wx.$_ServiceConfiguration.methods && wx.$_ServiceConfiguration.methods._loginSuccessCallBack && wx.$_ServiceConfiguration.methods._loginSuccessCallBack(session)
1151
+
1152
+ if (has_phone) {
1153
+ const realPhone = wx.getStorageSync('tif.realPhone') || ''
1154
+ const caPhone = wx.getStorageSync('tif.caPhone') || ''
1155
+ const confirmTime = wx.getStorageSync('tif.tel_confirm_time') || ''
1156
+
1157
+ console.log('realPhone', realPhone)
1158
+ console.log('caPhone', caPhone)
1159
+ console.log('confirmTime', confirmTime)
1160
+
1161
+ if (realPhone !== caPhone && confirmTime && (!utils.completeDate(new Date(Number(confirmTime + '000')), 6))) {
1162
+ // 埋点上报事件:自然人登录
1163
+ this.loginTracker(1, cidType)
1164
+
1165
+ this.setData({
1166
+ hadSuccessLogin: true
1167
+ })
1168
+
1169
+ // 【phone与caPhone不同】且【tel_confirm_time大于6个月】
1170
+ // 数据库手机号码有效期大于6个月
1171
+ flow.redirectTo({
1172
+ url: '../confirm-phone/confirm-phone'
1173
+ })
1174
+ } else {
1175
+ jingtongVerifyRequest.personToken({
1176
+ source: '11'
1177
+ }).then(async data => {
1178
+ // 设置用户账号信息
1179
+ setAccountInfo(session.openid)
1180
+
1181
+ // 埋点上报事件:自然人登录
1182
+ this.loginTracker(1, cidType)
1183
+
1184
+ this.setData({
1185
+ hadSuccessLogin: true
1186
+ })
1187
+
1188
+ // 埋点 - 个人用户实体全属性上报
1189
+ let last_login_time = utils.getCurrentTime()
1190
+ wx.setStorageSync('tif.lastLoginTime', last_login_time)
1191
+ const userEntityReportData = Object.assign(session, {
1192
+ user_status: '1',
1193
+ last_login_time,
1194
+ user_date_of_birth: session.cid_type === '111' ? utils.getBirthByIDCard(session.cid) : ''
1195
+ })
1196
+ await utils.awaitTo(jingtongVerifyRequest.userEntityReport(userEntityReportData))
1197
+
1198
+ setTimeout(() => {
1199
+ flow.resolve({
1200
+ token: data
1201
+ })
1202
+ }, 1200)
1203
+ })
1204
+ }
1205
+ } else {
1206
+ // 埋点上报事件:自然人登录
1207
+ this.loginTracker(1, cidType)
1208
+
1209
+ this.setData({
1210
+ hadSuccessLogin: true
1211
+ })
1212
+
1213
+ flow.redirectTo({
1214
+ url: '../bind-phone/bind-phone?source=3'
1215
+ })
1216
+ }
1217
+ } else {
1218
+ console.log('返回主包')
1219
+ flow.resolve()
1220
+ }
1221
+ }, 800)
1222
+ },
1223
+
1224
+ // 埋点上报事件:刷脸认证
1225
+ faceTracker(recognition_status = 1, cidType) {
1226
+ SDKTrack('face_recognition_login', {
1227
+ recognition_status, // 1: 人脸识别成功 2:人脸识别失败
1228
+ login_certificate: this.data.certTypeMap[cidType] || 1, // 证件类型
1229
+ invoke_location: '' // 调起位置
1230
+ })
1231
+ },
1232
+
1233
+ // 埋点上报事件:自然人登录
1234
+ loginTracker(login_status = 1, cidType) {
1235
+ SDKTrack('nature_person_login', {
1236
+ // 1 登录成功;2 登录失败-身份信息核验失败;3 登录失败-人脸核验失败
1237
+ // 4 登录失败-电子营业执照核验失败;5 登录失败-账号密码输入错误
1238
+ // 6 取消登录(包含点击温馨提示的“取消”,点击请法人登录的×,在登录页面点击左上角返回按钮退出登录)
1239
+ // 7 退出小程序终止登录;old_1 历史数据:除登录成功之外的所有情况
1240
+ login_status,
1241
+ login_certificate: this.data.certTypeMap[cidType] || 1, // 证件类型
1242
+ invoke_location: '', // 调起位置
1243
+ login_validity_period: this.data.formData.verify_expire_time / 24 || '' // 免登录时间
1244
+ })
1245
+ },
1246
+
1247
+ // 显示弹窗
1248
+ handleShowModal(status) {
1249
+ let modalStatus = ''
1250
+ if (status === '3') {
1251
+ // 未找到信息
1252
+ modalStatus = 'warning'
1253
+ } else if (status === '4') {
1254
+ // 核验中
1255
+ modalStatus = 'info'
1256
+ } else {
1257
+ // 信息有误
1258
+ modalStatus = 'error'
1259
+ }
1260
+ this.setData({
1261
+ modalStatus,
1262
+ showModal: true
1263
+ },() => {
1264
+ wx.hideLoading()
1265
+ })
1266
+ },
1267
+
1268
+ // modal确认事件
1269
+ handleModalOk() {
1270
+ // this.fetchPassortAuthResult()
1271
+ this.setData({
1272
+ showModal: false,
1273
+ showFaceModal: false,
1274
+ showLockFaceModal: false,
1275
+ showCardModal: false,
1276
+ showTipModal: false
1277
+ })
1278
+ },
1279
+
1280
+ // 调起银行卡认证
1281
+ toCardAuth() {
1282
+ console.log('====调起银行卡认证====')
1283
+ this.setData({
1284
+ currentAuthType: 'cardAuth',
1285
+ rules: rulesConfig.cardRules('zh_CN'),
1286
+ showCardModal: false
1287
+ })
1288
+ },
1289
+
1290
+ // 触发问号弹出
1291
+ showQuestionTip() {
1292
+ this.setData({
1293
+ showTipModal: true
1294
+ })
1295
+ },
1296
+
1297
+ onUnload: function() {
1298
+ // 页面卸载时的逻辑处理
1299
+ console.log('======页面即将卸载======', this.data.hadSuccessLogin);
1300
+ if (!this.data.hadSuccessLogin) {
1301
+ // 埋点上报事件:自然人登录
1302
+ this.loginTracker(6, this.data.formData.cid_type)
1303
+ }
1304
+ },
1305
+
1306
+ // 有些操作程序会触发销毁回调函数,该操作不是真正的小程序销毁操作
1307
+ handleExitedState() {
1308
+ this.setData({
1309
+ exitedState: false
1310
+ })
1311
+ setTimeout(() => {
1312
+ this.setData({
1313
+ exitedState: true
1314
+ })
1315
+ }, 2000)
1316
+ },
1317
+
1318
+ onSaveExitState: function() {
1319
+ // 小程序可能被销毁之前的逻辑处理
1320
+ if (!this.data.hadSuccessLogin && this.data.exitedState) {
1321
+ console.log('======小程序可能被销毁======')
1322
+ // 埋点上报事件:自然人登录
1323
+ this.loginTracker(7, this.data.formData.cid_type)
1324
+ }
1325
+ },
1326
+
1327
+ // 关闭 - 扫脸失败温馨提示弹窗
1328
+ cancelFaceErrorModal() {
1329
+ this.setData({
1330
+ faceErrorModal: false
1331
+ })
1332
+ },
1333
+
1334
+ // 扫脸失败温馨提示弹窗-跳转到失败原因
1335
+ okFaceErrorModal() {
1336
+ this.setData({
1337
+ faceErrorModal: false
1338
+ })
1339
+ flow.navigateTo({
1340
+ url: `../face-error-reason/face-error-reason?type=${this.data.faceErrorType}`,
1341
+ })
1342
+ },
1343
+
1344
+ openEye(e) {
1345
+ console.log(e)
1346
+ const isOpen = e.detail.isOpen
1347
+ const key = e.currentTarget.id
1348
+ const strKey = e.currentTarget.dataset.star
1349
+ console.log('isOpen', isOpen)
1350
+ console.log('key', key)
1351
+ console.log('strKey', strKey)
1352
+ if (isOpen) {
1353
+ console.log('显示脱敏')
1354
+ const { name, id_card_number } = this.data.formData
1355
+ const value = key === 'name' ? utils.hideName(name) : utils.hideIdCard(id_card_number, '111')
1356
+ console.log('value', value)
1357
+ this.setData({
1358
+ [`formData.${strKey}`]: value
1359
+ })
1360
+ } else {
1361
+ console.log('删除脱敏,显示明文')
1362
+ this.setData({
1363
+ [`formData.${strKey}`]: ''
1364
+ })
1365
+ }
1366
+ },
1367
+
1368
+ handleChangeSwtich(e) {
1369
+ this.setData({
1370
+ ['formData.sbSwitch']: e.detail.value
1371
+ })
1372
+ // 处理三证照的正则问题
1373
+ this.matchOptionsRule()
1374
+ },
1375
+
1376
+ // 隐藏提示
1377
+ closeForeignTip() {
1378
+ wx.setStorageSync('tif.hideForeignTip', '1')
1379
+ this.setData({
1380
+ showForeignTip: false
1381
+ })
1382
+ }
1287
1383
  })