123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- const { IoTVsp, IoTVspEvent, modeType } = requirePlugin('IoTVsp')
- import { request } from '@/utils/request'
- const isvPid = '2088441938577206'
- const orgOutId = 'suzhouyuanlin'
- const componentOutId = 'common_verify_import'
- let throttle = false
- const iotVspInit = function(callback = null) {
- // 跳转到开通结果时监听上报结果数据
- IoTVsp.addEventListener(IoTVspEvent.query, (data) => {
- // 当跳转至开通结果页,data中能获取到上报到信息,不需要点击完成拿到信息
- // console.log('IoTVspEvent.query-->', data)
- })
- // 开通结果页点击完成返回事件
- IoTVsp.addEventListener(IoTVspEvent.back, (data) => {
- //若配置不跳转至默认开通成功页,则开通成功后执行此回调
- // console.log('IoTVspEvent.back-->', data)
- // my.alert({content: 'IoTVspEvent.back-->' + JSON.stringify(data)})
- if(callback != null && throttle) {
- throttle = false
- callback(data)
- }
- })
- // 错误事件监听
- IoTVsp.addEventListener(IoTVspEvent.result, (data) => {})
- }
- const _startComponent = function(uniqueId) {
- if(!uniqueId) {
- return
- }
- throttle = true
- IoTVsp.start({
- mode: modeType.faceverify,
- config: {
- uniqueId,
- isvPid: isvPid,
- orgOutId: orgOutId,
- componentOutId: componentOutId
- }
- })
- }
- const iotVspUniqueId = function(idNumber, username, phone, avatar, uniqueId = null) {
- return new Promise((resolve, reject) => {
- if(!idNumber && !username && !phone) {
- reject()
- return
- }
- if(uniqueId) {
- _startComponent(uniqueId)
- resolve(false)
- return
- }
- uni.showLoading({
- content: "加载中..."
- })
- request({
- url: 'https://tx.hz-hanghui.com:8088/yx-fyzd/alipay/api/v1/open/iotvsp/userwithvid/create',
- // url: 'http://192.168.11.11:9100/yx-fyzd/alipay/api/v1/open/iotvsp/userwithvid/create',
- method: 'POST',
- data: {
- componentOutId: componentOutId,
- isvPid: isvPid,
- orgOutId: orgOutId,
- appId: getApp().globalData.appId,
- userInfoList: [{
- certType: 'IDENTITY_CARD',
- certNo: idNumber,
- certName: username,
- phone: phone || null,
- avatar: avatar || null
- }]
- },
- dataType: 'json',
- header: {
- 'Content-type': 'application/json'
- },
- success: res => {
- if(res.data && !res.data.uniqueId) {
- // uniqueId为空,表示已入库
- resolve(true)
- } else {
- _startComponent(res.data.uniqueId)
- resolve(false)
- }
- },
- fail: res => {
- reject(res)
- },
- complete: res => {
- uni.hideLoading()
- }
- })
- })
- }
- module.exports = {
- iotVspUniqueId,
- iotVspInit
- }
|