JAVA,Ajax 查詢手機號碼歸屬地 地址

在網上找了不少、若是根據網絡提供的API直接JS Ajax查詢會出問題:拒絕訪問 html

網上說是跨域了、解決辦法就是java後臺訪問這個API地址。下面羅列一些網絡上的API地址。 java

手機網 json

http://api.showji.com/Locating/www.showji.com.aspx?m=13524799521&output=json&callback=querycallback api

淘寶網

API地址: http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=13524799521
參數: 跨域

  • tel:手機號碼
  • 返回:JSON

拍拍

API地址: http://virtual.paipai.com/extinfo/GetMobileProductInfo?mobile=13524799521&amount=10000&callname=getPhoneNumInfoExtCallback
參數: 網絡

  • mobile:手機號碼
  • callname:回調函數
  • amount:未知(必須)
  • 返回:JSON

財付通

API地址: http://life.tenpay.com/cgi-bin/mobile/MobileQueryAttribution.cgi?chgmobile=13524799521
參數: 函數

  • chgmobile:手機號碼
  • 返回:xml

百付寶

API地址: https://www.baifubao.com/callback?cmd=1059&callback=phone&phone=13524799521
參數: jsonp

  • phone:手機號碼
  • callback:回調函數
  • cmd:未知(必須)
  • 返回:JSON

115

API地址: http://cz.115.com/?ct=index&ac=get_mobile_local&callback=jsonp1333962541001&mobile=13524799521
參數: url

  • mobile:手機號碼
  • callback:回調函數
  • 返回:JSON

有道

API地址: http://www.youdao.com/smartresult-xml/search.s?jsFlag=true&type=mobile&q=13524799521
參數: spa

  • type:mobile(表示查詢手機號碼)
  • q:手機號碼
  • 返回:JSON

我用的是有道的API、下面是代碼:

function findPhoneAddres(){
				   var mobile = $("#usermobil").val();  
                   var urlAction = "<%=path %>/customermanage/listcustomerinfo!findPhoneAddres.action";
			       $.get(urlAction, {phoneStr:mobile}, function (data){
			    	    if(data==''||data==null){
			    	    	alertMsg.info("找不到您輸入的手機號碼歸屬地!");    
			    	    }else{
			    	    	var json = eval("("+data+")");    
							var phoneStr = json.location ;
							$("#userAddres").val(phoneStr.split(" ")[1]); 
							$("#userAddresByPhone").val(phoneStr.split(" ")[1]);    
							$("#userAddresLabel").html("手機號歸屬地:"+phoneStr.split(" ")[1])
			    	    }  
					});     
}
JAVA
/*
	 * 手機號碼歸屬地查詢地址
	 */
	private final String urlAddres = "http://www.youdao.com/smartresult-xml/search.s?" +
									 "jsFlag=true&type=mobile&q=";
       /**
	 * 查詢手機號碼歸屬地
	 * @return * @throws Exception
	 */
	public String findPhoneAddres() throws Exception{
		String phone = request.getParameter("phoneStr");
		String url = urlAddres+phone;    
		String result = ActionURL.callUrlByGet(url, "GBK");  
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();  
		out.print(result);  
		out.close();     
		return null;
	}
相關文章
相關標籤/搜索