ioTVsp.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. const { IoTVsp, IoTVspEvent, modeType } = requirePlugin('IoTVsp')
  2. import { request } from '@/utils/request'
  3. const isvPid = '2088441938577206'
  4. const orgOutId = 'suzhouyuanlin'
  5. const componentOutId = 'common_verify_import'
  6. let throttle = false
  7. const iotVspInit = function(callback = null) {
  8. // 跳转到开通结果时监听上报结果数据
  9. IoTVsp.addEventListener(IoTVspEvent.query, (data) => {
  10. // 当跳转至开通结果页,data中能获取到上报到信息,不需要点击完成拿到信息
  11. // console.log('IoTVspEvent.query-->', data)
  12. })
  13. // 开通结果页点击完成返回事件
  14. IoTVsp.addEventListener(IoTVspEvent.back, (data) => {
  15. //若配置不跳转至默认开通成功页,则开通成功后执行此回调
  16. // console.log('IoTVspEvent.back-->', data)
  17. // my.alert({content: 'IoTVspEvent.back-->' + JSON.stringify(data)})
  18. if(callback != null && throttle) {
  19. throttle = false
  20. callback(data)
  21. }
  22. })
  23. // 错误事件监听
  24. IoTVsp.addEventListener(IoTVspEvent.result, (data) => {})
  25. }
  26. const _startComponent = function(uniqueId) {
  27. if(!uniqueId) {
  28. return
  29. }
  30. throttle = true
  31. IoTVsp.start({
  32. mode: modeType.faceverify,
  33. config: {
  34. uniqueId,
  35. isvPid: isvPid,
  36. orgOutId: orgOutId,
  37. componentOutId: componentOutId
  38. }
  39. })
  40. }
  41. const iotVspUniqueId = function(idNumber, username, phone, avatar, uniqueId = null) {
  42. return new Promise((resolve, reject) => {
  43. if(!idNumber && !username && !phone) {
  44. reject()
  45. return
  46. }
  47. if(uniqueId) {
  48. _startComponent(uniqueId)
  49. resolve(false)
  50. return
  51. }
  52. uni.showLoading({
  53. content: "加载中..."
  54. })
  55. request({
  56. url: 'https://tx.hz-hanghui.com:8088/yx-fyzd/alipay/api/v1/open/iotvsp/userwithvid/create',
  57. // url: 'http://192.168.11.11:9100/yx-fyzd/alipay/api/v1/open/iotvsp/userwithvid/create',
  58. method: 'POST',
  59. data: {
  60. componentOutId: componentOutId,
  61. isvPid: isvPid,
  62. orgOutId: orgOutId,
  63. appId: getApp().globalData.appId,
  64. userInfoList: [{
  65. certType: 'IDENTITY_CARD',
  66. certNo: idNumber,
  67. certName: username,
  68. phone: phone || null,
  69. avatar: avatar || null
  70. }]
  71. },
  72. dataType: 'json',
  73. header: {
  74. 'Content-type': 'application/json'
  75. },
  76. success: res => {
  77. if(res.data && !res.data.uniqueId) {
  78. // uniqueId为空,表示已入库
  79. resolve(true)
  80. } else {
  81. _startComponent(res.data.uniqueId)
  82. resolve(false)
  83. }
  84. },
  85. fail: res => {
  86. reject(res)
  87. },
  88. complete: res => {
  89. uni.hideLoading()
  90. }
  91. })
  92. })
  93. }
  94. module.exports = {
  95. iotVspUniqueId,
  96. iotVspInit
  97. }