[关闭]
@superpigy 2025-02-26T18:19:10.000000Z 字数 1797 阅读 58

FinClip SDK

App.JS回调注册

假设 getApp().globalData.context为保存的当前页面上下文
事件名称 recognition_done 为识别完成事件
事件名称 capture_done 为采集完成事件

  1. const custom_callback = (res) =>{
  2. if(getApp().globalData.context.__route__ === {{当前页面路由}}){
  3. if(res.event === 'recognition_done' || res.event === 'capture_done'){
  4. console.log(res)
  5. getApp().globalData.context.on_hamuna_sdk_callback(res)
  6. }
  7. }
  8. }
  9. console.log('custom event registered')
  10. try{
  11. wx.onCustomEvent(custom_callback)
  12. }
  13. catch(e){
  14. }

牛脸采集

  1. app.globalData.context.capturing = true
  2. wx.capture({
  3. pool_id: {{识别池ID}},
  4. loading_id: {{自定义变量}},
  5. success(res){
  6. console.log(res)
  7. app.globalData.context.on_hamuna_sdk_callback(res)
  8. },
  9. fail(e){
  10. console.log(e.errmsg)
  11. app.globalData.context.notify.show("牛脸识别模块出现错误", "error")
  12. }
  13. })

牛脸识别

  1. app.globalData.context.capturing = true
  2. wx.recognition({
  3. pool_id: {{识别池ID}},
  4. pool_name: {{对应名称}},
  5. success: function(res){
  6. console.log(res)
  7. app.globalData.context.on_hamuna_sdk_callback(res)
  8. },
  9. fail: function(e){
  10. console.log(e.errmsg)
  11. app.globalData.context.notify.show("牛脸识别模块出现错误", "error")
  12. }
  13. })

SDK回调样例

  1. on_hamuna_sdk_callback(res){
  2. if(res.event === 'capture_done'){
  3. var pool_id = res.data.pool_id
  4. if(pool_id != app.globalData.context.data.order.bind_pool_id){
  5. console.log('pool id not match')
  6. return
  7. }
  8. if(app.globalData.context.capturing){
  9. console.log('data changed')
  10. app.globalData.context.setData({
  11. data_changed: true
  12. })
  13. }
  14. else{
  15. }
  16. }
  17. else if(res.event === 'recognition_done'){
  18. var pool_id = res.data.pool_id
  19. if(pool_id != app.globalData.context.data.order.bind_pool_id){
  20. return
  21. }
  22. if(res.data.matched){
  23. if(app.globalData.context.capturing){
  24. console.log('data changed')
  25. app.globalData.context.setData({
  26. data_changed: true
  27. })
  28. }
  29. else{
  30. }
  31. }
  32. else{
  33. console.log('wrong matched')
  34. app.globalData.context.setData({
  35. has_wrong_matched: true
  36. })
  37. if(!app.globalData.context.capturing){
  38. }
  39. else{
  40. util.showModal("牛脸验证", "检测到匹配失败的牛只, 是否查看", function(res){
  41. if(!res.cancel){
  42. app.globalData.context.show_wrong_matches()
  43. }
  44. })
  45. }
  46. }
  47. }
  48. },
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注