全部产品

按量数据推送接口文档

更新时间:2017-06-07 13:26:11   分享:   

1. 公共参数:

https://help.aliyun.com/document_detail/25490.html?spm=5176.doc25485.6.238.EaiYk2

2. 签名:

https://help.aliyun.com/document_detail/25492.html?spm=5176.doc25490.6.240.mHjxKi

3. 接口定义:

3.1 接口请求地址:https://market.aliyuncs.com/?action=PushMeteringData

3.2 接口请求规范:

云市场对每个InstanceId的请求限制为 60s/次 每次请求支持写入的计量数据为100条;

Action:PushMeteringData

Method:post

Protocol:http | https

3.3 请求参数:

参数 类型 可否为空 说明
Metering JsonString 计量数据对象
InstanceId String 云市场实例ID
StartTime Long 计量开始时间,单位秒(格式为unix时间戳)
EndTime Long 计量结束时间,单位秒(格式为unix时间戳)
Entities List 计量实体对象
Key String 计量项属性名称(对照表:3.4)
Value Long (取值 >= 0)

如果商品设置为实时出账,StartTime和EndTime为任意时间宽度均可以,但是EndTime一定要大于StartTime。

如果商品设置为按小时出账,StartTime和EndTime必须为整点数据。

3.4 计量项属性值对照表:

计量项 说明 单位
Frequency 使用次数
Period 使用时长
Storage 使用存储空间 Byte
NetworkOut 上行使用流量 Bit/s
NetworkIn 下行使用流量 Bit/s
Character 字符数

3.5 请求参数示例:

a. 请求示例:

https://market.aliyuncs.com/?action=PushMeteringData&Metering={“Metering”: [{“InstanceId” : “1000001”, StartTime”: “100000000”,”EndTime”: “100000010”,”Entities”: [{“Key”: “Frequency”,”Value”: “96”},{“Key”: “Period”,”Value”: “126”}]}]}&<公共请求参数>

b. JSON示例:

  1. {
  2. "InstanceId": "100001",
  3. "StartTime": "100000000",
  4. "EndTime": "100000010",
  5. "Entities": [
  6. {
  7. "Key": "Frequency",
  8. "Value": "96"
  9. },
  10. {
  11. "Key": "Period",
  12. "Value": "126"
  13. }
  14. ]
  15. },
  16. {
  17. "InstanceId": "100002",
  18. "StartTime": "100000010",
  19. "EndTime": "100000020",
  20. "Entities": [
  21. {
  22. "Key": "Frequency",
  23. "Value": "22"
  24. },
  25. {
  26. "Key": "Period",
  27. "Value": "209"
  28. }
  29. ]
  30. }

3.6 返回值示例:

  1. {
  2. "requestId" : "23ed92je-d13ddrf-23f2ef-fi0ae9s8",
  3. "isSuccess" : true
  4. }

3.7 返回错误信息:

httpCode Market编码 errorCode errorMessage 说明
500 500 UnknownError The request processing has failed due to some unknown error. 未知异常
500 1000 Service.Flow.Control The instance was locked from flow control. 请求实例被流控锁定(流控限制为60秒/次)
500 1001 Invalid.Parameter Invalid input parameter. 请求参数无效
500 1002 Invalid.Parameter.Instance Invalid input parameters for instance. 请求实例无效
500 1003 Invalid.Parameter.Metering Invalid input parameters for metering entity. 请求计量实体无效
500 1004 Metering.Data.Exceeded Metering entities more than 100. 计量数据实体大于100条
500 1005 Permission.Denied The request for status not on the white list. 请求身份没有权限

3.8 使用SDK:

a. maven引用

  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-market</artifactId>
  4. <version>2.0.0-upgrade-SNAPSHOT</version>
  5. </dependency>

b. java示例

  1. Map<String, Object> data1 = new HashMap<String, Object>();
  2. data1.put("Key", "Frequency");
  3. data1.put("Value", 664);
  4. Map<String, Object> data2 = new HashMap<String, Object>();
  5. data2.put("Key", "Period");
  6. data2.put("Value", 123);
  7. List<Map<String, Object>> meteringAttributes = new ArrayList<Map<String, Object>>();
  8. meteringAttributes.add(data1);
  9. meteringAttributes.add(data2);
  10. Map<String, Object> meteringData = new HashMap<String, Object>();
  11. meteringData.put("StartTime", new DateTime("2016-08-05T16:11:00").getMillis() / 1000);
  12. meteringData.put("EndTime", new DateTime("2016-08-05T16:16:00").getMillis() / 1000);
  13. meteringData.put("Entities", meteringAttributes);
  14. meteringData.put("InstanceId", "10001461");
  15. List<Map<String, Object>> meteringDataList = new ArrayList<Map<String, Object>>();
  16. meteringDataList.add(meteringData);
  17. try {
  18. DefaultProfile.addEndpoint("cn-hangzhou1", "cn-hangzhou1", "Market", "market.aliyuncs.com");
  19. IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou1","your access key","your secret");
  20. IAcsClient client = new DefaultAcsClient(profile);
  21. PushMeteringDataRequest request = new PushMeteringDataRequest();
  22. request.setActionName("PushMeteringData");
  23. request.setAcceptFormat(FormatType.JSON);
  24. request.setMethod(MethodType.POST);
  25. request.setVersion("2015-11-01");
  26. request.setMetering(JSON.toJSONString(meteringDataList));
  27. PushMeteringDataResponse response = client.getAcsResponse(request);
  28. System.out.println("result output:" + JSON.toJSONString(response));
  29. assert (response.getSuccess());
  30. } catch (ClientException e) {
  31. e.printStackTrace();
  32. }
本文导读目录
本文导读目录
以上内容是否对您有帮助?