All Products
Document Center

Overview and Preparation

Last Updated: Apr 06, 2021


Mini Program developing operations from creating a Mini Program to releasing one can be implemented by calling openAPI, which enables the interaction between the user server side and the mPaaS server side.

Rate limit description

To prevent OpenAPI from being called too frequently and thus affecting the operation of the App, a rate limiting mechanism is adopted for calling OpenAPI. The details are as follows:

  • mcube rate limiting runs on a single server, and the limiting dimensions are appId+workspaceId.
  • Currently mcube provides two servers for accepting OpenAPI requests, which are then forwarded by load balancer.
  • On a single server, the limit for Mini Program uploading interface is 10 times every minute, that is, uploading interface can be called once every 6 seconds; the limit for other interfaces is 600 times every minute, that is, the interfaces can be called once every 0.1 second.


Before using OpenAPI, you need to obtain AccessKey, App ID and Workspace ID, configure Maven dependencies and configure file uploading.

Obtain AccessKey

AccessKey includes AccessKey ID and AccessKey Secret. Click here for obtaining method.

  • AccessKey ID: used to identify users.
  • AccessKey Secret: used for user authentication. MUST be kept safe.

Obtain App ID and Workspace ID

  1. Log in to mPaaS console, and enter the App.
  2. In Overview page, click Code configurations (choose Android or iOS based on your needs)> Download configuration file > Download now. You can view App ID and Workspace ID in the Code configurations panel.

Configure Maven dependencies

Before using OpenAPI, you need to complete the following Maven dependency configurations.

  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-mpaas</artifactId>
  4. <version>1.1.1</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.aliyun</groupId>
  8. <artifactId>aliyun-java-sdk-core</artifactId>
  9. <optional>true</optional>
  10. <version>[4.3.2,5.0.0)</version>
  11. </dependency>

Code sample

The following shows the code sample of using Client in Maven:

  1. private static final String REGION_ID = "cn-hangzhou"; //Region ID, the default is cn-hangzhou
  2. private static final String ACCESS_KEY_ID = "*****************"; //AccessKey ID of RAM account
  3. private static final String ACCESS_SECRET = "******************"; //AccessKey Secret of RAM account
  4. private static final String PRODUCT = "mpaas"; //Product name
  5. private static final String END_POINT = ""; //The endpoint that is called
  6. DefaultProfile.addEndpoint(REGION_ID, PRODUCT, END_POINT);
  7. DefaultProfile profile = DefaultProfile.getProfile(REGION_ID, ACCESS_KEY_ID, ACCESS_SECRET);
  8. IAcsClient iAcsClient = new DefaultAcsClient(profile);
  9. QueryMcubeVhostRequest queryMcubeVhostRequest = new QueryMcubeVhostRequest();
  10. queryMcubeVhostRequest.setAppId(APP_ID);
  11. queryMcubeVhostRequest.setWorkspaceId(WORKSPACE_ID);
  12. queryMcubeVhostRequest.setTenantId(TENANT_ID);
  13. QueryMcubeVhostResponse acsResponse = null;
  14. try {
  15. acsResponse = iAcsClient.getAcsResponse(queryMcubeVhostRequest);
  16. System.out.println(acsResponse.getResultCode());
  17. System.out.println(acsResponse.getQueryVhostResult());
  18. } catch (ClientException e) {
  19. e.printStackTrace();
  20. }

Configure file uploading

Since file streaming is not allowed in all APIs, to upload a file, you need to upload it to OSS first by calling the upload tool class, and then send the returned OSS address as a parameter to the specified API.

You can download the file upload tool class

Code sample

The following shows the code sample of file uploading:

  1. GetMcubeFileTokenRequest getMcubeFileTokenRequest = new GetMcubeFileTokenRequest();
  2. getMcubeFileTokenRequest.setAppId(APP_ID);
  3. getMcubeFileTokenRequest.setOnexFlag(true);
  4. getMcubeFileTokenRequest.setTenantId(TENANT_ID);
  5. getMcubeFileTokenRequest.setWorkspaceId(WORKSPACE_ID);
  6. GetMcubeFileTokenResponse acsResponse = iAcsClient.getAcsResponse(getMcubeFileTokenRequest);
  7. System.out.println(JSON.toJSONString(acsResponse));
  8. GetMcubeFileTokenResponse.GetFileTokenResult.FileToken fileToken = acsResponse.getGetFileTokenResult().getFileToken();
  9. OssPostObject ossPostObject = new OssPostObject();
  10. ossPostObject.setKey(fileToken.getDir());
  11. ossPostObject.setHost(fileToken.getHost());
  12. ossPostObject.setOssAccessId(fileToken.getAccessid());
  13. ossPostObject.setPolicy(fileToken.getPolicy());
  14. ossPostObject.setSignature(fileToken.getSignature());
  15. ossPostObject.setFilePath("your/local/file/path");
  16. String s = ossPostObject.postObject();

Refer to Obtain upload file token for descriptions about GetMcubeFileTokenRequest.