All Products
Search
Document Center

Mobile Platform as a Service:Configure preset booth

Last Updated:Oct 20, 2023

The operation of preset booths on HTML5 page involves obtaining booth information only. The obtaining methods includes: Obtain one by one and Obtain in batches .

In addition to obtaining booth information, you can also intercept booth information and advertising information by calling the API operations.

About this task

If you are a beginner, we recommend that you configure the advertisement booths of iOS pages dynamically on the mPaaS console (server side). For details, refer to Create a booth.

Obtain one by one

Call getCdpSpaceInfo on the HTML5 page to obtain booth information:

AlipayJSBridge.call('getCdpSpaceInfo', {
  spaceCode: 'space-code1',
  extInfo: {
    tradeNo: '123'
  },
  immediately: false,
  multiCallback: true
}, function (result) {
  console.log(result);
});

where:

  • spaceCode: The booth code, which is applied for to the backend.

  • extInfo: The extension information, in the format of key/value.

  • immediately: The boolean value. It indicates whether cache data is not required and data is directly obtained from the server. By default, data is read from the cache and does not need to be transferred.

  • multiCallback: The boolean value. It indicates whether multiple callbacks are required when the API is called once.

Note

If multiCallback is set to NO or not set, callback is performed only once. If there is a cache mechanism, ads cannot be displayed as scheduled when the page is opened for the first time, and are displayed the next time when the page is opened. If this parameter is set to YES, you need to perform MCDP callback twice. The first callback is the cached data (if there is a cache), and the second callback is the result returned by the RPC.

Obtain in batches

Call getCdpSpaceInfos on the HTML5 page to obtain booth information.

AlipayJSBridge.call('getCdpSpaceInfos', {
  spaceCodes: ['space-code1', 'space-code2'],
  extInfo: {
    tradeNo: '123'
  },
  immediately: false,
  multiCallback: true
}, function (result) {
  console.log(result);
});
/**
 * MCDP advertising service API
 *
 */
public abstract class CdpAdvertisementService extends ExternalService {

    /**
     * Initialize all advertisement information.
     *
     * @param extInfo: extension information.
     * @param callBack: callback.
     */
    public abstract void initialized(Map<String, String> extInfo, IAdGetSpaceInfoCallBack callBack);

    /**
     * Query the booth by booth ID. Call back onSuccess(SpaceInfo spaceInfo) asynchronously to return the query result.
     * If no local cache exists, the RPC query result is called back.
     * If a local cache exists and it's before update time, the local query result is called back.
     * If a local cache exists and it's before update time, the local query result is called back, and the update result is then called back after the RPC.
     * The onFail() API is called back only if the RPC fails.
     *
     * @param spaceCode: booth ID, which needs to be applied for to the advertisement delivery platform.
     * @param callback: callback API.
     */
    public abstract void getSpaceInfoByCode(String spaceCode, IAdGetSingleSpaceInfoCallBack callback);

    /**
     * Query the booth by booth ID. Call back onSuccess(SpaceInfo spaceInfo) asynchronously to return the query result.
     * If no local cache exists, the RPC query result is called back.
     * If a local cache exists and it's before update time, the local query result is called back.
     * If a local cache exists and it's before update time, the local query result is called back, and the update result is then called back after the RPC.
     * The onFail() API is called back only if the RPC fails.
     *
     * @param spaceCode: booth ID, which needs to be applied for to the advertisement delivery platform.
     * @param extInfo: extension parameter.
     * @param immediately: only return the RPC result.
     * @param callback: callback API.
     */
    public abstract void getSpaceInfoByCode(String spaceCode, Map<String, String> extInfo, boolean immediately, final IAdGetSingleSpaceInfoCallBack callback);

    /**
     * Query booths in batches based on the booth ID list. Call onSuccess(List<SpaceInfo> adSpaceInfo) asynchronously to return the query result.
     * If no local cache exists, the RPC query result is called back.
     * If a local cache exists and it's before update time, the local query result is called back.
     * If a local cache exists and it's before update time, the local query result is called back, and the update result is then called back after the RPC.
     * Callback onFail(ListString adSpaceCodes) API only when RPC fails
     *
     * @param spaceCodeList: booth ID list, which needs to be applied for to the advertisement delivery platform.
     * @param extInfo: extension parameter.
     * @param immediately: only return the RPC result.
     * @param callback: callback API.
     */
    public abstract void batchGetSpaceInfoByCode(List<String> spaceCodeList, Map<String, String> extInfo, boolean immediately, final IAdGetSpaceInfoCallBack callback);

    /**
     * TODO: reserved H5 API.
     *Query and display ads. It is called only by AdH5Plugin.
     *
     * @param activity: current page.
     * @param parentView: parent control.
     * @param url: URL.
     * @param h5Param: parameter.
     */
    public abstract void checkAndShowAdInH5(final Activity activity, ViewGroup parentView, String url, String h5Param);

    /**
     * Remove the advertisement view of the specified spaceCode.
     *
     * @param activity: page from which an announcement is to be removed.
     * @param spaceCode: ad ID
     */
    public abstract void removeAdvertisement(Activity activity, String spaceCode);

    /**
     * Obtain the action executor. If this parameter is not set, null is returned.
     *
     * @return: action executor.
     */
    public abstract ActionExecutor getActionExecutor();

    /**
     * Set the action executor.
     *
     * @param executor: action executor.
     */
    public abstract void setActionExecutor(ActionExecutor executor);


    /**
     * Set the user ID.
     *
     * @param userId: user ID.
     */
    public abstract void setUserId(String userId);

    /**
     * Obtain the user ID.
     *
     * @return: user ID.
     */
    public abstract String getUserId();

    /**
     * Obtain callback classes for advertisement booths.
     */
    public interface IAdGetSpaceInfoCallBack {
        /**
         * Succeeded in obtaining the booth information.
         *
         * @param adSpaceInfo: booth list.
         */
        void onSuccess(List<SpaceInfo> adSpaceInfo);

        /**
         * Failed to obtain booth information.
         *
         * @param adSpaceCodes: code list of booth requests.
         */
        void onFail(List<String> adSpaceCodes);
    }

    /**
     * Gets callback classes for a single booth.
     */
    public interface IAdGetSingleSpaceInfoCallBack {
        /**
         * Succeeded in obtaining the booth information.
         *
         * @param spaceInfo: booth information.
         */
        void onSuccess(SpaceInfo spaceInfo);

        /**
         * Failure
         */
        void onFail();
    }
}

ActionExecutor

ActionExecutor (action executor) implements the interception of booth and advertisement information. The client does not display the corresponding booths and advertisement content after the interception, and displays the booths and advertisement content without the interception.

/**
 * Action executor
 *
 */
public interface ActionExecutor {

    /**
     * Whether to intercept the action
     * @param spaceInfo: booth information.
     * @param spaceObjectInfo: ad information.
     * @param url: action url.
     * @return: The value true indicates intercepting the action whereas false indicates otherwise.
     */
    boolean interceptAction(final SpaceInfo spaceInfo, final SpaceObjectInfo spaceObjectInfo, final String url);

    /**
     * Execute the action.
     *
     * @param spaceInfo: booth information.
     * @param spaceObjectInfo: ad information.
     * @param url: action url.
     * @return: Value 1 indicates success and other values indicate exceptions.
     */
    int executeAction(final SpaceInfo spaceInfo, final SpaceObjectInfo spaceObjectInfo, final String url);
}