| | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.tejia.lijin.app.util.ui.dialog.DialogUtil; |
| | | import com.tejia.lijin.app.util.user.AccountBindManager; |
| | | import com.tejia.lijin.app.util.user.LoginManager; |
| | | import com.xiaomi.mipush.sdk.MiPushClient; |
| | | import com.tejia.lijin.app.BasicTextHttpResponseHandler; |
| | | import com.tejia.lijin.app.R; |
| | |
| | | * 请求服务器匹配验证码后登录 |
| | | */ |
| | | private void loginNew(String code) { |
| | | ShoppingApi.loginNew(LoginVerifyCodeActivity.this, code, mobileNum, "", "1", new BasicTextHttpResponseHandler() { |
| | | |
| | | LoginManager.loginByPhone(mobileNum, code, null, new LoginManager.LoginAndBindListener() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | if (jsonObject.optString("code").equalsIgnoreCase("0")) { |
| | | Gson gson = new GsonBuilder().serializeNulls().create(); |
| | | JSONObject data = jsonObject.optJSONObject("data"); |
| | | final UserInfo info = gson.fromJson(data.optJSONObject("userInfo").toString(), new TypeToken<UserInfo>() { |
| | | }.getType()); |
| | | tv_input_error.setVisibility(View.INVISIBLE); |
| | | SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = sp.edit(); |
| | | editor.putBoolean("isLogin", true); |
| | | editor.putBoolean("isFirstInput", false); |
| | | editor.putString("uid", info.getId()); |
| | | editor.putString("openid", info.getOpenid()); |
| | | editor.putString("portrait", info.getPortrait()); |
| | | editor.commit(); |
| | | |
| | | MiPushClient.setAlias(LoginVerifyCodeActivity.this, info.getId(), null); |
| | | |
| | | //保存邀请码 |
| | | String inviteCode = data.optString("inviteCode"); |
| | | UserUtil.setInviteCode(getApplicationContext(), inviteCode); |
| | | if (StringUtils.isNullOrEmpty(inviteCode)) { |
| | | startActivity(new Intent(LoginVerifyCodeActivity.this, ActivationInviteCodeAcitvity.class)); |
| | | } else { |
| | | Toast.makeText(LoginVerifyCodeActivity.this, "恭喜你,登录成功", Toast.LENGTH_SHORT).show(); |
| | | } |
| | | setResult(100); |
| | | finish(); |
| | | } else { |
| | | tv_input_error.setVisibility(View.VISIBLE); |
| | | tv_input_error.setText(jsonObject.optString("msg")); |
| | | Toast.makeText(LoginVerifyCodeActivity.this, jsonObject.optString("msg"), Toast.LENGTH_SHORT).show(); |
| | | } |
| | | public void onLoginStart() { |
| | | super.onLoginStart(); |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | super.onFinish(); |
| | | public void onLoginFinish() { |
| | | super.onLoginFinish(); |
| | | } |
| | | |
| | | @Override |
| | | public void onLoginSuccess(UserInfo user) { |
| | | super.onLoginSuccess(user); |
| | | tv_input_error.setVisibility(View.INVISIBLE); |
| | | UserUtil.loginSuccess(getApplicationContext(), user); |
| | | Toast.makeText(LoginVerifyCodeActivity.this, "恭喜你,登录成功", Toast.LENGTH_SHORT).show(); |
| | | setResult(100); |
| | | finish(); |
| | | } |
| | | |
| | | @Override |
| | | public void onLoginFail(int code, String msg) { |
| | | super.onLoginFail(code, msg); |
| | | tv_input_error.setVisibility(View.VISIBLE); |
| | | tv_input_error.setText(msg); |
| | | Toast.makeText(LoginVerifyCodeActivity.this, msg, Toast.LENGTH_SHORT).show(); |
| | | } |
| | | }); |
| | | } |
| | |
| | | * 请求服务器匹配验证码后修改手机号 |
| | | */ |
| | | private void bindPhoneNew(String code) { |
| | | ShoppingApi.bindPhoneNew(LoginVerifyCodeActivity.this, code, mobileNum, uid, new BasicTextHttpResponseHandler() { |
| | | AccountBindManager.bindPhone(LoginVerifyCodeActivity.this, code, mobileNum, null, new LoginManager.LoginAndBindListener() { |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | if (jsonObject.optString("code").equalsIgnoreCase("0")) { |
| | | Gson gson = new GsonBuilder().serializeNulls().create(); |
| | | final UserInfo info = gson.fromJson(jsonObject.optJSONObject("data").optJSONObject("userInfo").toString(), new TypeToken<UserInfo>() { |
| | | }.getType()); |
| | | tv_input_error.setVisibility(View.INVISIBLE); |
| | | SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = sp.edit(); |
| | | editor.putBoolean("isLogin", true); |
| | | editor.putBoolean("isFirstInput", false); |
| | | editor.putString("uid", info.getId()); |
| | | editor.putString("openid", info.getOpenid()); |
| | | editor.putString("portrait", info.getPortrait()); |
| | | editor.commit(); |
| | | Toast.makeText(LoginVerifyCodeActivity.this, "绑定成功", Toast.LENGTH_SHORT).show(); |
| | | setResult(100); |
| | | finish(); |
| | | } else if (jsonObject.optString("code").equalsIgnoreCase("2")) { |
| | | public void onBindFail(int code, String msg) { |
| | | super.onBindFail(code, msg); |
| | | if (code == 2) { |
| | | AddZFBInfoDialog.Builder builder = new AddZFBInfoDialog.Builder(LoginVerifyCodeActivity.this); |
| | | builder.setTitle("号码已占用提示").setMessage("很抱歉,该手机号已被其他帐号占用," + |
| | | "若要继续完成本帐号手机号更换,请去取消占用或更换其他手机号,谢谢。\n") |
| | |
| | | setResult(100); |
| | | } else { |
| | | tv_input_error.setVisibility(View.VISIBLE); |
| | | tv_input_error.setText(jsonObject.optString("msg")); |
| | | Toast.makeText(LoginVerifyCodeActivity.this, jsonObject.optString("msg"), Toast.LENGTH_SHORT).show(); |
| | | tv_input_error.setText(msg); |
| | | Toast.makeText(LoginVerifyCodeActivity.this, msg, Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | super.onFinish(); |
| | | public void onBindFinish() { |
| | | super.onBindFinish(); |
| | | } |
| | | |
| | | @Override |
| | | public void onBindStart() { |
| | | super.onBindStart(); |
| | | } |
| | | |
| | | @Override |
| | | public void onBindSuccess(UserInfo user) { |
| | | super.onBindSuccess(user); |
| | | tv_input_error.setVisibility(View.INVISIBLE); |
| | | UserUtil.loginSuccess(getApplicationContext(), user); |
| | | Toast.makeText(LoginVerifyCodeActivity.this, "绑定成功", Toast.LENGTH_SHORT).show(); |
| | | setResult(100); |
| | | finish(); |
| | | } |
| | | }); |
| | | } |
| | |
| | | * @param code |
| | | */ |
| | | private void bindPhoneWithOutLogin(String code, String mobile, String key) { |
| | | ShoppingApi.bindPhoneWithOutLogin(LoginVerifyCodeActivity.this, code, mobile, key, new BasicTextHttpResponseHandler() { |
| | | LoginManager.loginWithPhone(mobile, code, null, key, new LoginManager.LoginAndBindListener() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | if (jsonObject.optString("code").equalsIgnoreCase("0")) { |
| | | Gson gson = new GsonBuilder().serializeNulls().create(); |
| | | final UserInfo info = gson.fromJson(jsonObject.optJSONObject("data").optJSONObject("userInfo").toString(), new TypeToken<UserInfo>() { |
| | | }.getType()); |
| | | tv_input_error.setVisibility(View.INVISIBLE); |
| | | SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = sp.edit(); |
| | | editor.putBoolean("isLogin", true); |
| | | editor.putBoolean("isFirstInput", false); |
| | | editor.putString("uid", info.getId()); |
| | | editor.putString("openid", info.getOpenid()); |
| | | editor.putString("portrait", info.getPortrait()); |
| | | editor.commit(); |
| | | Toast.makeText(LoginVerifyCodeActivity.this, "绑定成功", Toast.LENGTH_SHORT).show(); |
| | | setResult(100); |
| | | finish(); |
| | | } else if (jsonObject.optString("code").equalsIgnoreCase("2")) { |
| | | public void onBindStart() { |
| | | super.onLoginStart(); |
| | | } |
| | | |
| | | @Override |
| | | public void onBindFinish() { |
| | | super.onLoginFinish(); |
| | | } |
| | | |
| | | @Override |
| | | public void onBindSuccess(UserInfo user) { |
| | | super.onLoginSuccess(user); |
| | | tv_input_error.setVisibility(View.INVISIBLE); |
| | | UserUtil.loginSuccess(getApplicationContext(), user); |
| | | Toast.makeText(LoginVerifyCodeActivity.this, "绑定成功", Toast.LENGTH_SHORT).show(); |
| | | setResult(100); |
| | | finish(); |
| | | } |
| | | |
| | | @Override |
| | | public void onBindFail(int code, String msg) { |
| | | super.onLoginFail(code, msg); |
| | | if (code == 2) { |
| | | AddZFBInfoDialog.Builder builder = new AddZFBInfoDialog.Builder(LoginVerifyCodeActivity.this); |
| | | builder.setTitle("号码已占用提示").setMessage("很抱歉,该手机号已被其他帐号占用," + |
| | | "若要继续完成本帐号手机号更换,请去取消占用或更换其他手机号,谢谢。\n") |
| | |
| | | setResult(100); |
| | | } else { |
| | | tv_input_error.setVisibility(View.VISIBLE); |
| | | tv_input_error.setText(jsonObject.optString("msg")); |
| | | Toast.makeText(LoginVerifyCodeActivity.this, jsonObject.optString("msg"), Toast.LENGTH_SHORT).show(); |
| | | tv_input_error.setText(msg); |
| | | Toast.makeText(LoginVerifyCodeActivity.this, msg, Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | super.onFinish(); |
| | | } |
| | | }); |
| | | } |