soter.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <view>
  3. <page-head :title="title"></page-head>
  4. <view class="uni-padding-wrap uni-common-mt">
  5. <view class="uni-btn-v">
  6. <button type="primary" @click="checkIsSupportSoterAuthentication">检查支持的认证方式</button>
  7. <button type="primary" @click="checkIsSoterEnrolledInDeviceFingerPrint">检查是否录入指纹</button>
  8. <button type="primary" @click="checkIsSoterEnrolledInDeviceFaceID">检查是否录入FaceID</button>
  9. <button type="primary" @click="startSoterAuthenticationFingerPrint">开始指纹认证</button>
  10. <button type="primary" @click="startSoterAuthenticationFaceID">开始FaceID认证</button>
  11. </view>
  12. <view style="width: 100%;text-align: center;">{{ result }}</view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. title: '生物认证',
  21. result: ''
  22. };
  23. },
  24. onLoad() {
  25. },
  26. methods: {
  27. checkIsSupportSoterAuthentication() {
  28. uni.checkIsSupportSoterAuthentication({
  29. success(res) {
  30. uni.showModal({
  31. content: '支持的认证方式:' + res.supportMode,
  32. showCancel: false
  33. })
  34. console.log(res);
  35. },
  36. fail(err) {
  37. console.log(err);
  38. }
  39. })
  40. },
  41. checkIsSoterEnrolledInDeviceFingerPrint() {
  42. uni.checkIsSoterEnrolledInDevice({
  43. checkAuthMode: 'fingerPrint',
  44. success(res) {
  45. if(res.isEnrolled) {
  46. uni.showToast({
  47. icon: 'none',
  48. title: '已录入指纹'
  49. })
  50. }else {
  51. uni.showModal({
  52. content: '未录入指纹',
  53. showCancel: false
  54. })
  55. }
  56. console.log(res);
  57. },
  58. fail(err) {
  59. uni.showModal({
  60. content: '未录入指纹',
  61. showCancel: false
  62. })
  63. console.log(err);
  64. }
  65. })
  66. },
  67. checkIsSoterEnrolledInDeviceFaceID() {
  68. uni.checkIsSoterEnrolledInDevice({
  69. checkAuthMode: 'facial',
  70. success(res) {
  71. if(res.isEnrolled) {
  72. uni.showToast({
  73. icon: 'none',
  74. title: '已录入FaceID'
  75. })
  76. }else {
  77. uni.showModal({
  78. content: '未录入FaceID',
  79. showCancel: false
  80. })
  81. }
  82. console.log(res);
  83. },
  84. fail(err) {
  85. uni.showModal({
  86. content: '未录入FaceID',
  87. showCancel: false
  88. })
  89. console.log(err);
  90. }
  91. })
  92. },
  93. startSoterAuthenticationFingerPrint() {
  94. uni.startSoterAuthentication({
  95. requestAuthModes: ['fingerPrint'],
  96. challenge: '123456',
  97. authContent: '请用指纹解锁',
  98. success(res) {
  99. uni.showToast({
  100. icon: 'none',
  101. title: '指纹验证成功'
  102. })
  103. console.log(res);
  104. },
  105. fail(err) {
  106. uni.showModal({
  107. content: '指纹验证失败,errCode:' + err.errCode,
  108. showCancel: false
  109. })
  110. console.log(err);
  111. }
  112. })
  113. },
  114. startSoterAuthenticationFaceID() {
  115. uni.startSoterAuthentication({
  116. requestAuthModes: ['facial'],
  117. challenge: '123456',
  118. authContent: '请用FaceID解锁',
  119. success(res) {
  120. uni.showToast({
  121. icon: 'none',
  122. title: 'FaceID验证成功'
  123. })
  124. console.log(res);
  125. },
  126. fail(err) {
  127. uni.showModal({
  128. content: 'FaceID验证失败,errCode:' + err.errCode,
  129. showCancel: false
  130. })
  131. console.log(err);
  132. }
  133. })
  134. }
  135. }
  136. };
  137. </script>
  138. <style></style>