/** 获取服务器保存的好友(蜂友) */ public void getFriend() { HttpUtils httpUtils = new HttpUtils(); MyRequestParams params = new MyRequestParams(); params.addQueryStringParameter("userid", GlobalParams.loginUserId); String url = params.myRequestParams(params); httpUtils.send( HttpRequest.HttpMethod.POST, UrlPools.MY_FRIEND + "?" + url, new RequestCallBack<String>() { @Override public void onSuccess(ResponseInfo<String> responseInfo) { String result = responseInfo.result; // Log.e(TAG, result); if (paraseMyFriendDate(result).getStatus() == 1) { friendlist = paraseMyFriendDate(result).getData().getList(); // Log.e(TAG, friendlist.get(0).getTitle());//测试是否获得数据 // 存入内存 BeewayApplication.getInstance().setFriendList(friendlist); // 存入db FriendDao friendDao = new FriendDao(LoginActivity.this); friendDao.setFriendList(friendlist); } } @Override public void onFailure(HttpException error, String msg) { // 访问失败 LogUtils.i(msg); } }); }
private void registercode(String username) { HttpUtils httpUtils = new HttpUtils(); MyRequestParams params = new MyRequestParams(); params.addQueryStringParameter("mobile", username); params.addQueryStringParameter("mobile", username); params.addQueryStringParameter("exist", "1"); params.addQueryStringParameter("userid", "0"); String url = params.myRequestParams(params); httpUtils.send( HttpRequest.HttpMethod.POST, UrlPools.CODE + "?" + url, new RequestCallBack<String>() { @Override public void onSuccess(ResponseInfo<String> responseInfo) { String result = responseInfo.result; IssueCutomerBean issueCutomerBean = issueCutomerBean(result); if (issueCutomerBean.getStatus().equals("1")) { Toast.makeText(context, issueCutomerBean.getInfo(), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(context, issueCutomerBean.getInfo(), Toast.LENGTH_SHORT).show(); } } @Override public void onFailure(HttpException error, String msg) { // 访问失败 Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show(); } }); TimeCountUtil timeCountUtil = new TimeCountUtil(this, 60000, 1000, iv_code); timeCountUtil.start(); }
/** 验证码登录 */ public void codeLogin() { // new Thread() { // @Override // public void run() { // super.run(); // 这里调用了环信的注册的功能,如果在服务端调用,可以更改 下面的逻辑功能主要是与服务端接口的对接的功能 // 引入httputil 网络访问的帮助类 HttpUtils httpUtils = new HttpUtils(); MyRequestParams params = new MyRequestParams(); params.addQueryStringParameter("username", currentUsername); params.addQueryStringParameter("code", currentPassword); String url = params.myRequestParams(params); httpUtils.send( HttpRequest.HttpMethod.POST, UrlPools.LOGIN_CODE + "?" + url, new RequestCallBack<String>() { @Override public void onSuccess(ResponseInfo<String> responseInfo) { // 访问成功 // 得到用户的相关信息,并且将用户信息保存 SharedPreferencesUtil.saveData(LoginActivity.this, "userinfo", responseInfo.result); String result = responseInfo.result; System.out.println("lagin result " + result); LogUtils.i(responseInfo.result); UserInfo userInfo = paraseData(result); if (userInfo.getStatus() == 1) { // 判断状态码是否为登录成功,如果成功,既可以登录环信操作 // 在这里记录登录的用户UserId GlobalParams.loginUserId = userInfo.getData().getUserid(); GlobalParams.nickname = userInfo.getData().getNickname(); Log.e("userid", GlobalParams.loginUserId); Log.e("nickname", GlobalParams.nickname); Toast.makeText(LoginActivity.this, GlobalParams.nickname, Toast.LENGTH_SHORT).show(); // 获取用户的相关GEO数据 GlobalParams.geohash = userInfo.getData().getGeohash(); // 存储用户名、密码和自动登录标示 isauto = true; String userid = userInfo.getData().getUserid(); String mNickname = userInfo.getData().getNickname(); String sex = userInfo.getData().getSex(); String content = userInfo.getData().getContent(); String realname = userInfo.getData().getRealname(); String birthday = userInfo.getData().getBirthday(); String email = userInfo.getData().getEmail(); String wechat = userInfo.getData().getWechat(); String qq = userInfo.getData().getQq(); String weibo = userInfo.getData().getWeibo(); BeewayApplication.getInstance() .saveParam( LoginActivity.this, currentUsername, currentPassword, isauto, userid, mNickname, sex, content, realname, birthday, email, wechat, qq, weibo); /** 获取附近的好友 */ getNearFrenid(); /** 获取蜂友 */ getFriend(); // 如果服务端处理就不需要这段处理 loginHuanXin(); } else { Toast.makeText(LoginActivity.this, userInfo.getInfo(), Toast.LENGTH_SHORT).show(); removeDialog(); } } @Override public void onFailure(HttpException error, String msg) { // 访问失败 LogUtils.i(msg); } }); // } // }.start(); }