2019独角兽企业重金招聘Python工程师标准>>>
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;}@Overrideprotected Object doInBackground(Object... params) {// TODO Auto-generated method stubSoapObject 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;}@Overrideprotected void onPostExecute(Object result) {// TODO Auto-generated method stubsuper.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
}