핸드폰 번호 귀속지 조회 무료api 인터페이스 코드

5270 단어
휴대전화 번호에 따라 사용자의 카드 유형, 운영자, 귀속지, 지역 등 정보를 조회한다.
휴대전화 귀속지 실체류
package org.wx.xhelper.model;

/**
 *      
 * @author wangxw
 * @version 1.0
 * @date Jul 9, 2014 4:03:04 PM
 */
public class PhoneBelong {

	//     
	private String phone;
	
	//           
	private String area;
	
	//      
	private String ctype;
	
	//      
	private String operators;
	
	//      
	private String simcall;

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getCtype() {
		return ctype;
	}

	public void setCtype(String ctype) {
		this.ctype = ctype;
	}

	public String getOperators() {
		return operators;
	}

	public void setOperators(String operators) {
		this.operators = operators;
	}

	public String getSimcall() {
		return simcall;
	}

	public void setSimcall(String simcall) {
		this.simcall = simcall;
	}
}

핸드폰 귀속지 서비스 인터페이스류
package org.wx.xhelper.service;

import java.io.UnsupportedEncodingException;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.wx.xhelper.model.PhoneBelong;

/**
 *           
 * @author wangxw
 * @version 1.0
 * @date Jul 9, 2014 4:07:11 PM
 */
public class PhoneBelongService {
	
	/**
	 *          
	 * @param phone
	 * @return        
	 * @throws UnsupportedEncodingException
	 */
	public static String getPhoneBelongDetail(String phone) throws UnsupportedEncodingException{
		//        
		PhoneBelong phoneBelong = getPhoneBelong(phone);
		
		//       
		StringBuffer news = new StringBuffer();
		
		if (phoneBelong != null) {
			news.append("  :"+phoneBelong.getPhone()).append("
"); news.append(" :"+phoneBelong.getArea()).append("
"); news.append(" :"+phoneBelong.getCtype()).append("
"); news.append(" :"+phoneBelong.getOperators()).append("
"); news.append(" :"+phoneBelong.getSimcall()).append("

"); } if(news.length() == 0){ news.append(" ").append(phone).append(" , !"); } // 2048 if(news.toString().getBytes("UTF-8").length > 2048){ return news.substring(0, 2000/3).concat("..."); } return news.toString(); } /** * * @param phone * @return */ public static PhoneBelong getPhoneBelong(String phone){ URL url = null; PhoneBelong phoneBelong = new PhoneBelong(); try{ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); url = new URL("http://api.k780.com:88/?app=phone.get&phone="+phone+"&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=xml"); Document doc = builder.parse(url.openStream()); NodeList node = doc.getElementsByTagName("result"); for(int i=0;i<node.getLength();i++){ String area = ""; String ctype = ""; String operators = ""; String simcall = ""; if(doc.getElementsByTagName("area").item(i).getFirstChild() != null){ area = doc.getElementsByTagName("area").item(i).getFirstChild().getNodeValue(); } if(doc.getElementsByTagName("ctype").item(i).getFirstChild() != null){ ctype = doc.getElementsByTagName("ctype").item(i).getFirstChild().getNodeValue(); } if(doc.getElementsByTagName("operators").item(i).getFirstChild() != null){ operators = doc.getElementsByTagName("operators").item(i).getFirstChild().getNodeValue(); } if(doc.getElementsByTagName("style_simcall").item(i).getFirstChild() != null){ simcall = doc.getElementsByTagName("style_simcall").item(i).getFirstChild().getNodeValue(); } phoneBelong.setPhone(phone); phoneBelong.setArea(area); phoneBelong.setCtype(ctype); phoneBelong.setOperators(operators); phoneBelong.setSimcall(simcall); } }catch(Exception e){ e.printStackTrace(); } return phoneBelong; } }

질의 결과:
번호: 13800138000 지역번호: 010카드 유형: 모바일 글로벌 카드 운영자: 모바일 귀속지: 중국, 베이징

좋은 웹페이지 즐겨찾기