通过Webservice查询手机号码归属地

public class SearchLocationTask extends AsyncTask{
		private String methodName;
		private String soapAction;
		private String phoneNum;
		private String getPropertyName;
		public SearchLocationTask(String phoneNum){
			this.methodName = Constant.GET_LOCATION_METHOD_NAME;
			this.soapAction = Constant.GET_LOCATION_SOAP_ACTION;
			this.phoneNum= phoneNum;
			this.getPropertyName = Constant.GET_LOCATION_RESULT_NAME;
		}
		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			SoapObject detail = null;
			Object result = null;
			try{
			SoapObject rpc = new SoapObject(Constant.NAMESPACE, methodName);
			rpc.addProperty("mobileCode", phoneNum);
			Looper.prepare();
			HttpTransportSE ht = new HttpTransportSE(Constant.URL);
			ht.debug = true;
			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			envelope.bodyOut = rpc;
			envelope.dotNet = true;
			envelope.setOutputSoapObject(rpc);
			ht.call(soapAction, envelope);
			detail = (SoapObject) envelope.bodyIn;
			result =  detail.getProperty(getPropertyName);
			}catch(Exception e){
				e.printStackTrace();
			}
			return result;
		}
		@Override
		protected void onPostExecute(Object result) {
			// TODO Auto-generated method stub
			super.onPostExecute(result);
			/**
			 * 解析数据
			 */
			String resultStr = result.toString();
			String[] resultList = resultStr.split(" ");
			if(resultList.length == 1){
			        //获取字符串汇中的中文列表
				Util.showMessageByToast(currentContext, resultList[0]);
			}else{
			//获取省份名
			String province = Constant.GetChineseWord(resultList[0]).get(0);
			//获取城市名
			String city = resultList[1];
			int length = province.length()+2;
			//获取运营商
			String service = resultList[2].substring(0,length);
			//获取卡类型
			String cardType = resultList[2].substring(length);
			//展示
			//......
			}
		}
	}
public class Constant {
	/**
	 * 命名空间
	 */
	public static final String NAMESPACE = "http://WebXml.com.cn/";
	/**
	 * 获取归属地信息URL
	 */
	public static String URL = "http://www.webxml.com.cn/webservices/MobileCodeWS.asmx";
	/**
	 * 获得归属地方法名
	 */
	public static String GET_LOCATION_METHOD_NAME = "getMobileCodeInfo";
	/**
	 * 获得归属地soapAction
	 */
	public static String GET_LOCATION_SOAP_ACTION = "http://WebXml.com.cn/getMobileCodeInfo";
	/**
	 * 获取归属地返回数据key
	 */
	public static String GET_LOCATION_RESULT_NAME = "getMobileCodeInfoResult";
	/**
	 * 获取字符串中的中文列表
	 * @param oriText
	 * @return
	 */
	public static List<String> GetChineseWord(String str_text)
	{
		List<String> chineseWordsList = new ArrayList<String>();
		String reg="([\u4e00-\u9fa5]+)";
		Matcher matcher = Pattern.compile(reg).matcher(str_text);
		while(matcher.find()){
			chineseWordsList.add(matcher.group());
		}
		return chineseWordsList;
	}
}


转载于:https://my.oschina.net/sorthWindow/blog/336252

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值