[java]代码库import java.io.BufferedReader;

import java.io.DataOutputStream;

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 net.sf.json.JSONObject;

/**

*苹果序列号调用示例代码 - 聚合数据

*在线接口文档:http://www.juhe.cn/docs/37

**/

public class JuheDemo {

public static final String DEF_CHATSET = "UTF-8";

public static final int DEF_CONN_TIMEOUT = 30000;

public static final int DEF_READ_TIMEOUT = 30000;

public static String userAgent =  "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";

//配置您申请的KEY

public static final String APPKEY ="*************************";

//1.苹果序列号/IMEI号查询

public static void getRequest1(){

String result =null;

String url ="http://apis.juhe.cn/appleinfo/index";//请求接口地址

Map params = new HashMap();//请求参数

params.put("sn","");//苹果产品的序列号或IMEI号

params.put("dtype","");//返回数据格式:json或xml,默认json

params.put("key",APPKEY);//你申请的key

try {

result =net(url, params, "GET");

JSONObject object = JSONObject.fromObject(result);

if(object.getInt("error_code")==0){

System.out.println(object.get("result"));

}else{

System.out.println(object.get("error_code")+":"+object.get("reason"));

}

} catch (Exception e) {

e.printStackTrace();

}

}

public static void main(String[] args) {

}

/**

*

* @param strUrl 请求地址

* @param params 请求参数

* @param method 请求方法

* @return  网络请求字符串

* @throws Exception

*/

public static String net(String strUrl, Map params,String method) throws Exception {

HttpURLConnection conn = null;

BufferedReader reader = null;

String rs = null;

try {

StringBuffer sb = new StringBuffer();

if(method==null || method.equals("GET")){

strUrl = strUrl+"?"+urlencode(params);

}

URL url = new URL(strUrl);

conn = (HttpURLConnection) url.openConnection();

if(method==null || method.equals("GET")){

conn.setRequestMethod("GET");

}else{

conn.setRequestMethod("POST");

conn.setDoOutput(true);

}

conn.setRequestProperty("User-agent", userAgent);

conn.setUseCaches(false);

conn.setConnectTimeout(DEF_CONN_TIMEOUT);

conn.setReadTimeout(DEF_READ_TIMEOUT);

conn.setInstanceFollowRedirects(false);

conn.connect();

if (params!= null && method.equals("POST")) {

try {

DataOutputStream out = new DataOutputStream(conn.getOutputStream());

out.writeBytes(urlencode(params));

} catch (Exception e) {

// TODO: handle exception

}

}

InputStream is = conn.getInputStream();

reader = new BufferedReader(new InputStreamReader(is, DEF_CHATSET));

String strRead = null;

while ((strRead = reader.readLine()) != null) {

sb.append(strRead);

}

rs = sb.toString();

} catch (IOException e) {

e.printStackTrace();

} finally {

if (reader != null) {

reader.close();

}

if (conn != null) {

conn.disconnect();

}

}

return rs;

}

//将map型转为请求参数型

public static String urlencode(Mapdata) {

StringBuilder sb = new StringBuilder();

for (Map.Entry i : data.entrySet()) {

try {

sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue()+"","UTF-8")).append("&");

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

}

}

return sb.toString();

}

}

java调用序列_基于JAVA的苹果序列号接口调用代码实例相关推荐

  1. python名片识别_基于Python的名片识别接口调用代码实例

    基于Python的名片识别接口调用代码实例 代码描述:基于Python的名片识别接口调用代码实例 #!/usr/bin/python # -*- coding: utf-8 -*- import js ...

  2. python名片打印程序代码_基于Python的名片识别接口调用代码实例

    #!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib import urlencode #-------- ...

  3. 使用php进行财务统计,基于php的基金财务数据接口调用代码实例

    代码描述:基于php的基金财务数据接口调用代码实例 关联数据:基金财务数据 接口地址:http://www.juhe.cn/docs/api/id/28 1.[代码][PHP]代码 // +----- ...

  4. 名片识别信息分类python_基于Python的名片识别接口调用代码实例.doc

    基于Python的名片识别接口调用代码实例 代码描述:基于Python的名片识别接口调用代码实例 #!/usr/bin/python # -*- coding: utf-8 -*- import js ...

  5. 时刻表的选择php代码,基于php的火车时刻表接口调用代码实例

    基于php的火车时刻表接口调用代码实例 代码描述:基于php的火车时刻表接口调用代码实例 代码平台:聚合数据 // +----------------------------------------- ...

  6. python短信接口_基于 python 的短信接口调用代码示例模板

    阅信短信验证码平台最近会从新梳理基于不同语言的短信接口调用代码示例,是为了迎合市面上现在流行的各个语言代码实现,也是为了能够更好的服务满足客户的不同层次的需求. 下面的代码是基于 python 的短信 ...

  7. python开发环境一般用哪个快递_基于Python的常用快递sdk调用代码实例

    #!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib import urlencode #-------- ...

  8. 名片识别信息分类python_基于PYTHON的名片识别接口调用代码实例

    #!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib import urlencode #-------- ...

  9. java 金数据推送数据_基于JAVA的黄金数据接口调用代码实例

    代码描述:基于JAVA的黄金数据接口调用代码实例 接口地址:http://www.juhe.cn/docs/api/id/29 1.[代码][Java]代码 import java.io.Buffer ...

最新文章

  1. 赢在中国(08-02-27)
  2. 文本去重之MinHash算法——就是多个hash函数对items计算特征值,然后取最小的计算相似度...
  3. 玛塔机器人函数_玛塔创想编程机器人套装包含什么?
  4. 设计模式-创建型-生成器
  5. 30秒就能学会一个Python小技巧?
  6. LeetCode 991. 坏了的计算器(逆向思考)
  7. 字符串String的trim()方法
  8. 服务器驱动器输入信号,伺服驱动器超大齿轮比驱动控制方法
  9. 谁说国产操作系统没救了? | 人物志
  10. 机器学习工具在数据中心的应用与发展
  11. html余下的高度,html – 使第二行的弹性项目占据容器的剩余高度
  12. ubuntu 黑体_Ubuntu 10.04下安装字体最简单的方法
  13. unity2d物体3d效果
  14. 基于C++的关键字检索系统
  15. python爬虫股票上证指数_Python爬虫爬取搜狐证券股票数据
  16. win10、win7系统重装教程
  17. win10调节桌面显示计算机,Win10系统电脑屏幕的饱和度如何调整?
  18. 随机过程(2)__马尔可夫链的主要性质__查普曼-科莫高洛夫方程
  19. 4. 存储过程 · sql编程
  20. Unity3d Ugui图片上制作点光 、棱形光效果shader,并具有裁切

热门文章

  1. 金三银四面试必问:AQS了解吗?
  2. HTTP状态码(100,200,300,400,500)
  3. 从零开始长期给某开源社区提PR步骤记录
  4. mysql的存储过程的参数_MySQL 存储过程参数
  5. Guava简介(详细)
  6. Redis 交集并集差集
  7. Linux学习有用吗?学习用linux
  8. 瑞格尔侯爵葡萄酒之城大师班
  9. 数据仓库之【用户行为数仓】01:项目效果展示、背景
  10. 2020最新版java学习路线