This operation is used to call the scan component. It applies only to Android. Before using this interface, make sure you have added Scan component to your project. actionType
in the interface is used to get code value.
scan API usage instruction
AlipayJSBridge.call('scan', {
type: 'bar',
actionType: 'scan'
}, function(result) {
alert(JSON.stringify(result));
});
Code sample
Obtain QR code information:
<h1>Click the information corresponding to the output code after scanning.</h1>
<a href="#" class="btn read">Start scanning.</a>
<script>
function ready(callback) {
// Call JS Bridge if it has been injected.
if (window.AlipayJSBridge) {
callback && callback();
} else {
// Listen to the injection event if it has not been injected.
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function() {
document.querySelector('.read').addEventListener('click', function() {
AlipayJSBridge.call('scan', {
type: 'qr'
}, function(result) {
alert(JSON.stringify(result));
});
});
});
</script>
API
AlipayJSBridge.call('scan', {
type, actionType, qrcode
}, fn);
Input parameters
Name | Type | Description | Required | Default value |
---|---|---|---|---|
type | string | Target scan type, QR code or bar code. | Y | “” |
actionType | string | Operation type: “scan”: scan only the code value. | N | “scan” |
qrcode | string | Indicates the code value used for the “route” operation. | N | “” |
fn | function | Callback function after scanning the QR code to obtain code information. | N | - |
Output parameters
Parameter carried in the callback function: result: {error, barCode, qrCode, cardNumber}.
Name | Type | Description |
---|---|---|
barCode | string | Bar code data obtained through scan. |
qrCode | string | QR code data obtained through scan. |
error | int | Error code (10: operation canceled, 11: operation failed). |