用量类查询

CMIOT_API2010-流量信息批量查询

集团客户可以查询所属物联卡近期GPRS流量使用情况,批量查询多个用户、指定日期的GPRS使用量,一次最多查询100张卡(仅支持查询最近7天中某一天的数据)。


API请求参数说明

请求地址:https://api.iot.10086.cn/v2/batchgprsusedbydate

请求方式:GET/POST


公共参数

参数 是否必须 默认值 含义

appid

应用编码,第三方应用唯一标识。由物联卡集团客户向中国移动提出API接入申请,中国移动物联网全网管理员在运营管理平台上分配并反馈给集团客户(反馈方式:邮箱),appid样例:100001

transid

事务编码,由物联卡集团客户按照相应规则自主生成(不可超过48位)。生成规则:appid+YYYYMMDDHHMISS+8位数字序列(此序列由集团客户自主生成,比如从00000001开始递增等等),transid样例:1000012014101615303080000001

ebid

能力编码,同appid一起由中国移动反馈给集团客户,ebid样例:2300000000000001

token

令牌,appid+password+transid(password同appid、ebid一起由中国移动反馈给集团客户)并使用64位SHA-256算法进行加密,token样例: 4962ad69adcbf490c9f749fff734b 5706a874ebab1120aaa23c9d288290534ca


业务参数

参数 是否必须 默认值 含义 校验规则

msisdns

所查询的物联卡号码,最长13位数字,举例:14765004176,msisdns、iccids、imsis三者必须有且只有一项

msisdn、iccid、imsi必须有且只有一项

iccids

集成电路卡识别码,IC卡的唯一识别号码,共有20位字符组成,举例:898600D6991330004146,批量查询多个号码用下划线分隔。例如:xxxx_xxxx_xxxx;msisdns、iccids、imsis必须有且只有一项

imsis

国际移动用户识别码,其总长度不超过15位,使用0~9的数字,举例:460079650004176,批量查询多个号码用下划线分隔。例如:xxxx_xxxx_xxxx;msisdns、iccids、imsis必须有且只有一项

query_date

查询时间(例如:系统当前日期20150421,7日内,即20150414-20150420有效)


返回参数说明

应答公共信息:

参数 是否必须 默认值 含义

status

返回码:

0-正确,非0-失败

message

错误信息。错误码对应的错误描述,参考错误码列表

result

返回结果集(status为“0”时,result包含正确的结果数据;status为“非0”时, result可能为空,也可能包含其他提示数据)

应答数据信息:

参数 是否必须 默认值 含义

GPRS

当日使用的GPRS流量总量(单位:KB)

MSISDN

物联网专网卡号

ICCID

集成电路卡识别码,IC卡的唯一识别号码

IMSI

国际移动用户识别码


API请求URL示例

https://api.iot.10086.cn/v2/batchgprsusedbydate?appid=xxx&ebid=xxx&transid=xxx&token=xxx&query_date=xxx&iccids=xxx_xxx_xxx -以iccids进行查询

https://api.iot.10086.cn/v2/batchgprsusedbydate?appid=xxx&ebid=xxx&transid=xxx&token=xxx&query_date=xxx&msisdns=xxx_xxx_xxx -以msisdns进行查询

https://api.iot.10086.cn/v2/batchgprsusedbydate?appid=xxx&ebid=xxx&transid=xxx&token=xxx&query_date=xxx&imsis=xxx_xxx_xxx -以imsis进行查询


API请求示例代码

  • Java
  • PHP
  • Python
  • C#
复制代码

package com.iot;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;


/**
 *
 * @author IOT JAVA请求API服务平台接口demo
 *
 */
public class CMIOT_API2010 {

	// 请求URL的IP和端口,需要按实际环境修改
	public static final String ipAndPort = "http://api.iot.10086.cn";
	// 请求的版本号
	public static final String version = "/v2";
	// 请求具体的接口名称
	public static final String apiName = "/batchgprsusedbydate";

	/**
	 * 获取请求接口的返回信息
	 *
	 * @param url
	 *            请求接口时需要传入的URL
	 */
	public static String sendRequest(String url) {

		InputStream inputStream = null;
		BufferedReader bufferedReader = null;
		HttpURLConnection httpURLConnection = null;
		try {
			URL requestURL = new URL(url);
			// 获取连接
			httpURLConnection = (HttpURLConnection) requestURL.openConnection();
			httpURLConnection.setConnectTimeout(10000);	//建立连接的超时时间,毫秒
			httpURLConnection.setReadTimeout(25000);	//获得返回的超时时间,毫秒
			httpURLConnection.setRequestMethod("GET");

			// 通过输入流获取请求的内容
			inputStream = httpURLConnection.getInputStream();
			bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
			String temp = null;
			StringBuffer stringBuffer = new StringBuffer();
			// 循环读取返回的结果
			while ((temp = bufferedReader.readLine()) != null) {
				stringBuffer.append(temp);
			}

			return stringBuffer.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			//断开连接
			if (httpURLConnection!=null) {
				httpURLConnection.disconnect();
			}
			// 关闭流
			if(bufferedReader!=null){
					try {
						bufferedReader.close();
					} catch (IOException e) {
						e.printStackTrace();
					}

			}
			if(inputStream!=null){
					try {
						inputStream.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
			}

		}
		return null;

	}

	/**
	 * 构造请求地址URL
	 * @param paramMap 请求参数
	 * @return URL
	 */
	private static String buildUrl(Map<String, String> paramMap){
		String url = null;
		StringBuffer urlString = new StringBuffer();
		urlString.append(ipAndPort).append(version).append(apiName);

		if (!paramMap.isEmpty()) {
			// 参数列表不为空,地址尾部增加'?'
			urlString.append('?');
			// 拼接参数
			Set<Map.Entry<String, String>> entrySet = paramMap.entrySet();
			for (Map.Entry<String, String> entry : entrySet) {
				try {
					urlString.append(entry.getKey()).append('=').append(URLEncoder.encode(entry.getValue(), "UTF-8")).append('&');
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
			}
			// 去掉最后一个字符“&”
			url = urlString.substring(0, urlString.length() - 1);
		}
		return url;
	}

	public static void main(String[] args) throws IOException {
		// 封装请求接口的参数,需要按实际环境修改
		HashMap<String, String> map = new HashMap<>();
		map.put("appid", "A0B40MV");
		map.put("ebid", "0001000000346");
		map.put("transid", "A0B40MV2016090714165048673959");
		map.put("token", "0be65e363333039c46bf9244aaddd5876970bcf052cb18e9a4ea11e0a06685b3");
		map.put("query_date", "20170625");
		map.put("msisdns", "1064826090232_1064826029898_1064826029896_1064826090209_1064826090283_1064826090212_1064826090284");

		// 通过参数构造请求URL和参数
		String url = buildUrl(map);
		// 获取接口返回信息
		String result = sendRequest(url);
		System.out.println(result);

	}
}

<?php
        //设置页面显示编码UTF-8
        header("Content-Type: text/html;charset=utf-8");
        // 请求URL的IP和端口,需要按实际环境修改
        $ipAndPort = "http://api.iot.10086.cn";
        // 请求的版本号
        $version = "/v2";
        // 请求具体的接口名称
        $apiName = "/batchgprsusedbydate";

            /**
             * 请求API的方法
             * @param GET方式请求地址 $URL
             * @return 返回请求的数据
             */
            function requestAPI($URL) {
                //创建一个新的CURL资源赋值给 $curl
                $curl=curl_init();
                //设置URL
                curl_setopt($curl, CURLOPT_URL, $URL);
                //执行请求
                $result=curl_exec($curl);
                // ===用于区分空输入和布尔值false
                if ($result===false) {
                    echo "error !  plese check you requset url...";
                }
                //释放资源
                curl_close($curl);
                return $result;

            }

            /**
             * 构造URL方法
             * @param unknown $params
             */
            function buildURL($params){
                $strURL=null;
                foreach ($params as $key=>$value){
                    $strURL=$strURL.$key."=".urlencode($value)."&";
                }
                //去除最后一个"&";
                $strURL=substr($strURL, 0, -1);
                global  $ipAndPort;
                global  $version;
                global  $apiName;
                //拼接URL
                $strURL=$ipAndPort.$version.$apiName.'?'.$strURL;
                return  $strURL;
            }
            //定义参数,需要按实际环境修改
            $params=array(

                'token'=>'0be65e363333039c46bf9244aaddd5876970bcf052cb18e9a4ea11e0a06685b3',
                'appid'=>'A0B40MV',
                'transid'=>'A0B40MV2016090714165048673959',
                'ebid'=>'0001000000346',
                'query_date'=>'20170625',
                'msisdns'=>'1064826090232_1064826029898_1064826029896_1064826090209_1064826090283_1064826090212_1064826090284'
            );

            $requestURL=buildURL($params);
            requestAPI($requestURL);
?>

# -*- coding: utf-8 -*-
'''
@author IOT Python2.79请求API服务平台接口

#CMIOT_API2010	流量信息批量查询
'''

import urllib, urllib2,datetime


def send_request_get(ipAndPort,version,api_name,**kwargs):
    '''
    说明:组装url并调用接口
    :param ipAndPort: ip及端口信息
    :param version: 版本号
    :param api_name: api名称
    :param kwargs:  参数
    :return: 调用API返回的信息
    '''
    base_url = ipAndPort + version + api_name
    params = urllib.urlencode(kwargs)
    url = '?'.join([base_url,params])
    print u'调用URL:'+url

    try:
        response = urllib2.urlopen(url)
    except urllib2.URLError,e:
        raise ValueError(e)
    response_message = response.read()
    return response_message

def get_last_date(s_format='%Y%m%d',num=5):
    """
    说明:根据传入格式,获取前5天的日期
    :param s_format: 返回时间的格式
    :param num 输入几就是查询几天天的数据
    :return:时间格式字符串
    """
    if num == None:
        last_date = datetime.datetime.now()
    elif s_format =='%Y%m':
        last_date = datetime.datetime.now() - datetime.timedelta(days=30)
    else:
        last_date = datetime.datetime.now() - datetime.timedelta(days=num)

    return str(last_date.strftime(s_format))

class API_Demo_Request:
    #CMIOT_API2010	流量信息批量查询
    def test_03_CMIOT_API2010(self):
    #1.接口的参数及数据准备
    appid = "A0B40MV"                #应用编码--需要按实际环境修改
    transid = "A0B40MV2016090714165048673959" #transid--需要按实际环境修改
    ebid = "0001000000346"                 #能力编码--需要按实际环境修改
    token = "0be65e363333039c46bf9244aaddd5876970bcf052cb18e9a4ea11e0a06685b3" #token--需要按实际环境修改
    query_date = get_last_date(s_format='%Y%m%d')   #查询日期--需要按实际环境修改
    msisdn = "1064826090232_1064826029898_1064826029896_1064826090209_1064826090283_1064826090212_1064826090284"               #MISDN 号码--需要按实际环境修改
    api_name = "batchgprsusedbydate"        #请求具体的接口名称
    ipAndPort = "http://api.iot.10086.cn" #请求URL的IP和端口--需要按实际环境修改
    version = "/v2/"   #请求的版本号--需要按实际环境修改

    #2.接口调用"
    #接口调用格式https://api.iot.10086.cn/v2/batchgprsusedbydate?appid=xxx&ebid=xxx&transid=xxx&token=xxx&query_date=xxx&msisdns=xxx_xxx
    response_message = send_request_get(ipAndPort,version,api_name,appid=appid,ebid=ebid,transid=transid,token=token,query_date=query_date,msisdns=msisdn)

        #3.接口调用返回的信息
        print response_message

if __name__=='__main__':
    API_Demo_Request().test_03_CMIOT_API2010()
                    

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;


namespace HttpDemo
{
    class Program
    {
        static void Main(string[] args)
        {
			//CMIOT_API2010	流量信息批量查询
            string domain = "http://api.iot.10086.cn/v2/";//需要按照实际环境修改
			string enabler = "batchgprsusedbydate";

            //以下业务参数需要根据实际情况修改
            string appid = "A3CI163";   //应用编号
            string transid = "A3CI1632017051214010379823456";//事务编码
            string ebid = "0001000000027";//能力编号
            string token = "4b524a2958e823bd9245f733dc9a38a14784baef5151edf0f532296611c07564";
            string msisdns = "1064826090232_1064826029898_1064826029896_1064826090209_1064826090283_1064826090212_1064826090284";  //msisdns、imsis、iccids 三个参数有且仅有一个即可,多个卡号以下划线分割
            string query_date = "20170701";     //支持一周内的数据查询

            string paramters = "?appid=" + appid + "&transid=" + transid + "&ebid=" + ebid + "&token=" + token + "&msisdns=" + msisdns + "&query_date=" + query_date;     //msisdns 可改为imsis或iccids
            string uri = domain + enabler + paramters;
            string response = RequestSync(uri, "post");  //同步get请求把post改为get即可
            Debug.WriteLine(response);
            Console.ReadLine();
        }

		//同步get 或 post
        public static string RequestSync(string uri, string method)
        {
            WebRequest request = WebRequest.Create(uri);
            //get 或者 post
            request.Method = method;
            //读取返回消息
            string res = string.Empty;
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                res = reader.ReadToEnd();
                reader.Close();
            }
            catch (Exception ex)
            {
                res = ex.ToString();
            }
            return res;
        }
    }
}

API响应示例

                {
"message": "正确",
"result": [
    {
        "ICCID": "898602B2221340000878",
        "IMSI": "460040260900788",
        "MSISDN": "1064826090232",
        "SMS": "0"
    },
    {
        "ICCID": "898602B2221340001456",
        "IMSI": "460040260990087",
        "MSISDN": "1064826029898",
        "SMS": "0"
    },
    {
        "ICCID": "898602B2221340058954",
        "IMSI": "460040260944556",
        "MSISDN": "1064826029896",
        "SMS": "0"
    },
    {
        "ICCID": "898602B2221340044444",
        "IMSI": "460040260911223",
        "MSISDN": "1064826090209",
        "SMS": "0"
    },
    {
        "ICCID": "898602B2221340055373",
        "IMSI": "460040260954321",
        "MSISDN": "1064826090283",
        "SMS": "0"
    },
    {
        "ICCID": "898602B2221340336580",
        "IMSI": "460040260912345",
        "MSISDN": "1064826090212",
        "SMS": "0"
    },
    {
        "ICCID": "898602B2221340011223",
        "IMSI": "460040260966833",
        "MSISDN": "1064826090284",
        "SMS": "0"
    }
],
"status": "0"
}
            

错误码

  • 查看错误码

API工具

  • token生成工具
  • SDK工具下载