Since 8.5RPC
Important: Due to precision loss during conversion in native, i.e., {"value":9.45}
is converted to {"value":9.449999999999999}
in native. Please always use string type for all numeric data
Send RPC request to backend.
Usage
AlipayJSBridge.call('rpc', {
operationType: 'alipay.client.xxxx',
requestData: [],
headers: {}
}, function(result) {
console.log(result);
});
Example
Basic Function
<h1>Press button to send RPC request</h1>
<a href="javascript:void(0)" class="btn rpc">Send RPC request</a><br />
<a href="javascript:void(0)" class="btn rpcHeader">Send RPC request and expect headers data in response</a>
<script>
function ready(callback) {
if (window.AlipayJSBridge) {
callback && callback();
} else {
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function() {
document.querySelector('.rpc').addEventListener('click', function() {
AlipayJSBridge.call('rpc', {
operationType: 'alipay.client.xxxx',
requestData: [],
headers: {}
}, function(result) {
alert(JSON.stringify(result));
});
});
document.querySelector('.rpcHeader').addEventListener('click', function() {
AlipayJSBridge.call('rpc', {
operationType: 'alipay.client.xxxx',
requestData: [],
headers: {},
getResponse: true
}, function(result) {
alert(JSON.stringify(result));
});
});
});
</script>
API
AlipayJSBridge.call('rpc', {
operationType:,
requestData:,
headers
}, fn);
Input Parameters
Name | Type | Description | Mandatory | Default |
---|
operationType | string | Name of RPC service | Y | | |
requestData | array | Request data, please refer to the specific RPC API for required data | N | | |
headers | object | Headers in the request | N | {}} | |
gateway | string | Address of network gateway | N | alipay gateway | |
compress | boolean | Whether or not to support request gzip compression | N | true | |
disableLimitView | boolean | Whether or not to stop showing network dialog when network traffic is constrained by the RPC gateway | N | false | |
timeout | int | Timeout in seconds | N | Configuration from the framework | |
getResponse | boolean | Whether or not to expect headers data from RPC response. (Note: if set to true, additional hierarchy is added to the response data for traceId and entityId. This requires MMTP to be switched on) | N | false | |
fn | function | Callback function | N | | |
Output Parameters
The callback function parameter result: {error }
Name | Type | Description |
---|
error | string | Error code |
Errors
error | Description |
---|
10 | Network error |
11 | Request timeout |
Other | |
RPC errors
error | Description |
---|
1000 | Success |
0 | Unknown error |
1 | No communication peer found at client |
2 | Client has no network access |
3 | Client certificate error |
4 | Client network timeout |
5 | Client network slow |
6 | No response from server |
7 | Client network I/O error |
8 | Client network request dispatch error |
9 | Client error occurs |
10 | Deserialisation error at client, wrong format from server |
11 | Client login failure |
12 | Client switched account |
13 | Request aborted |
14 | Client network cache error |
15 | Client network authorisation error |
16 | DNS resolution error |
17 | operationType not in white list |
1001 | Access denied |
1002 | Maximum number of invocations exceeded |
2000 | Login timeout |
3000 | Missing operation type or operation type not supported |
3001 | Request data is empty |
3002 | Data format is wrong |
4001 | Service request timeout |
4002 | Remote business system exception |
4003 | Remote proxy creation failed |
5000 | Unknown error |
6000 | RPC service not found |
6001 | RPC target method not found |
6002 | Number of RPC parameters mismatched |
6003 | RPC target method not accessible |
6004 | RPC JSON deserialisation exception |
6005 | Illegal parameters passed to RPC method |
6666 | RPC business exception |
7000 | No public key configured |
7001 | Not enough parameters for signature verification |
7002 | Signature verification failed |
7003 | Timestamp check failed in signature verification |
7004 | operationType is empty during RPC signature verification |
7005 | productId is empty productId |
7006 | Parameter did is empty during RPC signature verification |
7007 | Request time parameter t is empty during RPC signature verification |
7008 | Parameter IMEI is empty during RPC signature verification |
7009 | Parameter IMSI is empty during RPC signature verification |
7010 | API version is empty during RPC signature verification |
7011 | User has no permission during RPC signature verification |
7012 | RPC API not published during RPC signature verification |
7013 | Parameter productId is not registered or secret key is empty during RPC signature verification |
7014 | Encrypted data is empty during RPC signature verification |
7015 | Invalid signature found during RPC signature verification |
7016 | Parameter login sid is empty during RPC signature verification |
7017 | Parameter login sid is invalid during RPC signature verification |
7018 | Parameter token is invalid during RPC signature verification |
7019 | Parameter login alipayuserid is empty during RPC signature verification |
8001 | No data changed in response |
RPC traffic constrain
Type | Description |
---|
Silent | N/A |
Alert | A dialog is prompted, as illustrated in RPC traffic constrain dialog below |
Toast | A toast is prompted |
gateway | Let gateway configuration decides |
RPC traffic constrain dialog
