authentication.vue 5.8 KB

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