此接口用于将顾客的下一个结算日期推迟。
您的APP在推出一些优惠活动的时候,例如奖励顾客使用商品时长,可以调用华为应用内支付服务器提供的延迟结算接口,将订阅者的下一个结算日期推迟。用户将继续享受已经付费的服务和内容,但在延迟期内不会被扣款。系统会更新订阅续订日期以反映新的订阅日期。您可以通过延迟结算完成以下操作:
将免费内容或者服务作为套餐或特别优惠的一部分提供给用户(例如,让订阅年度杂志的用户免费访问特定内容)。
向特定客户赠送内容或者服务的访问权限。
每次调用 API 的结算最短可延迟一天,最长为一年(365天)。您可以在新的结算日期到来之前再次调用 API以进一步延迟结算。延期后,下个续期周期的开始日期为延期后的过期时间。
您的APP可能需要使用电子邮件或在应用中通知用户,让他们知道自己的结算日期已被延迟(发生更改)。
承载协议 | HTTPS POST |
接口方向 | 开发者服务器-> 华为支付服务器 |
接口URL | {rootUrl}/sub/applications/{apiVersion}/purchases/delay rootUrl在不同站点有不同的url:开发者应固定选择最近站点的Subscription服务地址访问。具体请参见站点信息和站点选择。 |
数据格式 | 请求消息:Content-Type: application/json 响应消息:Content-Type: application/json |
参数名称 | 必选(M)/可选(O) | 数据类型 | 参数描述 |
subscriptionId | M | String | 订阅Id |
purchaseToken | M | String | 商品的已购买Token,发起购买和查询订阅信息均会返回。 |
currentExpirationTime | M | Long | 订阅当前的有效期,Long,标准时间戳,必须等于当前过期时间; |
desiredExpirationTime | M | Long | 延迟后的订阅有效期,Long,标准时间戳,取值必须大于订阅当前有效期,最少延期一天,最大允许延迟365天; |
参数名称 | 必选(M)/可选(O) | 数据类型 | 参数描述 |
responseCode | M | String | 返回码。 ● 0:成功 ● 其他:失败,具体参考接口错误码。 |
responseMessage | O | String | 响应描述。 |
newExpirationTime | O | Long | 延迟后的订阅有效期时间,Long,标准时间戳 |
- public class SubscriptionService {
- // TODO: replace the (ip:port) to the real one, and if the protocol is https, you should deal with the license
- // yourself.
- public static final String TOC_SITE_URL = "http://ip:port";
- // site for telecom carrier
- public static final String TOBTOC_SITE_URL = "https://subscr-at-dre.iap.dbankcloud.com";
- public static String getRootUrl(Integer accountFlag) {
- if (accountFlag != null && accountFlag == 1) {
- return TOBTOC_SITE_URL;
- }
- return TOC_SITE_URL;
- }
- public static void delaySubscription(String subscriptionId, String purchaseToken, Long currentExpirationTime,
- Long desiredExpirationTime, Integer accountFlag) throws Exception {
- // fetch the App Level AccessToken
- String appAt = AtDemo.getAppAT();
- // construct the Authorization in Header
- Map<String, String> headers = AtDemo.buildAuthorization(appAt);
- // pack the request body
- Map<String, Object> bodyMap = new HashMap<>();
- bodyMap.put("subscriptionId", subscriptionId);
- bodyMap.put("purchaseToken", purchaseToken);
- bodyMap.put("currentExpirationTime", currentExpirationTime);
- bodyMap.put("desiredExpirationTime", desiredExpirationTime);
- String msgBody = JSONObject.toJSONString(bodyMap);
- String response = AtDemo.httpPost(getRootUrl(accountFlag) + "/sub/applications/v2/purchases/delay",
- "application/json; charset=UTF-8", msgBody, 5000, 5000, headers);
- // TODO: display the response as string in console, you can replace it with your business logic.
- System.out.println(response);
- }
- }