| | |
| | | import android.os.Bundle; |
| | | import android.os.PersistableBundle; |
| | | import android.text.InputType; |
| | | import android.text.TextUtils; |
| | | import android.util.Base64; |
| | | import android.util.Log; |
| | | import android.view.LayoutInflater; |
| | |
| | | import com.dayu.pipirrapp.databinding.ActivityLoginBinding; |
| | | import com.dayu.pipirrapp.net.ApiManager; |
| | | import com.dayu.pipirrapp.net.BaseResponse; |
| | | import com.dayu.pipirrapp.net.subscribers.CodeListener; |
| | | import com.dayu.pipirrapp.net.subscribers.SubscriberListener; |
| | | import com.dayu.pipirrapp.observer.LoginObserver; |
| | | import com.dayu.pipirrapp.utils.CommonData; |
| | |
| | | private void getCode() { |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("type", "math");//图片类型:char-文本,math-一位数算式,math2-两位数算式 |
| | | ApiManager.getInstance().getCode(data, new CodeListener() { |
| | | |
| | | |
| | | ApiManager.getInstance().requestGetHideLoading(LoginActivity.this, BASE_URL + ":8088/app/captcha/get", CodeResult.class, data, new SubscriberListener<BaseResponse<CodeResult>>() { |
| | | @Override |
| | | public void onNext(CodeResult body) { |
| | | public void onNext(BaseResponse<CodeResult> t) { |
| | | try { |
| | | if (body != null && !TextUtils.isEmpty(body.getBase64())) { |
| | | String encodedString = body.getBase64(); |
| | | codeToken = body.getToken(); |
| | | if (t.isSuccess()) { |
| | | String encodedString = t.getContent().getBase64(); |
| | | codeToken = t.getContent().getToken(); |
| | | // 移除Base64字符串的头部信息 |
| | | encodedString = encodedString.substring("data:image/png;base64,".length()); |
| | | // 对Base64字符串进行解码 |
| | |
| | | binding.codeError.setVisibility(View.VISIBLE); |
| | | ToastUtil.showToast(LoginActivity.this, "验证码获取失败"); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | CrashReport.postCatchedException(e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void error(Throwable throwable) { |
| | | |
| | | } |
| | | }); |
| | | |
| | | |
| | | // ApiManager.getInstance().getCode(data, new CodeListener() { |
| | | // @Override |
| | | // public void onNext(CodeResult body) { |
| | | // try { |
| | | // if (body != null && !TextUtils.isEmpty(body.getBase64())) { |
| | | // String encodedString = body.getBase64(); |
| | | // codeToken = body.getToken(); |
| | | // // 移除Base64字符串的头部信息 |
| | | // encodedString = encodedString.substring("data:image/png;base64,".length()); |
| | | // // 对Base64字符串进行解码 |
| | | // byte[] imageAsBytes = Base64.decode(encodedString, Base64.DEFAULT); |
| | | // // 使用BitmapFactory将字节数组解码成Bitmap对象 |
| | | // Bitmap image = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length); |
| | | // binding.codeImg.setImageBitmap(image); |
| | | // binding.codeImg.setVisibility(View.VISIBLE); |
| | | // binding.codeError.setVisibility(View.GONE); |
| | | // } else { |
| | | // binding.codeImg.setVisibility(View.INVISIBLE); |
| | | // binding.codeError.setVisibility(View.VISIBLE); |
| | | // ToastUtil.showToast(LoginActivity.this, "验证码获取失败"); |
| | | // } |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // CrashReport.postCatchedException(e); |
| | | // } |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void error(Throwable throwable) { |
| | | // |
| | | // } |
| | | // }); |
| | | } |
| | | |
| | | private void login(String phone, String pw, String token, String code) { |
| | |
| | | } |
| | | loginBean.setName(t.getContent().getName()); |
| | | loginBean.setPhone(t.getContent().getPhone()); |
| | | DaoSingleton.getInstance(LoginActivity.this).loginDao().update(loginBean); |
| | | DaoSingleton.getInstance(LoginActivity.this).loginDao().insert(loginBean); |
| | | SharedPreferencesHelper.getInstance(LoginActivity.this).put(CommonData.isShowCode, false); |
| | | Intent intent = new Intent(LoginActivity.this, MainActivity.class); |
| | | startActivity(intent); |
| | | LoginActivity.this.finish(); |
| | | startMainActivity(); |
| | | } else { |
| | | ToastUtil.showToast(LoginActivity.this, t.getMsg()); |
| | | loginError++; |
| | |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 启动MainActivity |
| | | */ |
| | | private void startMainActivity() { |
| | | Intent intent = new Intent(LoginActivity.this, MainActivity.class); |
| | | startActivity(intent); |
| | | LoginActivity.this.finish(); |
| | | } |
| | | |
| | | @Override |
| | | protected void onStart() { |
| | | super.onStart(); |