index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view>
  3. <text>{{id}}</text>
  4. <text>{{name}}</text>
  5. <text>{{address}}</text>
  6. <text>{{sex}}</text>
  7. <text>{{time}}</text>
  8. <lzcOCR class="lzcOCR" @end="idcardEnd"></lzcOCR>
  9. <button @click="start">开始同步区县</button>
  10. </view>
  11. </template>
  12. <script>
  13. import lzcOCR from '@/components/lzc-OCR/lzc-OCR.vue';
  14. import config from '@/config.js';
  15. let jl = require('../../static/jl.json')
  16. export default {
  17. components: {
  18. lzcOCR
  19. },
  20. data() {
  21. return {
  22. id: '1',
  23. name: '2',
  24. address: '3',
  25. sex: '4',
  26. time: '5',
  27. client_id: config.face_client_id,
  28. client_secret: config.face_client_secret,
  29. token: '',
  30. groupId: '',
  31. }
  32. },
  33. methods: {
  34. getAccessToken(groupId) {
  35. uni.request({
  36. url: '/baiduApi/oauth/2.0/token',
  37. data: {
  38. grant_type: 'client_credentials',
  39. client_id: this.client_id,
  40. client_secret: this.client_secret
  41. },
  42. method: 'POST',
  43. header: {
  44. 'Content-Type': 'application/x-www-form-urlencoded'
  45. },
  46. success: (res) => {
  47. if (res.statusCode == 200) {
  48. this.token = res.data.access_token
  49. this.createGroup(groupId)
  50. }
  51. },
  52. error: (err) => {}
  53. })
  54. },
  55. createGroup(groupId) {
  56. uni.request({
  57. url: '/baiduApi/rest/2.0/face/v3/faceset/group/add?access_token=' + this.token,
  58. data: {
  59. group_id: groupId,
  60. },
  61. method: 'POST',
  62. header: {
  63. 'Content-Type': 'application/x-www-form-urlencoded'
  64. },
  65. success: (res) => {
  66. console.log("创建组返回,", groupId, res)
  67. },
  68. error: (err) => {}
  69. })
  70. },
  71. start() {
  72. let array = jl.RECORDS
  73. let shi = []
  74. jl.RECORDS.forEach(e => {
  75. // console.log(e.code.substring(0, 6));
  76. this.getAccessToken(e.code.substring(0, 6))
  77. })
  78. },
  79. idcardEnd(words) {
  80. console.log("www", words)
  81. alert(JSON.stringify(words))
  82. uni.showModal({
  83. content: words
  84. })
  85. this.id = words.words_result['公民身份号码'].words
  86. this.name = words.words_result['姓名'].words
  87. this.address = words.words_result['民族'].words
  88. this.sex = words.words_result['性别'].words
  89. this.time = words.words_result['出生'].words
  90. }
  91. }
  92. }
  93. </script>
  94. <style>
  95. .lzcOCR {
  96. width: 90%;
  97. display: flex;
  98. justify-content: center;
  99. }
  100. </style>