RPC calls

更新时间:
复制 MD 格式

Use the RPC interface to call server-side APIs from your mobile app via AlipayJSBridge.

Note

JSON data from JavaScript lacks type information. When converted to a dictionary at the native layer, numeric precision may be lost. Pass precise numeric values as strings. For example, {"value":9.45} becomes {"value":9.449999999999999} at the native layer. Use {"value":"9.45"} instead.

Syntax

AlipayJSBridge.call('rpc', {
  operationType: 'alipay.client.xxxx',
  requestData: [],
  headers: {}
}, function(result) {
  console.log(result);
});

Code example

<h1>Click the button to initiate an RPC request</h1>

<a href="javascript:void(0)" class="btn rpc">Initiate Request</a><br/>
<a href="javascript:void(0)" class="btn rpcHeader">Initiate Request with Response Header</a>

<script>
function ready(callback) {
  // If jsbridge is already injected, call it directly.
  if (window.AlipayJSBridge) {
    callback && callback();
  } else {
    // If not, listen for the injection 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 reference

AlipayJSBridge.call('rpc', {
  operationType:,
  requestData:,
  headers
}, fn);

Request parameters

Property

Type

Description

Required

Default value

operationType

string

The name of the RPC service.

Yes

-

requestData

array

Request parameters. Construct based on the target RPC interface.

N

-

headers

object

Custom headers for the RPC request.

N

{}

gateway

string

The gateway address.

N

Alipay gateway

compress

boolean

Whether to enable gzip compression for the request.

N

true

disableLimitView

boolean

Suppresses the unified rate-limiting pop-up when the gateway is rate-limited.

N

false

timeout

int

Request timeout in seconds.

Default timeouts by platform:

  • On iOS: 20 s on Wi-Fi, 30 s on other networks.

  • On Android: 12 s to 42 s on Wi-Fi/4G, 32 s to 60 s on other networks.

N

-

getResponse

boolean

Returns the RPC response header.

Important

When true, wraps response data in an additional layer, enabling backflow reporting to retrieve the traceId and entityId.

N

false

fn

function

The callback function.

N

-

Response parameters

The callback receives result: {error }.

Property

Type

Description

error

string

The error code.

Error codes

Error code

Description

10

Network error.

11

Request timeout.

Other

Defined by the mobilegw gateway.

Native RPC error codes

Error code

Description

1000

Success.

0

Unknown error.

1

The client cannot find the communication object.

2

The client has no network connectivity. (The JSAPI converts this to error code 10).

3

Client certificate error.

4

Client network connection timeout.

5

The client network speed is too slow.

6

The server did not return a response to the client request.

7

Client network I/O error.

8

Client network request scheduling error.

9

Client processing error.

10

Client data deserialization error. The server-side data format is incorrect.

11

Client logon failed.

12

The client logon account was switched.

13

Request interrupted, for example, by a thread interruption.

14

Client network cache error.

15

Client network authorization error.

16

DNS parsing error.

17

The operationType is not in the whitelist.

1001

Access denied.

1002

Call limit exceeded: "The system is busy. Try again later."

2000

Logon timed out. Log on again.

3000

The operation type is missing or not supported.

3001

The request data is empty: "The system is busy. Try again later."

3002

Incorrect data format.

4001

Service request timed out. Try again later.

4002

Remote call to business system failed: "The network is busy. Try again later."

4003

Failed to create a remote call agent: "The network is busy. Try again later."

5000

Unknown error: "Sorry, the operation cannot be performed at the moment. Try again later."

6000

RPC - Service not found.

6001

RPC - Target method not found.

6002

RPC - Incorrect number of parameters.

6003

RPC - Target method is not accessible.

6004

RPC - JSON parsing exception.

6005

RPC - Invalid parameters when calling the target method.

6666

RPC - Business exception.

7000

No public key is set.

7001

Insufficient parameters for signature verification.

7002

Signature verification failed.

7003

Timestamp check for signature verification failed.

7004

The operationType parameter for the signature verification RPC interface is empty.

7005

The productId parameter is empty.

7006

The did parameter for the signature verification interface is empty.

7007

The request sending time parameter 't' for the signature verification interface is empty.

7008

The IMEI (International Mobile Equipment Identity) parameter for the signature verification interface is empty.

7009

The IMSI (International Mobile Subscriber Identity) parameter for the signature verification interface is empty.

7010

The API version number for the signature verification interface is empty.

7011

The user does not have permission for the signature verification interface.

7012

The signature verification RPC interface is not public.

7013

The productId for the signature verification interface is not registered or the key is empty.

7014

The data to be signed for the signature verification interface is empty.

7015

The contract for the signature verification interface is invalid.

7016

The sid passed to the logon RPC for the signature verification interface is empty.

7017

The sid passed to the logon RPC for the signature verification interface is invalid.

7018

The token passed to the logon RPC for the signature verification interface is invalid.

7019

The alipayuserid obtained from the logon RPC for the signature verification interface is empty.

8001

etag: The response data has not changed.

Custom RPC gateway

Specify a custom gateway address in the RPC call.

RPC rate-limiting logic

Container version

disableLimitView

Behavior

Callback parameter

<=9.9.5

true

Silence

1002

<=9.9.5

false

Alert

1002

>=9.9.6

true

Silence

1002

>=9.9.6

false

Gateway processing

100201

Behavior type

Description

Silence

None.

Alert

A unified rate-limiting dialog box appears.

Toast

A toast message appears. No message appears if the user closes the system.

Gateway processing

Suppress alerts and toasts through the gateway RPC configuration.

RPC rate-limiting pop-up

RPC rate-limiting pop-up

FAQ

Q: How do I resolve the ESLint: 'AlipayJSBridge' is not defined error?

A: Two solutions:

  • Solution 1: window.AlipayJSBridge.call('rpc');

  • Solution 2:

      const { AlipayJSBridge } = window;
      AlipayJSBridge.call('rpc');