Configuration parameters
The following are optional configuration parameters:
Parameters | Type | Description | Default Value | Optional Value |
---|---|---|---|---|
language | String | Set the language for captcha interface | zh | zh, en |
styleConfig | Object | Custom Component Styles | / | color, btnWidth, btnHeight |
product | String | Define product form | popup | popup, bind |
language
Multiple languages is supported, and corresponding text will be displayed when the following parameters are passed to the component. If no parameters are uploaded, the default is Chinese.
- zh (Chinese, default)
- en (English)
Code sample:
//Insert configuration on template, omit other required parameters |
styleConfig
Provide a custom style with the following three attributes:
Color: the color of the clicked button in the custom component (optional color can only be passed in full HEX with 6 bits, and the background color on the button is 60% of the opacity of the color value passed in)
btnWidth: the width of the custom verification plug-in (optional parameter btnWidth passes in the allowed css length, with units required)
btnHeight: the height of the custom verification plug-in (optional parameter btnHeight passes in allowed css length, with units required)
Code sample:
//wxml |
product
Support bind button-free mode, and the default value of this parameter is popup mode. Optional parameters:
popup: classic mode with button
bind: button-free mode. The user needs to call the Verify method to evoke the captcha interface.
Parameters inserted in the template are bind and verify. Other parameters are omitted here. Please refer to bind mode demo for details.
Code sample:
// wxml |
MiniProgram API Method
Ready
Listen if the DOM element which contains the captcha button is ready.
Code sample:
// wxml |
Error
The onError callback will be triggered whenever there are errors (refer to ErrorCode) that can be caught by captcha, such as listening to the verification error event, excessive refresh, failed loading of static resources, and poor network.
Error returns an e, where e.detail contains two attributes: code (error code) and tips (error prompt). In Error, we need to do a special reset for challenge expiration, as shown below
Code sample:
// wxml |
Success
Listens for the verification success event and returns a result object. The detail in the result contains four attributes: lot_number, pass_token, captcha_output, gen_time. These parameters are the evidence of the current verification success,
Passing those to secondary verification is required.
Code sample:
// wxml |
Close
This callback is triggered when the user turns off the pop-up verification.
Code sample:
// wxml |
toReset
Reset captcha. It is used when the user’s background detects that the captcha is successful yet other information is incorrect (such as the username and password are incorrect), or the error occurs with the captcha.
Code sample:
// wxml |