authentication.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <view class="container">
  3. <view class="notes">拍摄您本人人脸,确保对准手机,光线充足</view>
  4. <view class="msg">{{ name }} {{ cardNumber }}</view>
  5. <view class="photo"><img src="../../static/imgs/headImage.png" /></view>
  6. <view class="button" @click="handleTakePhotoClick">拍摄人脸开启身份认证</view>
  7. <!-- 认证结果弹窗 -->
  8. <uni-popup ref="popup" :is-mask-click="false">
  9. <view class="popup-content">
  10. <view class="title">
  11. <view class="icon"><img src="./imgs/success.png" /></view>
  12. <view class="title_info">打卡成功</view>
  13. </view>
  14. <view class="time">{{ nowTime }}</view>
  15. <view class="popup_button" @click="handleGoHome">我知道了</view>
  16. </view>
  17. </uni-popup>
  18. </view>
  19. </template>
  20. <script>
  21. import { encrypt, decrypt } from '@/util/encryp.js'
  22. import { RSAencrypt } from '@/util/jsencrypt.js'
  23. export default {
  24. data() {
  25. return {
  26. // 当前时间
  27. nowTime: '',
  28. // 场景照片
  29. sceneImage: '',
  30. // 经纬度
  31. lat: '',
  32. lng: '',
  33. // 地址
  34. location: '',
  35. // 规则id
  36. id: '',
  37. // 姓名
  38. name: '',
  39. // 学号
  40. cardNumber: '',
  41. // 身份证号
  42. idCard: '',
  43. // 是否需要场景照片,值为1时是不需要
  44. flag: ''
  45. }
  46. },
  47. onLoad(options) {
  48. let userInfo = uni.getStorageSync('clockIn_userInfo')
  49. if (userInfo) {
  50. this.name = userInfo.name
  51. this.cardNumber = userInfo.cardNumber
  52. this.idCard = userInfo.idCard
  53. }
  54. this.id = options.id
  55. this.lat = options.latitude
  56. this.lng = options.longitude
  57. this.location = options.address
  58. if (options.imgUrl) {
  59. this.sceneImage = options.imgUrl
  60. }
  61. if (options.flag) {
  62. this.flag = options.flag
  63. }
  64. },
  65. methods: {
  66. // 拍摄人脸开启身份认证按钮回调
  67. handleTakePhotoClick() {
  68. uni.chooseImage({
  69. count: 1,
  70. sizeType: ['compressed'],
  71. sourceType: ['camera'],
  72. success: res => {
  73. // console.log(res);
  74. uni.showLoading({
  75. title: '上传中',
  76. mask: true
  77. })
  78. uni.uploadFile({
  79. url: `https://chtech.ncjti.edu.cn/campusclock/attendance/api/file/upload`,
  80. filePath: res.tempFilePaths[0],
  81. name: 'file',
  82. header: {
  83. platform: 2,
  84. 'Accept-Language': 'zh-CN,zh;q=0.9'
  85. },
  86. success: uploadFileRes => {
  87. let imgUrl = JSON.parse(uploadFileRes.data).data
  88. // console.log(imgUrl)
  89. this.handleEncrypt(imgUrl)
  90. },
  91. fail: () => {
  92. uni.showToast({
  93. title: '上传失败',
  94. icon: 'error'
  95. })
  96. }
  97. })
  98. }
  99. })
  100. },
  101. // 对比人脸请求
  102. handleEncrypt(imgUrl) {
  103. uni.showLoading({
  104. title: '认证中',
  105. mask: true
  106. })
  107. uni.request({
  108. url: '/testingServer/faceVerification/api/identity-comparison-record/comparison',
  109. method: 'post',
  110. data: {
  111. data: RSAencrypt(
  112. encrypt(
  113. JSON.stringify({
  114. url: imgUrl,
  115. name: this.name,
  116. // name: '周祥',
  117. idCard: this.idCard,
  118. category: '校园打卡',
  119. studentNumber: this.cardNumber
  120. })
  121. )
  122. )
  123. },
  124. success: res => {
  125. if (res.data.status == 200) {
  126. let result = JSON.parse(decrypt(res.data.authorization))
  127. // console.log(result)
  128. if (result.status == 200) {
  129. uni.showToast({
  130. title: result.desc
  131. })
  132. setTimeout(() => {
  133. this.handleUploading(imgUrl)
  134. }, 1500)
  135. } else {
  136. uni.showToast({
  137. title: `${result.desc},请重新认证`,
  138. icon: 'error',
  139. duration: 2000
  140. })
  141. }
  142. }
  143. }
  144. })
  145. },
  146. // 打卡请求
  147. async handleUploading(imgUrl) {
  148. let res = await this.$myRequest_clockIn({
  149. url: '/attendance/api/sign/check/in/update',
  150. method: 'put',
  151. header: {
  152. 'content-type': 'application/json'
  153. },
  154. data: {
  155. id: this.id,
  156. lat: this.lat,
  157. lng: this.lng,
  158. location: this.location,
  159. matchFaceImage: imgUrl,
  160. sceneImage: this.flag == 1 ? '' : this.sceneImage
  161. }
  162. })
  163. // console.log(res);
  164. if (res.code == 200) {
  165. this.getNowTime()
  166. this.$refs.popup.open()
  167. }
  168. },
  169. // 点击 我知道了按钮 跳回首页
  170. handleGoHome() {
  171. this.$refs.popup.close()
  172. uni.reLaunch({
  173. url: '/pages/home/home'
  174. })
  175. },
  176. // 获取当前时间
  177. getNowTime() {
  178. let date = new Date()
  179. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  180. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  181. let seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  182. this.nowTime = hours + ':' + minutes + ':' + seconds
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. .container {
  189. .notes {
  190. margin-top: 110rpx;
  191. text-align: center;
  192. font-size: 28rpx;
  193. }
  194. .msg {
  195. margin-top: 10rpx;
  196. text-align: center;
  197. font-size: 28rpx;
  198. }
  199. .info {
  200. margin-top: 100rpx;
  201. height: 40rpx;
  202. text-align: center;
  203. color: #5393ff;
  204. }
  205. .photo {
  206. margin: 0 auto;
  207. margin-top: 60rpx;
  208. width: 375rpx;
  209. height: 375rpx;
  210. border-radius: 188rpx;
  211. overflow: hidden;
  212. .img {
  213. width: 100%;
  214. height: 100%;
  215. border-radius: 50%;
  216. }
  217. img {
  218. width: 100%;
  219. height: 100%;
  220. }
  221. }
  222. .button {
  223. margin: 0 auto;
  224. margin-top: 127rpx;
  225. width: 430rpx;
  226. height: 100rpx;
  227. line-height: 100rpx;
  228. text-align: center;
  229. color: #fff;
  230. border-radius: 21rpx;
  231. font-size: 32rpx;
  232. background: linear-gradient(180deg, rgba(0, 172, 252, 1) 0%, rgba(0, 130, 252, 1) 100%);
  233. }
  234. .popup-content {
  235. display: flex;
  236. flex-direction: column;
  237. justify-content: space-around;
  238. align-items: center;
  239. width: 630rpx;
  240. height: 376rpx;
  241. border-radius: 33rpx;
  242. background-color: #fff;
  243. .title {
  244. display: flex;
  245. justify-content: center;
  246. align-items: center;
  247. .icon {
  248. width: 40rpx;
  249. height: 40rpx;
  250. img {
  251. width: 100%;
  252. height: 100%;
  253. }
  254. }
  255. .title_info {
  256. margin-left: 8rpx;
  257. font-size: 36rpx;
  258. font-weight: 800;
  259. color: #0082fc;
  260. }
  261. }
  262. .time {
  263. font-size: 32rpx;
  264. }
  265. .popup_button {
  266. width: 50%;
  267. text-align: center;
  268. font-size: 32rpx;
  269. color: #0082fc;
  270. }
  271. }
  272. }
  273. </style>