Alipay, China's leading third-party online payment solutionAlipay, China's leading third-party online payment solution

4. Start to use Griver AppContainer

After the initialization, you can open a mini program or web app with Griver API.

Open a mini program

The openApp API is called by the super app to open mini programs with appId, the unique ID of the mini program.

Method signature

copy
void openApp(Context context, String appId, Bundle extraParams, GriverContainerAPICallBack callBack)

Request parameters

Name

Type

Description

Required

context

Context

Interface to global information about an application environment.

M

appId

String

The unique ID that is assigned by Mini Program Platform to identify a mini program. You can get the ID from the Mini Program Platform console or by fetching mini program information with the fetchApps API.

M

extraParams

Bundle

This parameter is used to pass startup parameters to IAPMini Program SDK to customize the behavior of a mini program during startup. The passed parameters should be included in the definition of {@linkGriverParams.LaunchParams}. For how to specify the startup parameters, see Startup parameters.

O

callBack

GriverContainerAPICallBack

The callback that is used to listen to mini program launch failures.

O

Response parameters

Name

Type

Description

Required

error

Error

An object that is used to return the error code and error message when the mini program launch fails.

O

Error codes

Error code

Error message

Description

Further action

90002

GRV_CONTAINER_NOT_INITIALIZED

IAPMiniProgram SDK is not initialized.

Initialize the SDK.

90003

GRV_CONTAINER_ERROR_UNKNOWN

Parameter error.

Refer to the Request parameters table and check if all parameter types are correct and if all required parameters are specified.

Sample

Kotlin

copy
val bundle = Bundle()
bundle.putString("query", "a=b&c=d")
Griver.openApp(context, appId, bundle,
               GriverContainerAPICallBack { errorCode, errorMessage ->
                   //return the error code and error message if the mini program launch fails
               })

Java

copy
Bundle bundle = new Bundle();
bundle.putString("query", "a=b&c=d");
Griver.openApp(context, appId, bundle, new GriverContainerAPICallBack() {
    @Override
    public void error(int errorCode, String errorMessage) {
        //return the error code and error message if the mini program launch fails
    }
});

Open a web app

The openUrl API is called by the super app to open mini programs with url, the URL of the mini program.

Method signature

copy
void openUrl(Context context, String url, Bundle extraParams, GriverContainerAPICallBack callBack)

Request parameters

Name

Type

Description

Required

context

Context

Interface to global information about an application environment.

M

url

String

The scheme URL of the mini program. The URL should use the HTTP or HTTPs protocols and include the _ariver_appid, _ariver_path, and _ariver_version query string parameters. You can get the URL from the Mini Program Platform console.

M

extraParams

Bundle

This parameter is used to pass startup parameters to IAPMini Program SDK to customize the behavior of a mini program during startup. The passed parameters should be included in the definition of {@linkGriverParams.LaunchParams}. For how to specify the startup parameters, see Startup parameters.

O

callback

GriverContainerAPICallBack

The callback that is used to listen to mini program launch failures.

O

Response parameters

Name

Type

Description

Required

error

Error

An object that is used to return the error code and error message when the mini program launch fails.

O

Error codes

Error code

Error message

Description

Further action

90002

GRV_CONTAINER_NOT_INITIALIZED

IAPMiniProgram SDK is not initialized.

Initialize the SDK.

90003

GRV_CONTAINER_ERROR_UNKNOWN

Parameter error.

Refer to the Request parameters table and check if all parameter types are correct and if all required parameters are specified.

Samples

Kotlin

copy

copy
val bundle = Bundle()
bundle.putString("query", "a=b&c=d")
Griver.openUrl(context, url, bundle,
               GriverContainerAPICallBack { errorCode, errorMessage ->
                   //return the error code and error message if the mini program launch fails
               })

Java

copy
Bundle bundle = new Bundle();
bundle.putString("query", "a=b&c=d");
Griver.openUrl(context, appId, bundle, new GriverContainerAPICallBack() {
    @Override
    public void error(int errorCode, String errorMessage) {
        //return the error code and error message if the mini program launch fails
    }
});

Preview and remote debug mini program

The Mini Program Studio provides the ability to preview and remote debug the mini program. To scan the QR code that is generated by Mini Program Studio and then preview or remote debug the mini program, your app should follow these steps to achieve scanability.

Step 1: Scan the QR Code

First of all, your app should have a scanner. Use your scanner to scan the QR code that Mini Program Studio generated, and get the scan results.

Step 2: Recognize the mini program QR code

As your scanner is a universal scanner, it may get different scan results. So you need to recognize the result of scanning the mini program QR code.

The result of scanning the mini program QR code has the following rules.

  • It is a text that can parse to a valid URI.
  • It must contain the _ariver_appid, _ariver_path, and _ariver_version query string.

Take the following scanning result of the preview QR code in Mini Program Studio as an example:

copy
mini://platformapi/startapp?_ariver_appid=2171010045421679&_ariver_path=&_ariver_version=0.1.1587126785630&_ariver_source=debug&_ariver_scene=PREVIEW&_ariver_token=ee3fa2b45c414b91ac090cb1fd04eda6

As mentioned before, the Griver AppContainer can open a mini program by openUrl if the URL is a valid URI that contains the _ariver_appid. So when you find that the scanning result meets the rules mentioned above, treat it as a mini program QR code.

Step 3: Open by Griver AppContainer

After you recognize the scanning result is a mini program QR code, pass the scan result to Griver AppContainer directly by openUrl interface. Then you can use your app to preview or remote debug the mini program in Mini Program Studio.

Multi-environment support

Griver AppContainer provides multi-environment support. If you set other environment parameters when the application started, you can add the environment info in Griver/config.json. To publish a mini program in the production environment, do not set the environment parameter. Here is an example:

copy
{
    "environment": "sandbox"
}

Now Griver AppContainer supports the following environments:

  • dev: The development environment
  • test: The test environment
  • sandbox: The sandbox environment

Note: If you do not set the environment parameter, it means you can get a mini program published in the production environment.