JSAPI

Since 8.5

RPC

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) {
  // Invoke directly if JSBridge is already injected
  if (window.AlipayJSBridge) {
    callback && callback();
  } else {
    // Otherwise listen to `AlipayJSBridgeReady` event
    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

NameTypeDescriptionMandatoryDefault
operationTypestringName of RPC serviceY
requestDataarrayRequest data, please refer to the specific RPC API for required dataN
headersobjectHeaders in the requestN{}}
gatewaystringAddress of network gatewayNalipay gateway
compressbooleanWhether or not to support request gzip compressionNtrue
disableLimitViewbooleanWhether or not to stop showing network dialog when network traffic is constrained by the RPC gatewayNfalse
timeoutintTimeout in secondsNConfiguration from the framework
getResponsebooleanWhether 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)Nfalse
fnfunctionCallback functionN

Output Parameters

The callback function parameter result: {error }

NameTypeDescription
errorstringError code

Errors

errorDescription
10Network error
11Request timeout
Other

RPC errors

errorDescription
1000Success
0Unknown error
1No communication peer found at client
2Client has no network access
3Client certificate error
4Client network timeout
5Client network slow
6No response from server
7Client network I/O error
8Client network request dispatch error
9Client error occurs
10Deserialisation error at client, wrong format from server
11Client login failure
12Client switched account
13Request aborted
14Client network cache error
15Client network authorisation error
16DNS resolution error
17operationType not in white list
1001Access denied
1002Maximum number of invocations exceeded
2000Login timeout
3000Missing operation type or operation type not supported
3001Request data is empty
3002Data format is wrong
4001Service request timeout
4002Remote business system exception
4003Remote proxy creation failed
5000Unknown error
6000RPC service not found
6001RPC target method not found
6002Number of RPC parameters mismatched
6003RPC target method not accessible
6004RPC JSON deserialisation exception
6005Illegal parameters passed to RPC method
6666RPC business exception
7000No public key configured
7001Not enough parameters for signature verification
7002Signature verification failed
7003Timestamp check failed in signature verification
7004operationType is empty during RPC signature verification
7005productId is empty productId
7006Parameter did is empty during RPC signature verification
7007Request time parameter t is empty during RPC signature verification
7008Parameter IMEI is empty during RPC signature verification
7009Parameter IMSI is empty during RPC signature verification
7010API version is empty during RPC signature verification
7011User has no permission during RPC signature verification
7012RPC API not published during RPC signature verification
7013Parameter productId is not registered or secret key is empty during RPC signature verification
7014Encrypted data is empty during RPC signature verification
7015Invalid signature found during RPC signature verification
7016Parameter login sid is empty during RPC signature verification
7017Parameter login sid is invalid during RPC signature verification
7018Parameter token is invalid during RPC signature verification
7019Parameter login alipayuserid is empty during RPC signature verification
8001No data changed in response

RPC traffic constrain

TypeDescription
SilentN/A
AlertA dialog is prompted, as illustrated in RPC traffic constrain dialog below
ToastA toast is prompted
gatewayLet gateway configuration decides

RPC traffic constrain dialog