# User Authorization Device
Device if you want to initiate a call to the user, requires the user to call in theMobile phone WeChatAuthorize the device first.
WeChat calling device, if using callWMPF or callDevice The interface does not require authorization. use initByCaller The interface still needs authorization.
# 1. Request authorization
Before the user is authorized, it needs to be passed from the developer's background.Get Equipment Tickets Interface to get the device bill snTicket.
Get it SnTicket After that, you need to call inside the Mini Program wx.requestDeviceVoIP
Ask the user to authorize.
Base library required >= 2.27.3 Support. Equipment Group >= 2.30.4 Support.
wx.requestDeviceVoIP({
sn: 'xxxxxx', // Device that initiates a call to the user Sn (same as when the device is registered)
snTicket: 'xxxxxx', // Acquired SnTicket
modelId: 'xxxxxx', // Device accessFrom the WeChat Official Platform model_id
deviceName: 'xxx', // Device name to be displayed to the user when authorizing
success(res) {
console.log(`requestDeviceVoIP success:`, res)
},
fail(err) {
console.error(`requestDeviceVoIP fail:`, err)
},
})
Note:
- If the user denies authorization or disauthorizes it in the settings page, call again
requestDeviceVoIP
No authorization bullet box appears. The developer should guide the user to manually open it in the settings page. - In the authorization boxName of device= deviceName + modelId Corresponding Equipment ModelSuch asdevcie foriot,modelId The corresponding device model isCampus Phone, the final name isiot Campus Phone
# 2. Dealing with cases where authorization lapses
After the user is authorized, the following actions may cause the authorization to expire:
- Clear Authorization:Delete the Mini Program in Recent Use, and the user's authorization record is cleared。
- Deauthorization: After the user agrees to the authorization, the Mini Program settings page will appearVoice and Video Call AlertsModule, after clicking into the user can manage the authorized device, and can cancel the authorization. (Need WeChat client >= 8.0.30 Support)
In order to ensure that the user can use the audio and video communication capabilities normally,Developers need to deal with cases where authorization expires. Before initiating a call, it is recommended that developers go through Section 4 The manner described in the sectionCheck authorization statusAnd remind the user to reauthorize if necessary:
- Empty authorization: you can call it directly
requestDeviceVoIP
Ask the user to re-authorize. - Cancellation of authorization/User Denied Authorization: Call Again
requestDeviceVoIP
No authorization bullet box appears. The developer should guide the user to manually turn on the authorization switch in the settings page.
The developer can determine the user's authorization status by:
- Error code by initiating the call failure. When a call is initiated using the plug-in, if the user does not authorize the device, it returns errCode: 9。(If you use a device group, verify that the device exists in the device group)
- Query the authorization status when the user uses the Mini Program. See No. 4 Section.
# 3. Volume licensing
If you need volume authorization, you can createEquipment GroupWhen a user authorizes an audio or video call with a device, it is possible to bulk license to a group of devices without having to re-license each device.
For example, in the campus phone scenario, there may be many phones in the same school. Devices from the same school can be added to a device group and used wx.requestDeviceVoIP Authorize the entire group of devices.
Note: For device groups, deviceName Appears as the name specified when creating the device group. Customization is not allowed when authorizing.
Base library required >= 2.30.4 Support.
wx.requestDeviceVoIP({
isGroup: true,
groupId: 'Equipment Group ID',
success(res) {
console.log(res)
},
fail(res) {
console.log(res)
},
})
# 4. Authorization status query
The developer can beUser Uses Mini ProgramThe authorization status is queried in the following manner.According to the Mini Program unified authorization system design, does not provide background interface query authorization status, also does not provide the user operation authorization event callback.
# 4.1 Device (group) authorized by the current user
Query the currently logged in user consent/Which devices (groups) have been denied or de-authorized.
inMobile phone WeChat end Mini Programcall [wx.getDeviceVoIPList
]((wx.getDeviceVoIPList )), can be used to check the authorization status before initiating a call on the phone.
Base library required >= 2.30.3 Support. Equipment Group >= 2.30.4 Support.
// Mini Program base library interface
wx.getDeviceVoIPList ({
success(res) {
console.log('[getDeviceVoIPList ]', res.list)
// [{sn: 'xxx', model_id: 'xxx', status: 0}]
// status: 0/Not authorized1/Authorized
},
})
- Equipment Group Only groupId Field, sn and model_id for
undefined
。
# 4.2 Whether the current device is authorized
According to the user OpenId, a query specifying whether the user authorizes the device (group).
Provided by Plugins getIotBindContactList Interface,Generally used on the device side, which can be used to check authorization status before initiating a call on the device side, such as the contacts page.
const wmpfVoip = requirePlugin('wmpf-voip' ).default
wmpfVoip
.getIotBindContactList({
sn: 'device sn ',
model_id: 'modelid of application ',
Openid _list: [Openid _1', Openid _2'], // Pass in the list of openids that need to be verified
})
.then(res => {
console.log(`[getIotBindContactList]:`, res.contact_list)
// [{sn: 'xxx', model_id: 'xxx', status: 0}]
// status: 0/Not authorized1/Authorized
})