All Products
Search
Document Center

Configure preset booth

Last Updated: Aug 24, 2021

The operation of preset booths on HTML5 page involves obataining 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:

  1. AlipayJSBridge.call('getCdpSpaceInfo', {
  2. spaceCode: 'space-code1',
  3. extInfo: {
  4. tradeNo: '123'
  5. },
  6. immediately: false,
  7. multiCallback: true
  8. }, function (result) {
  9. console.log(result);
  10. });

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.

  1. AlipayJSBridge.call('getCdpSpaceInfos', {
  2. spaceCodes: ['space-code1', 'space-code2'],
  3. extInfo: {
  4. tradeNo: '123'
  5. },
  6. immediately: false,
  7. multiCallback: true
  8. }, function (result) {
  9. console.log(result);
  10. });
  11. /**
  12. * MCDP advertising service API
  13. *
  14. */
  15. public abstract class CdpAdvertisementService extends ExternalService {
  16. /**
  17. * Initialize all advertisement information.
  18. *
  19. * @param extInfo: extension information.
  20. * @param callBack: callback.
  21. */
  22. public abstract void initialized(Map<String, String> extInfo, IAdGetSpaceInfoCallBack callBack);
  23. /**
  24. * Query the booth by booth ID. Call back onSuccess(SpaceInfo spaceInfo) asynchronously to return the query result.
  25. * If no local cache exists, the RPC query result is called back.
  26. * If a local cache exists and it's before update time, the local query result is called back.
  27. * 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.
  28. * The onFail() API is called back only if the RPC fails.
  29. *
  30. * @param spaceCode: booth ID, which needs to be applied for to the advertisement delivery platform.
  31. * @param callback: callback API.
  32. */
  33. public abstract void getSpaceInfoByCode(String spaceCode, IAdGetSingleSpaceInfoCallBack callback);
  34. /**
  35. * Query the booth by booth ID. Call back onSuccess(SpaceInfo spaceInfo) asynchronously to return the query result.
  36. * If no local cache exists, the RPC query result is called back.
  37. * If a local cache exists and it's before update time, the local query result is called back.
  38. * 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.
  39. * The onFail() API is called back only if the RPC fails.
  40. *
  41. * @param spaceCode: booth ID, which needs to be applied for to the advertisement delivery platform.
  42. * @param extInfo: extension parameter.
  43. * @param immediately: only return the RPC result.
  44. * @param callback: callback API.
  45. */
  46. public abstract void getSpaceInfoByCode(String spaceCode, Map<String, String> extInfo, boolean immediately, final IAdGetSingleSpaceInfoCallBack callback);
  47. /**
  48. * Query booths in batches based on the booth ID list. Call onSuccess(List<SpaceInfo> adSpaceInfo) asynchronously to return the query result.
  49. * If no local cache exists, the RPC query result is called back.
  50. * If a local cache exists and it's before update time, the local query result is called back.
  51. * 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.
  52. * Callback onFail(ListString adSpaceCodes) API only when RPC fails
  53. *
  54. * @param spaceCodeList: booth ID list, which needs to be applied for to the advertisement delivery platform.
  55. * @param extInfo: extension parameter.
  56. * @param immediately: only return the RPC result.
  57. * @param callback: callback API.
  58. */
  59. public abstract void batchGetSpaceInfoByCode(List<String> spaceCodeList, Map<String, String> extInfo, boolean immediately, final IAdGetSpaceInfoCallBack callback);
  60. /**
  61. * TODO: reserved H5 API.
  62. *Query and display ads. It is called only by AdH5Plugin.
  63. *
  64. * @param activity: current page.
  65. * @param parentView: parent control.
  66. * @param url: URL.
  67. * @param h5Param: parameter.
  68. */
  69. public abstract void checkAndShowAdInH5(final Activity activity, ViewGroup parentView, String url, String h5Param);
  70. /**
  71. * Remove the advertisement view of the specified spaceCode.
  72. *
  73. * @param activity: page from which an announcement is to be removed.
  74. * @param spaceCode: ad ID
  75. */
  76. public abstract void removeAdvertisement(Activity activity, String spaceCode);
  77. /**
  78. * Obtain the action executor. If this parameter is not set, null is returned.
  79. *
  80. * @return: action executor.
  81. */
  82. public abstract ActionExecutor getActionExecutor();
  83. /**
  84. * Set the action executor.
  85. *
  86. * @param executor: action executor.
  87. */
  88. public abstract void setActionExecutor(ActionExecutor executor);
  89. /**
  90. * Set the user ID.
  91. *
  92. * @param userId: user ID.
  93. */
  94. public abstract void setUserId(String userId);
  95. /**
  96. * Obtain the user ID.
  97. *
  98. * @return: user ID.
  99. */
  100. public abstract String getUserId();
  101. /**
  102. * Obtain callback classes for advertisement booths.
  103. */
  104. public interface IAdGetSpaceInfoCallBack {
  105. /**
  106. * Succeeded in obtaining the booth information.
  107. *
  108. * @param adSpaceInfo: booth list.
  109. */
  110. void onSuccess(List<SpaceInfo> adSpaceInfo);
  111. /**
  112. * Failed to obtain booth information.
  113. *
  114. * @param adSpaceCodes: code list of booth requests.
  115. */
  116. void onFail(List<String> adSpaceCodes);
  117. }
  118. /**
  119. * Gets callback classes for a single booth.
  120. */
  121. public interface IAdGetSingleSpaceInfoCallBack {
  122. /**
  123. * Succeeded in obtaining the booth information.
  124. *
  125. * @param spaceInfo: booth information.
  126. */
  127. void onSuccess(SpaceInfo spaceInfo);
  128. /**
  129. * Failure
  130. */
  131. void onFail();
  132. }
  133. }

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.

  1. /**
  2. * Action executor
  3. *
  4. */
  5. public interface ActionExecutor {
  6. /**
  7. * Whether to intercept the action
  8. * @param spaceInfo: booth information.
  9. * @param spaceObjectInfo: ad information.
  10. * @param url: action url.
  11. * @return: The value true indicates intercepting the action whereas false indicates otherwise.
  12. */
  13. boolean interceptAction(final SpaceInfo spaceInfo, final SpaceObjectInfo spaceObjectInfo, final String url);
  14. /**
  15. * Execute the action.
  16. *
  17. * @param spaceInfo: booth information.
  18. * @param spaceObjectInfo: ad information.
  19. * @param url: action url.
  20. * @return: Value 1 indicates success and other values indicate exceptions.
  21. */
  22. int executeAction(final SpaceInfo spaceInfo, final SpaceObjectInfo spaceObjectInfo, final String url);
  23. }