This document explains how to integrate the Phone Number Verification Service native plugin into the uni-app development framework and perform mobile number verification.
Background information
Uni-app native plugin
The Alibaba Cloud Phone Number Verification SDK is an authentication plugin developed using the uni-app native plugin extension capability of HBuilder. It lets you easily integrate Alibaba Cloud's phone number verification capabilities into your project and implement related features at the JavaScript (JS) layer.
This plugin is developed with native code and is compatible only with Android and iOS applications built on the uni-app framework and is not compatible with other types of mini programs.
Add the plugin to your project
Create a uni-app project.
If you have not created a uni-app project, see Create a project by using the HBuilder visual interface.
If you already have a project, proceed to the next step.
Download the plugin.
Go to the plugin page: Alibaba Cloud Phone Number Verification SDK.
On the right side of the page, click Download for offline packaging to download the plugin.
Import the plugin into your project.
In the root directory of your project, create a new folder named nativeplugins. Unzip the downloaded AliCloud-NirvanaPns_x.x.x.zip package and add the extracted plugin folder to the
nativepluginsfolder.
Open the
manifest.jsonfile in the root directory and click App Native Plugin Configuration > Select Local Plugin.
In the Local Plugin Selection dialog box, select the Alibaba Cloud Phone Number Verification SDK checkbox.

Click OK to import the plugin.
Create a scheme code
See Create a verification scheme and obtain the Scheme Code.
Interaction flow
For the complete interaction flow, see Mobile number verification interaction flow.
Methods
Import method
In your vue or nvue file, import the native plugin by using the uni.requireNativePlugin method.
Example
const aLiSDKModule = uni.requireNativePlugin('AliCloud-NirvanaPns');setAuthSDKInfo (Set secret)
This is a required method.
Before using one-click logon, you must set the secret and ensure that the secret matches your app's bundle ID or package name.
Parameters: setAuthSDKInfo(info)
Parameter | Type | Description |
info | String | The secret generated in the Phone Number Verification Service console. |
Example
aLiSDKModule.setAuthSDKInfo("<SDK_INFO>"); // Replace this with the secret you obtained from the console.accelerateVerify
Accelerates obtaining a mobile number verification token.
We recommend calling this method 2 to 3 seconds before you call the method to get the mobile number verification token. This buffer allows the method to obtain a temporary credential, a process that typically takes 1 to 3 seconds.
Avoid calling this method multiple times.
Calling this method is unnecessary if you get the mobile number verification token immediately after the application starts.
Parameters
Parameter | Type | Description |
timeout | Number | The interface timeout in milliseconds. |
callback(args) | Function | Callback function. The structure of the input parameters is as follows:
|
Example
aLiSDKModule.accelerateVerify(5000, (result) => {
console.log(JSON.stringify(result));
if ("600000" == result.resultCode) {
console.log("Successfully accelerated the token acquisition for mobile number verification");
} else {
console.log("Failed to accelerate token acquisition for mobile number verification, " + result.msg);
}
});
getVerifyToken
Gets the token for mobile number verification.
Parameters
Parameter | Type | Description |
timeout | Number | The interface timeout in milliseconds. |
callback(args) | Function | Callback.The input parameters for the callback have the following structure:
|
Example
aLiSDKModule.getVerifyToken(5000, (result) => {
if ("600000" == result.resultCode) {
console.log(
"Successfully obtained the mobile number verification token. You must now use the mobile number and token to perform verification on your server. The SDK's role in the process is complete."
);
}
});getVersion (Get SDK version)
Parameters:getVersion(callback)
Parameter | Type | Description |
callback(version) | Function | The callback function. The input parameter is an object with the following properties:
|
Example
aLiSDKModule.getVersion((version) => {
console.log("The current SDK version number is: " + version);
});checkEnvAvailable (Environment check)
Checks whether the current environment supports one-click logon or local number verification.
Parameters:checkEnvAvailable(authType, callback)
Parameter | Type | Description |
authType | Number | The type of check to perform:
|
callback(args) | Function | The callback function. The input parameter is an object with the following properties:
|
Example
aLiSDKModule.checkEnvAvailable(2, (result) => {
if ("600000" == result.resultCode) {
uni.navigateTo({
animationDuration: 300,
url: "../login/login",
});
} else {
console.log("The current environment does not support one-click logon. result = ", JSON.stringify(result));
uni.showToast({
icon: "none",
title: result.msg,
duration: 3000,
});
}
});getCurrentCarrierName (Get default SIM carrier)
Parameters:getCurrentCarrierName(callback)
Return value | Type | Description |
callback(carrierName) | Function | The callback function. The input parameter is an object with the following properties:
|
Example
aLiSDKModule.getCurrentCarrierName((carrierName) => {
console.log("The current carrier is: " + carrierName);
});setCheckboxIsChecked
Parameters
Parameter | Type | Description |
isChecked | Boolean | Whether to select the checkbox by default.
|
Example
aLiSDKModule.setCheckboxIsChecked(true)closePrivactAlertView
Example
aLiSDKModule.closePrivactAlertView()