java调用序列_基于JAVA的苹果序列号接口调用代码实例
[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的苹果序列号接口调用代码实例相关推荐
- python名片识别_基于Python的名片识别接口调用代码实例
基于Python的名片识别接口调用代码实例 代码描述:基于Python的名片识别接口调用代码实例 #!/usr/bin/python # -*- coding: utf-8 -*- import js ...
- python名片打印程序代码_基于Python的名片识别接口调用代码实例
#!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib import urlencode #-------- ...
- 使用php进行财务统计,基于php的基金财务数据接口调用代码实例
代码描述:基于php的基金财务数据接口调用代码实例 关联数据:基金财务数据 接口地址:http://www.juhe.cn/docs/api/id/28 1.[代码][PHP]代码 // +----- ...
- 名片识别信息分类python_基于Python的名片识别接口调用代码实例.doc
基于Python的名片识别接口调用代码实例 代码描述:基于Python的名片识别接口调用代码实例 #!/usr/bin/python # -*- coding: utf-8 -*- import js ...
- 时刻表的选择php代码,基于php的火车时刻表接口调用代码实例
基于php的火车时刻表接口调用代码实例 代码描述:基于php的火车时刻表接口调用代码实例 代码平台:聚合数据 // +----------------------------------------- ...
- python短信接口_基于 python 的短信接口调用代码示例模板
阅信短信验证码平台最近会从新梳理基于不同语言的短信接口调用代码示例,是为了迎合市面上现在流行的各个语言代码实现,也是为了能够更好的服务满足客户的不同层次的需求. 下面的代码是基于 python 的短信 ...
- python开发环境一般用哪个快递_基于Python的常用快递sdk调用代码实例
#!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib import urlencode #-------- ...
- 名片识别信息分类python_基于PYTHON的名片识别接口调用代码实例
#!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib import urlencode #-------- ...
- java 金数据推送数据_基于JAVA的黄金数据接口调用代码实例
代码描述:基于JAVA的黄金数据接口调用代码实例 接口地址:http://www.juhe.cn/docs/api/id/29 1.[代码][Java]代码 import java.io.Buffer ...
最新文章
- 赢在中国(08-02-27)
- 文本去重之MinHash算法——就是多个hash函数对items计算特征值,然后取最小的计算相似度...
- 玛塔机器人函数_玛塔创想编程机器人套装包含什么?
- 设计模式-创建型-生成器
- 30秒就能学会一个Python小技巧?
- LeetCode 991. 坏了的计算器(逆向思考)
- 字符串String的trim()方法
- 服务器驱动器输入信号,伺服驱动器超大齿轮比驱动控制方法
- 谁说国产操作系统没救了? | 人物志
- 机器学习工具在数据中心的应用与发展
- html余下的高度,html – 使第二行的弹性项目占据容器的剩余高度
- ubuntu 黑体_Ubuntu 10.04下安装字体最简单的方法
- unity2d物体3d效果
- 基于C++的关键字检索系统
- python爬虫股票上证指数_Python爬虫爬取搜狐证券股票数据
- win10、win7系统重装教程
- win10调节桌面显示计算机,Win10系统电脑屏幕的饱和度如何调整?
- 随机过程(2)__马尔可夫链的主要性质__查普曼-科莫高洛夫方程
- 4. 存储过程 · sql编程
- Unity3d Ugui图片上制作点光 、棱形光效果shader,并具有裁切