authentication.vue 5.7 KB

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