# User Authorized Device
If the device wants to initiate a call to the user, the user needs to authorize the device first on the mobile WeChat side .
WeChat Calling devices, using the callWMPF or callDevice interface does not require authorization.Authorization is still required to use the initByCaller interface.
# 1. Request authorization
Before the user authorizes, it is necessary to get the device ticket snTicket from the developer's background through the interface.
After you get the snTicket, you need to call wx.requestDeviceVoIP Please ask the user to authorize.
Requires base library = > 2.2.7.3 support.Device Group > > 2.30.4 Support.
wx.requestDeviceVoIP({
sn: 'xxxxxx', // 向用户发起通话的设备 sn(需要与设备注册时一致)
snTicket: 'xxxxxx', // 获取的 snTicket
modelId: 'xxxxxx', // 「设备接入」从微信公众平台获取的 model_id
deviceName: 'xxx', // 设备名称,用于授权时显示给用户
success(res) {
console.log(`requestDeviceVoIP success:`, res)
},
fail(err) {
console.error(`requestDeviceVoIP fail:`, err)
},
})
NOTE:
- If the user denies authorization or unauthorizes it in the settings page, calling
requestDeviceVoIPagain does not appear an authorization box.Developers should guide users to manually open it in the settings page. - "Device name" = "deviceName" + "modelId for device model" in the authorization box.For example, "devcieName" is "iot," modelId corresponding to the device model is "campus phone," the final name is "iot campus phone"

# 2. Addressing the failure of authorization
After a user has successfully authorized the authorization, the following actions may cause the approval to lapse:
- Empty authorization: Delete Weixin Mini Program in recent use, and the user's authorization record is cleared .
- Unauthorize: After the user agrees to authorize, the Voice and Video Call Reminder module appears in the Weixin Mini Program settings page. After clicking in, the user can manage the authorized device and can unauthorize.(Requires WeChat Guest > = 8.0.30 support)
In order to ensure that users can use audio and video calling capabilities, developers need to deal with the failure of authorization. Before initiating a call, developers are advised to check the authorization status** by **as described in Section 4.And remind users to reauthorize when necessary:
- Empty authorization: You can directly call
requestDeviceVoIPto ask the user to reauthorize. - Deauthorize / User Deny Authorization: Calling the
requestDeviceVoIPagain does not appear an authorization box.Developers should guide users to manually turn on the authorization switch in the settings page.
Developers can determine a user's authorization status by:
- Initiate a failed error code. When using the plug-in to initiate a call, errCode: 9 is returned if the user does not authorize the device. (If you use a device group, make sure that the device group is in this device)
- Query authorization status when the user uses Weixin Mini Program.See Section 4.
# 3. Volume Authorization
If volume licensing is required, you can create device groups .When users authorize and devices make audio and video calls, you can authorize a group of devices in bulk without having to repeatedly authorize every device.
For example, in a campus phone scenario, there might be many calls in the same school.You can add devices from the same school to a device group and authorize the entire device group using wx.requestDeviceVoIP .
Note: For device groups, deviceName appears as the name specified when the device group was created, and customization is not allowed during authorization.
Requires base library = > 2.30.4 support.
wx.requestDeviceVoIP({
isGroup: true,
groupId: '设备组 ID',
success(res) {
console.log(res)
},
fail(res) {
console.log(res)
},
})
# 4. Authorization status query
Developers can query the authorization status of users using Weixin Mini Program in the following ways. According to the unified authorization system of Mini programs, it does not provide background interface to query authorization status, nor does it provide event callback for user operation authorization.
# 4.1 Current user authorized devices (groups)
Query which devices (groups) the user who is currently logged in has agreed / declined or denied authorization.
Call [ within of WeChat on Weixin Mini Program side of **T]] mobile phone wx.getDeviceVoIPList , which can be used to check authorization status before initiating a call on the phone.
Base library = > 2.30.3 support is required.Device Group > > 2.30.4 Support.
// Weixin Mini Program Base Library Interface
wx.getDeviceVoIPList({
success(res) {
console.log('[getDeviceVoIPList]', res.list)
// [{sn: 'xxx', model_id: 'xxx', status: 0}]
// status: 0/未授权;1/已授权
},
})
- Device groups have only groupId fields, sn and model_id are
undefined.
# 4.2 Is the current device licensed?
Based on user openId, the query specifies whether the user authorizes the device (group).
Provided by plugin getIotBindContactList Interface, is generally used on the device side and can be used to check the authorization status before the device side initiates a call (such as a link page).
const wmpfVoip = requirePlugin('wmpf-voip').default
wmpfVoip
.getIotBindContactList({
sn: '设备sn',
model_id: '申请的modelid',
openid_list: ['openid_1', 'openid_2'], // 传入需要验证的openid列表
})
.then(res => {
console.log(`[getIotBindContactList]:`, res.contact_list)
// [{sn: 'xxx', model_id: 'xxx', status: 0}]
// status: 0/未授权;1/已授权
})