com.lidroid.xutils.http.RequestParams Java Examples

The following examples show how to use com.lidroid.xutils.http.RequestParams. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpRequest.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
public void setRequestParams(RequestParams param, RequestCallBackHandler callBackHandler) {
    if (param != null) {
        if (uriCharset == null) {
            uriCharset = Charset.forName(param.getCharset());
        }
        List<RequestParams.HeaderItem> headerItems = param.getHeaders();
        if (headerItems != null) {
            for (RequestParams.HeaderItem headerItem : headerItems) {
                if (headerItem.overwrite) {
                    this.setHeader(headerItem.header);
                } else {
                    this.addHeader(headerItem.header);
                }
            }
        }
        this.addQueryStringParams(param.getQueryStringParams());
        HttpEntity entity = param.getEntity();
        if (entity != null) {
            if (entity instanceof UploadEntity) {
                ((UploadEntity) entity).setCallBackHandler(callBackHandler);
            }
            this.setEntity(entity);
        }
    }
}
 
Example #2
Source File: HttpRequest.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
public void setRequestParams(RequestParams param) {
    if (param != null) {
        if (uriCharset == null) {
            uriCharset = Charset.forName(param.getCharset());
        }
        List<RequestParams.HeaderItem> headerItems = param.getHeaders();
        if (headerItems != null) {
            for (RequestParams.HeaderItem headerItem : headerItems) {
                if (headerItem.overwrite) {
                    this.setHeader(headerItem.header);
                } else {
                    this.addHeader(headerItem.header);
                }
            }
        }
        this.addQueryStringParams(param.getQueryStringParams());
        this.setEntity(param.getEntity());
    }
}
 
Example #3
Source File: HttpFragment.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
/**
	 * post请求数据
	 * @param view
	 */
	@OnClick(R.id.post)
	public void post(View view) {
		//这个地址只支持get, 这里只是示范。
		String url = "http://www.weather.com.cn/data/cityinfo/101010100.html"; 
		RequestParams params = new RequestParams();
		/*		//添加请求参数
		params.addBodyParameter(key, value);*/
		
/*		//添加请求头
		params.addHeader(name, value);*/
		http.send(HttpMethod.POST, url, params, new RequestCallBack<String>() {

			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				data.setText(responseInfo.result);
			}

			@Override
			public void onFailure(HttpException error, String msg) {
				Toast.makeText(getActivity(), "访问失败" + msg, Toast.LENGTH_SHORT).show();
			}
			
		});
		
	}
 
Example #4
Source File: HttpFragment.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
/**
	 * get请求数据
	 * @param view
	 */
	@OnClick(R.id.get)
	public void get(View view) {
		String url = "http://www.weather.com.cn/data/cityinfo/101010100.html";
		RequestParams params = new RequestParams();
/*		//添加请求参数
		params.addBodyParameter(key, value);*/
		
/*		//添加请求头
		params.addHeader(name, value);*/
		http.send(HttpMethod.GET, url, params, new RequestCallBack<String>() {

			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				data.setText(responseInfo.result);
			}

			@Override
			public void onFailure(HttpException error, String msg) {
				Toast.makeText(getActivity(), "访问失败" + msg, Toast.LENGTH_SHORT).show();
			}
			
		});
	}
 
Example #5
Source File: PayHelperUtils.java    From Hook with Apache License 2.0 5 votes vote down vote up
public static void getTradeInfo(final Context paramContext, final String paramString) {
        Log.i("tag", "getTradeInfo:1 ");
        long l = System.currentTimeMillis();
        String str1 = getCurrentDate();
        String str2 = "https://mbillexprod.alipay.com/enterprise/simpleTradeOrderQuery.json?beginTime=" + (l - 864000000L) + "&limitTime=" + l + "&pageSize=20&pageNum=1&channelType=ALL";
        HttpUtils localHttpUtils = new HttpUtils(15000);
        localHttpUtils.configResponseTextCharset("GBK");
        RequestParams localRequestParams = new RequestParams();
        localRequestParams.addHeader("Cookie", paramString);
        localRequestParams.addHeader("Referer", "https://render.alipay.com/p/z/merchant-mgnt/simple-order.html?beginTime=" + str1 + "&endTime=" + str1 + "&fromBill=true&channelType=ALL");
        localHttpUtils.send(HttpRequest.HttpMethod.GET, str2, localRequestParams, new RequestCallBack() {
            public void onFailure(HttpException paramAnonymousHttpException, String paramAnonymousString) {
//                PayHelperUtils.sendmsg(PayHelperUtils.this, "服务器异常" + paramAnonymousString);
                Log.i("tag", "服务器异常");
            }

            public void onSuccess(ResponseInfo paramAnonymousResponseInfo) {
                String result = (String) paramAnonymousResponseInfo.result;
                try {
                    Log.i("tag", "getTradeInfo2" + result);
                    JSONArray array = new JSONObject(result).getJSONObject("result").getJSONArray("list");
                    if ((array != null) && (array.length() > 0)) {
                        String json = array.getJSONObject(0).getString("tradeNo");
                        Log.i("tag", "getTradeInfo3" + json);
                        Intent localIntent = new Intent();
                        localIntent.putExtra("tradeno", json);
                        localIntent.putExtra("cookie", paramString);
                        localIntent.setAction(Constans.ACTION_PAY_SUCCESS);
                        paramContext.sendBroadcast(localIntent);
//                        EventBus.getDefault().post(new MessageEvent(MessageEvent.MessageType.TRADENORECEIVED_ACTION,json,paramString));
                    }
                    return;
                } catch (Exception p) {
//                    PayHelperUtils.sendmsg(PayHelperUtils.this, "getTradeInfo异常" + paramAnonymousResponseInfo.getMessage());
                    Log.i("tag", "getTradeInfo异常" + p.getMessage());
                }
            }
        });
    }
 
Example #6
Source File: test.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
public void test3(){

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("uname", "中文");
        //params.addHeader("appkey" , "0000001");
        HttpUtils http = new HttpUtils();
        try {
            ResponseStream responseStream = http.sendSync(HttpRequest.HttpMethod.POST,
            		"http://10.0.2.2:8080/ALLGO_SERVER/login", params);
            Log.i("Http" , responseStream.readString() ) ;
        } catch (Exception e) {
            LogUtils.e(e.getMessage(), e);
        }
    
	}
 
Example #7
Source File: test.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
public void test4(){
       RequestParams params = new RequestParams();
       params.addQueryStringParameter("uname", "中文");
       HttpUtils http = new HttpUtils();
       http.send(HttpRequest.HttpMethod.POST,
               "http://192.168.1.104:8080/ALLGO_SERVER/login",
               params,
               new RequestCallBack<String>() {

                   @Override
                   public void onStart() {
                   	Log.i("Http" ,"onStart" ) ;
                   }

                   @Override
                   public void onLoading(long total, long current, boolean isUploading) {
                   }

                   @Override
                   public void onSuccess(ResponseInfo<String> responseInfo) {
                   	Log.i("Http" , "onSuccess" + responseInfo.result ) ;
                   }

                   @Override
                   public void onFailure(HttpException error, String msg) {
                   	Log.i("Http" ,"error==>" +  msg ) ;
                   }
               });
}
 
Example #8
Source File: NetUtil.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化
 * @param uri
 * @param refresh
 * @param context
 * @param callback
 */
public NetUtil(String uri, RefreshInterFace refresh, Context context,NetCallBack callback) {
	super();
	this.uri = uri;
	this.refresh = refresh;
	this.context = context;
	this.callback = callback;
	declare =(MyDeclare)context.getApplicationContext();
	myParams= new HashMap<String,String>();
	params = new RequestParams();
}
 
Example #9
Source File: PullService.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
private void getOnePull() {
	SharedPreferences sharedPref = this.getSharedPreferences("userdata",Context.MODE_PRIVATE);
	RequestParams params = new RequestParams();
       params.addQueryStringParameter("uid", sharedPref.getInt("uid", -1) + "");
       SharedPreferences sharedPref1 = this.getSharedPreferences("appdata",Context.MODE_PRIVATE);
	params.addHeader("Cookie","JSESSIONID="+sharedPref1.getString("SessionId", ""));
       
       HttpUtils http = new HttpUtils();
       http.send(HttpRequest.HttpMethod.GET,
       		declare.getHost_url() + "remind/unread",
               params,
               new RequestCallBack<String>() {

				@Override
                   public void onStart() {
                   	Log.i(TAG ,"Pull==>onStart" ) ;
                   }

                   @Override
                   public void onLoading(long total, long current, boolean isUploading) {
                   }

                   @Override
                   public void onSuccess(ResponseInfo<String> responseInfo) {
					readingParse(responseInfo.result);
                   }
                   @Override
                   public void onFailure(HttpException error, String msg) {
                   	Log.i(TAG ,"Pull==>error==>" +  msg ) ;
                   }
               });
}
 
Example #10
Source File: XHttpHelper.java    From AndroidAppCodeFramework with Apache License 2.0 5 votes vote down vote up
/**
 *Get / Post 请求数据构造函数
 * @param url url地址
 * @param params 请求参数
 * @param isGetRequest 是否Get请求
 * @param callBack 请求回调函数
 */
public XHttpHelper(String url, RequestParams params, boolean isGetRequest, XHttpRequestDefaultCallBack callBack){
    this.url = url;
    this.params = params;
    if(callBack == null){
        this.callBack = new XHttpRequestDefaultCallBack();
    }else{
        this.callBack = callBack;
    }

    getHttpRequest(isGetRequest);
}
 
Example #11
Source File: XHttpHelper.java    From AndroidAppCodeFramework with Apache License 2.0 5 votes vote down vote up
/**
 *Get / Post 请求数据构造函数
 * @param url url地址
 * @param params 请求参数
 * @param isGetRequest 是否Get请求
 * @param callBack 请求回调函数
 */
public XHttpHelper(String url, RequestParams params, boolean isGetRequest, XHttpRequestDefaultCallBack callBack){
    this.url = url;
    this.params = params;
    if(callBack == null){
        this.callBack = new XHttpRequestDefaultCallBack();
    }else{
        this.callBack = callBack;
    }

    getHttpRequest(isGetRequest);
}
 
Example #12
Source File: JokeServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void getJokeById(final ApiCallBack apiCallBack, Integer jokeId) {
	HttpUtils http = new HttpUtils();
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	http.configDefaultHttpCacheExpiry(0); 
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("jokeId", String.valueOf(jokeId));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_GET_JOKE, params,
		new RequestCallBack<String>() {
			@SuppressWarnings("rawtypes")
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if(code == Constants.SUCCESS) {
					Log.e(TAG, "getJokeById success");
					Joke joke = FastjsonUtil.deserialize(
							map.get("data").toString(), Joke.class);
					apiCallBack.onSuccess(joke);
				} else {
					Log.e(TAG, "getJokeById fail, fail msg is " + map.get("msg"));
					apiCallBack.onFailure(String.valueOf(code));
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "getJokeById error", error);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					apiCallBack.onError(error, msg);
				}
			}
		});
}
 
Example #13
Source File: JokeServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void getCommentByJokeId(final Handler handler, int jokeId, int offset,
		int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(60); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("qushiId", String.valueOf(jokeId));
	params.addQueryStringParameter("offset", String.valueOf(offset));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_GET_COMMENTS, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE);
					return;
				}
				PageResult page = FastjsonUtil.deserialize(
						map.get("data").toString(), PageResult.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("pageResult", page);
				message.what = Constants.SUCCESS;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example #14
Source File: JokeServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void refushAll(final Handler handler, int newOrHotFlag, int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(0); //缓存超期时间0分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_LIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				try {
					String rs = responseInfo.result;
					Map map = FastjsonUtil.json2Map(rs);
					int code = Integer.parseInt(String.valueOf(map.get("code")));
					if (code != 200) {
						//请求失败
						handler.sendEmptyMessage(Constants.FAILURE);
						return;
					}
					PageResult page = FastjsonUtil.deserialize(
							map.get("data").toString(), PageResult.class);
					Message message = new Message();
					Bundle bundle = new Bundle();
					bundle.putSerializable("pageResult", page);
					message.what = Constants.SUCCESS_1;
					message.setData(bundle);
					handler.sendMessage(message);
				} catch (Exception e) {
					handler.sendEmptyMessage(Constants.FAILURE);
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example #15
Source File: MeiTuServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void refresh(final Handler handler, int newOrHotFlag, int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(0); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_LIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE);
					return;
				}
				PageResult page = FastjsonUtil.deserialize(
						map.get("data").toString(), PageResult.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("pageResult", page);
				message.what = Constants.SUCCESS_1;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example #16
Source File: QuTuServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
	public void refush(final Handler handler, int newOrHotFlag, int count) {
		HttpUtils http = new HttpUtils();
		http.configDefaultHttpCacheExpiry(0); //缓存超期时间0分钟
		http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
		RequestParams params = new RequestParams();
		params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
//		params.addQueryStringParameter("offset", String.valueOf(1));
		params.addQueryStringParameter("count", String.valueOf(count));
		http.send(HttpRequest.HttpMethod.GET,
			RcpUri.INTERFACE_URI_LIST, params,
			new RequestCallBack<String>() {
				@Override
				public void onSuccess(ResponseInfo<String> responseInfo) {
					String rs = responseInfo.result;
					Map map = FastjsonUtil.json2Map(rs);
					int code = Integer.parseInt(String.valueOf(map.get("code")));
					if (code != 200) {
						//请求失败
						handler.sendEmptyMessage(Constants.FAILURE);
						return;
					}
					PageResult page = FastjsonUtil.deserialize(
							map.get("data").toString(), PageResult.class);
					Message message = new Message();
					Bundle bundle = new Bundle();
					bundle.putSerializable("pageResult", page);
					message.what = Constants.SUCCESS_1;
					message.setData(bundle);
					handler.sendMessage(message);
				}
				@Override
				public void onFailure(HttpException error, String msg) {
					handler.sendEmptyMessage(Constants.FAILURE);
				}
			});
	}
 
Example #17
Source File: QuTuServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void getQuTu(final Handler handler, int newOrHotFlag, int offset,
		int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
	params.addQueryStringParameter("offset", String.valueOf(offset));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_LIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE);
					return;
				}
				PageResult page = FastjsonUtil.deserialize(
						map.get("data").toString(), PageResult.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("pageResult", page);
				message.what = Constants.SUCCESS;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example #18
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void reSetPassword(String phone, String password,
		final ApiCallBack apiCallBack) {
	HttpUtils http = new HttpUtils();
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	http.configDefaultHttpCacheExpiry(0); 
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("phone", phone);
	params.addQueryStringParameter("password", password);
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_RESET_PWD, params,
		new RequestCallBack<String>() {
			@SuppressWarnings("rawtypes")
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if(code == Constants.SUCCESS) {
					Log.e(TAG, "reSetPassword success");
					User user = FastjsonUtil.deserialize(
							map.get("data").toString(), User.class);
					apiCallBack.onSuccess(user);
				} else {
					Log.e(TAG, "reSetPassword fail, fail msg is " + map.get("msg"));
					apiCallBack.onFailure(String.valueOf(code));
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "reSetPassword error", error);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					apiCallBack.onError(error, msg);
				}
			}
		});
}
 
Example #19
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void checkUserExeist(String phone, final ApiCallBack apiCallBack) {
	HttpUtils http = new HttpUtils();
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	http.configDefaultHttpCacheExpiry(0); 
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("phone", phone);
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_CHECK_EXEIST, params,
		new RequestCallBack<String>() {
			@SuppressWarnings("rawtypes")
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if(code == Constants.SUCCESS) {
					Log.e(TAG, "checkUserExeist success");
					apiCallBack.onSuccess(code);
				} else {
					Log.e(TAG, "checkUserExeist fail, fail msg is " + map.get("msg"));
					apiCallBack.onFailure(String.valueOf(code));
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "checkUserExeist error", error);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					apiCallBack.onError(error, msg);
				}
			}
		});
}
 
Example #20
Source File: MeiTuServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void getMeiTu(final Handler handler, int newOrHotFlag, int offset,
		int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
	params.addQueryStringParameter("offset", String.valueOf(offset));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_LIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE);
					return;
				}
				PageResult page = FastjsonUtil.deserialize(
						map.get("data").toString(), PageResult.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("pageResult", page);
				message.what = Constants.SUCCESS;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example #21
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void setPortrait(final Handler handler, String userId, String portraitURL) {
	Log.e(TAG, "setPortrait");
	HttpUtils http = new HttpUtils();
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("userId", userId);
	params.addQueryStringParameter("portraitURL", portraitURL);
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_SET_PORTRAIT, params,
		new RequestCallBack<String>() {
			@SuppressWarnings("rawtypes")
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if(code == Constants.SUCCESS) {
					Log.e(TAG, "set portrait success");
					handler.sendEmptyMessage(Constants.SUCCESS_1);
				} else {
					Log.e(TAG, "set portrait fail, fail msg is " + map.get("msg"));
					handler.sendEmptyMessage(Constants.FAILURE_1);
					ToastUtils.showMessage(mContext,
							R.string.set_portrait_fail);
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "set portrait error", error);
				handler.sendEmptyMessage(Constants.FAILURE_1);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					ToastUtils.showMessage(mContext,
							R.string.set_portrait_fail);
				}
			}
		});
}
 
Example #22
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void feedback(final Handler handler, String content, String contact, String imgUrl) {
	HttpUtils http = new HttpUtils();
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	try {
		params.addQueryStringParameter("content", URLEncoder.encode(content, "UTF-8"));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	if(!Util.isNotEmpty(contact)) {
		params.addQueryStringParameter("contactWay", contact);
	}
	if(Util.isNotEmpty(imgUrl)) {
		params.addQueryStringParameter("imgUrl", imgUrl);
	}
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_FEEDBACK, params,
		new RequestCallBack<String>() {
			@SuppressWarnings("rawtypes")
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if(code == Constants.SUCCESS) {
					Log.e(TAG, "feedback success");
					ToastUtils.showMessage(mContext,
							R.string.feedback_success);
					handler.sendEmptyMessage(Constants.SUCCESS);
				} else {
					Log.e(TAG, "feedback fail, fail msg is " + map.get("msg"));
					handler.sendEmptyMessage(Constants.FAILURE);
					ToastUtils.showMessage(mContext,
							R.string.feedback_fail);
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "feedback error", error);
				handler.sendEmptyMessage(Constants.FAILURE);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					ToastUtils.showMessage(mContext,
							R.string.feedback_fail);
				}
			}
		});
}
 
Example #23
Source File: BillResultReceiver.java    From Hook with Apache License 2.0 4 votes vote down vote up
@Override
    public void onReceive(final Context context, Intent intent) {
//        Log.i("tag", "BillResultReceiver");
//        String money = intent.getStringExtra(Constans.BILL_MONEY);
//        String mark = intent.getStringExtra(Constans.BILL_MARK);
//        String type = intent.getStringExtra(Constans.BILL_TYPE);
//        String billNo = intent.getStringExtra(Constans.BILL_NO);
//        PushParam pushParam = new PushParam();
//        pushParam.setMark(mark);
//        pushParam.setMoney(money);
//        pushParam.setBillNo(billNo);
//        pushParam.setType(type);
//        Log.i("tag", "BillResultReceiver: mark:"+mark+"money:"+money+"billno:"+no+"type:"+type);

        final String tradeno = intent.getStringExtra("tradeno");
        String cookie = intent.getStringExtra("cookie");
        String url = "https://tradeeportlet.alipay.com/wireless/tradeDetail.htm?tradeNo=" + tradeno + "&source=channel&_from_url=https%3A%2F%2Frender.alipay.com%2Fp%2Fz%2Fmerchant-mgnt%2Fsimple-order._h_t_m_l_%3Fsource%3Dmdb_card";
        HttpUtils localHttpUtils = new HttpUtils(15000);
        localHttpUtils.configResponseTextCharset("GBK");
        RequestParams localRequestParams = new RequestParams();
        localRequestParams.addHeader("Cookie", cookie);
        localHttpUtils.send(HttpRequest.HttpMethod.GET, url, localRequestParams, new RequestCallBack() {
            @Override
            public void onSuccess(ResponseInfo responseInfo) {
                Log.i("tag", "onMessageEvent:" + responseInfo.result);
                Object localObject = Jsoup.parse((String) responseInfo.result).getElementsByClass("trade-info-value");
                if (((Elements) localObject).size() >= 5) {
                    String paramAnonymousResponseInfo = ((Elements) localObject).get(0).ownText();
                    String xx = ((Elements) localObject).get(1).ownText();
                    String xxx = ((Elements) localObject).get(2).ownText();
                    localObject = ((Elements) localObject).get(3).ownText();
                    PayHelperUtils.sendmsg(context,"付款成功alipay:订单号:"+ tradeno + "金额:" + paramAnonymousResponseInfo + "备注:" + (String) localObject);
                    Log.i("tag", "收到支付宝订单,订单号:" + tradeno + "金额:" + paramAnonymousResponseInfo + "备注:" + (String) localObject+"xx:"+xx+"xxx:"+xxx);
                    PushParam pushParam = new PushParam();
                    pushParam.setMark((String) localObject);
                    pushParam.setMoney(paramAnonymousResponseInfo);
                    pushParam.setBillNo(tradeno);
                    pushParam.setType("alipay");
                    pushParam.setState(1);
                    DBManager dbManager=new DBManager(context);
                    dbManager.updatePay(pushParam);
//                    Api.PUSH_ORDER_RESULT(context, pushParam, String.class, 1);
                }

            }

            @Override
            public void onFailure(HttpException error, String msg) {
                Log.i("tag", "服务器异常1");
            }
        });


    }
 
Example #24
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void addTencentUser(final Handler handler, String openId, String portraitUrl, String nickName,
		int sex) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("openId", openId);
	params.addQueryStringParameter("portraitUrl", portraitUrl);
	try {
		params.addQueryStringParameter("nickName", URLEncoder.encode(nickName, "UTF-8"));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	params.addQueryStringParameter("sex", String.valueOf(sex));
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_ADD_TENCENT_USER, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE);
					Log.e(TAG, "save user failure");
					return;
				}
				Log.e(TAG, "save user success");
				User user = FastjsonUtil.deserialize(
						map.get("data").toString(), User.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("user", user);
				message.what = Constants.SUCCESS;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "save user failure", error);
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example #25
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void addSinaUser(final Handler handler, String uid, String portraitUrl,
		String nickName) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("uid", uid);
	params.addQueryStringParameter("portraitUrl", portraitUrl);
	try {
		params.addQueryStringParameter("nickName", URLEncoder.encode(nickName, "UTF-8"));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_ADD_SINA_USER, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					if(handler != null) {
						handler.sendEmptyMessage(Constants.FAILURE_2);
					}
					Log.e(TAG, "save user failure");
					return;
				}
				Log.e(TAG, "save user success");
				User user = FastjsonUtil.deserialize(
						map.get("data").toString(), User.class);
				if(handler != null) {
					Message message = new Message();
					Bundle bundle = new Bundle();
					bundle.putSerializable("user", user);
					message.what = Constants.SUCCESS_2;
					message.setData(bundle);
					handler.sendMessage(message);
				} else {
					App.currentUser = user;
					App.getInstance().getSpUtil().putObject("user", user);
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "save user failure", error);
				if(handler != null) {
					handler.sendEmptyMessage(Constants.FAILURE_2);
				}
			}
		});
}
 
Example #26
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void regist(final Handler handler, String email, String password) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("userName", email);
	params.addQueryStringParameter("password", password);
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_REGIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE_1);
					Log.e(TAG, "regist failure");
					if(code == 502) {  //用户名存在
						ToastUtils.showMessage(mContext, R.string.phone_exists);
					}
					if(code == 504) {  //注册失败
						ToastUtils.showMessage(mContext, R.string.regist_fail);
					}
					return;
				}
				Log.e(TAG, "regist success");
				User user = FastjsonUtil.deserialize(
						map.get("data").toString(), User.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("user", user);
				message.what = Constants.SUCCESS_1;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "regist failure", error);
				handler.sendEmptyMessage(Constants.FAILURE_1);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					ToastUtils.showMessage(mContext, R.string.regist_fail);
				}
			}
		});
}
 
Example #27
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void regist(final ApiCallBack apiCallBack, String email, String password) {
	HttpUtils http = new HttpUtils();
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("userName", email);
	params.addQueryStringParameter("password", password);
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_REGIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					apiCallBack.onFailure(String.valueOf(map.get("code")));
					Log.e(TAG, "regist failure");
					if(code == 502) {  //用户名存在
						ToastUtils.showMessage(mContext, R.string.phone_exists);
					}
					if(code == 504) {  //注册失败
						ToastUtils.showMessage(mContext, R.string.regist_fail);
					}
					return;
				}
				Log.e(TAG, "regist success");
				User user = FastjsonUtil.deserialize(
						map.get("data").toString(), User.class);
				apiCallBack.onSuccess(user);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "regist failure", error);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					apiCallBack.onError(error, msg);
				}
			}
		});
}
 
Example #28
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void login(final Handler handler, String email, String password) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("userName", email);
	params.addQueryStringParameter("password", password);
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_LOGIN, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE);
					Log.e(TAG, "login failure");
					if(code == 503) {  //用户名不存在
						ToastUtils.showMessage(mContext, R.string.no_account);
						return;
					}
					if(code == 504) {  //登录密码错误
						ToastUtils.showMessage(mContext, R.string.password_error);
						return;
					}
					ToastUtils.showMessage(mContext, R.string.login_fail);
				}
				Log.e(TAG, "login success");
				User user = FastjsonUtil.deserialize(
						map.get("data").toString(), User.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("user", user);
				message.what = Constants.SUCCESS;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "login failure", error);
				handler.sendEmptyMessage(Constants.FAILURE);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					ToastUtils.showMessage(mContext, R.string.login_fail);
				}
			}
		});
}
 
Example #29
Source File: NetUtil.java    From ALLGO with Apache License 2.0 4 votes vote down vote up
private void send(HttpRequest.HttpMethod arg0,RequestParams params){
	SharedPreferences sharedPref = context.getSharedPreferences("appdata",Context.MODE_PRIVATE);
	params.addHeader("Cookie","JSESSIONID="+sharedPref.getString("SessionId", ""));
	http = new HttpUtils();
	http.configCurrentHttpCacheExpiry(1000 * 1);
    http.send(arg0,
    		declare.getHost_url() + uri,
    		params,
            new RequestCallBack<String>() {

				@Override
                public void onStart() {
                	Log.i(TAG ,"onStart" ) ;
                }
				
                @Override
                public void onSuccess(ResponseInfo<String> responseInfo) {
                	Log.i(TAG, "Http==>"+responseInfo.result);
					try {
						jsonObject = new JSONObject(responseInfo.result);
						 if(jsonObject.getString("response").equals("error")){
							refresh.refresh(jsonObject.getJSONObject("error").getString("text"), -1);
						 }else if(jsonObject.getString("response").equals("notlogin")){
							 Toast.makeText(context, "登录过期,请重新登录", Toast.LENGTH_SHORT).show();
							 Intent intent = new Intent(context,LogOffACTIVITY.class);
							 intent.putExtra("action", 1);
							 context.startActivity(intent);
						 }else {
							 callback.getResult(jsonObject);
						 }
					} catch (JSONException e) {
						e.printStackTrace();
					}
                }
                @Override
                public void onFailure(HttpException error, String msg) {
                	Log.i(TAG ,"error==>" +  msg ) ;
                	refresh.refresh(msg, -1);
                }
            });
}
 
Example #30
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void setNickAndSex(final Handler handler, String userId, String nickName, String sex) {
	HttpUtils http = new HttpUtils();
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("userId", userId);
	if(nickName != null) {
		params.addQueryStringParameter("nickName", nickName);
	}
	if(sex != null) {
		params.addQueryStringParameter("sex", sex);
	}
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_SET_NICK_SEX, params,
		new RequestCallBack<String>() {
			@SuppressWarnings("rawtypes")
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if(code == Constants.SUCCESS) {
					Log.e(TAG, "set nickName sex success");
					handler.sendEmptyMessage(Constants.SUCCESS_2);
				} else {
					Log.e(TAG, "set nickName sex fail, fail msg is " + map.get("msg"));
					handler.sendEmptyMessage(Constants.FAILURE_2);
					ToastUtils.showMessage(mContext,
							R.string.set_nick_sex_fial);
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "set nickName sex error", error);
				handler.sendEmptyMessage(Constants.FAILURE_2);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					ToastUtils.showMessage(mContext,
							R.string.set_nick_sex_fial);
				}
			}
		});
}