# Pay face mode in a campus setting

For some of the existing payment face brushing devices, we support additional user identity through WeChat payment face recognition to initiate calls.

There are restrictions on payment for face wiper calls:

  • Only support WeChat to pay for the use of facial devices, the specific way to open please refer to the relevant documents of Weixin Pay;
  • Android devices only supported, WMPF < = 2.0 version;
  • Only supports the device to initiate calls, does not support the phone WeChat calling devices.

# 1. Start a call

The payment device also initiates calls through the initByCaller interface, but there are some differences in parameters.Use the following businessType to pay for face brushing devices:

businessType Type of business caller.id listener.id voipToken Minimum version
0 Face brush mode (time billing) WeChat user_id returned by paying for face brush WeChat User openId WeChat Pay the voip_token returned by face brush
3 Face-brushing mode (license billing) Ditto Ditto Ditto 2.3.8
  • wx.authorize Have the user corresponding to openId authorizescope.voip, otherwiseerrCode: 8,See Section 2 for details of the process;
  • A listener must be a caller associate.Otherwise returnserrCode: 9.

# 2. Contact Management

# 2.1 Contact Binding

In the campus scenario, the developer needs to access the plug-in "contact binding relationship" function, and only after the parent has completed the relationship binding operation can the child make a voice and video call to the parent.

The linkage binding is the mapping relationship between userId (child) and openId (parent), and the developer can also implement the linkage management function through the related interface.

# Administrator binding

The first associate is the administrator, who needswx.authorizeto authorizevoip.scope,Call the plug-in interfacewmpfVoip.bindVoipAdminContactto complete the binding.

// Bind to become an administrator
try {
  await wx.authorize({
    scope: 'scope.voip',
  })
  const res = await wmpfVoip.bindVoipAdminContact({
    userId: 'xxxxxx', // 传入微信支付刷脸返回的 user_id
  })
  console.log(`bindVoipAdminContact`, res)
} catch (error) {
  console.error('authorize scope voip', error)
  wx.showToast({
    title: '请前往设置页授权通话提醒',
    icon: 'none',
  })
}

# Other contacts are bound

Other contacts are bound by the admin sharing page.That is, the administrator clicks the "Share" button in Weixin Mini Program and sends the message throughwmpfVoip.getBindContactPathGet the plugin share page link and set it inonShareAppMessageon the page.

When the binding is complete, it will jump to the page set by setVoipEndPagePath .

// Get the path to the plug-in contact binding relationship page, where the user performs a relationship binding operation.
// Share binding pages: Get the share link in advance when the student administrator enters the page
wmpfVoip
  .getBindContactPath({
    userId: 'xxxx', // 学生 id
    userName: 'xxxx', // 学生名字
    userAvatar: 'xxxx', // 学生头像
  })
  .then(path => {
    // 在 onShareAppMessage 中使用 path
    // 可在 path 后拼上参数, 如'&xxx=yyy', 小程序中通过 getPluginEnterOptions 获取
  })

// In page
Page({
  onShareAppMessage() {
    return {
      title: `邀请你成为「${userName}」的联系人`,
      path: 'xxxx', // getBindContactPath 获取的 path
    }
  },
})

// app.js
App({
  onLoad() {
    // 设置联系人绑定关系页面操作完成后要跳转的页面路径。
    wmpfVoip.setVoipEndPagePath({
      key: 'BindContact',
      url: 'xxxxxx',
      options: 'param1=xxx&param2=xxx',
    })
  },
})

Be careful

  • The userName and userId (WeChat the user_id returned by the payment brush face) should be consistent with the information entered by the dialing party (student);
  • The dialing party should be able to obtain the openId and name of the associate of the receiving party, which can be displayed on the associate list page;
  • During the completion of the binding, the corresponding event is triggered.Can be monitored via onVoipEvent .Specifically refer tobindContacttype.

# 2.2 Request a list of contacts

# Plug-in Interface

wmpfVoip.getVoipBindContactList({ userId: '学生userId' }).then(list => {
  /**
      [{
        user_id: 'xxx',
        is_ad: 0, // 0 普通联系人,1 管理员
        openid_list: [], // 管理员可以获取孩子(user_id)下绑定的所有联系人(openid)列表,包括自己。
      }]
    */
})

# Back-end Interface

Request address

POST https://api.weixin.qq.com/wxa/business/getvoipcontactlist?access_token=ACCESS_TOKEN

Request parameters

attribute type Required to fill in Introductions
access_token / cloudbase_access_token string yes Interface call credentials
user_id string yes Student userId

Return value

Object

The returned JSON packet

attribute type Introductions
errcode number Error code
errmsg string Error message
contact_list ContactInfo[] Contact list

ContactInfo

attribute type Introductions
open_id string Associate openid
role number Contact identity, 0 for general contact, 1 for administrator.

Legal value of errCode

errCode Introductions
0 success
1 List of users without contacts

# 2.3 Delete Contacts

Only the administrator can delete the student's (user_id) associate (openid). The administrator cannot delete himself.

wmpfVoip.deleteVoipBindContact({
  userId: 'xxx',
  openidList: ['openId1', 'openId2'],
})

# 2.4 Transfer Administrator

Only administrators can call the transfer interface.

wmpfVoip.transerAdmin({
  userId: 'xxx',
  newAdminOpenid: '新管理员的openid',
})

# 2.5 Listening to incidents

During the contact bonding process,onVoipEventreceivesbindContactevents to get the status of a shared contact bonded:

data parameter

attribute type Introductions
type string Bind the result, taking the value for the following
errMsg string Error message
userId string Student user_id

Type value

type describe
success Contact binding successfully
unbind The contact did not bind the student
binded The contact had tied the student up.
expire Share link is out of date
overload The student's bound contacts have exceeded the limit.
invalid The link was shared illegally, possibly because it was shared by a non-administrator
auth Coassociate authorization scope.voip failed
cancel Contact cancels binding