|
|
@ -1,38 +1,47 @@ |
|
|
|
package com.unionmed.unionmedtv.login.activity.fragment; |
|
|
|
package com.unionmed.unionmedtv.login.activity.fragment; |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Intent; |
|
|
|
import android.graphics.Bitmap; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.CountDownTimer; |
|
|
|
import android.os.CountDownTimer; |
|
|
|
import android.text.TextUtils; |
|
|
|
import android.text.TextUtils; |
|
|
|
|
|
|
|
import android.util.Log; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.widget.EditText; |
|
|
|
import android.widget.EditText; |
|
|
|
|
|
|
|
import android.widget.ImageView; |
|
|
|
|
|
|
|
import android.widget.LinearLayout; |
|
|
|
|
|
|
|
import android.widget.ProgressBar; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.fragment.app.Fragment; |
|
|
|
import androidx.fragment.app.Fragment; |
|
|
|
|
|
|
|
|
|
|
|
import com.blankj.utilcode.util.ToastUtils; |
|
|
|
import com.blankj.utilcode.util.ToastUtils; |
|
|
|
import com.example.yideng.loaddialoglibrary.LmiotDialog; |
|
|
|
import com.example.yideng.loaddialoglibrary.LmiotDialog; |
|
|
|
|
|
|
|
import com.google.gson.Gson; |
|
|
|
|
|
|
|
import com.google.gson.JsonObject; |
|
|
|
|
|
|
|
import com.hjq.http.EasyConfig; |
|
|
|
import com.hjq.http.EasyHttp; |
|
|
|
import com.hjq.http.EasyHttp; |
|
|
|
import com.hjq.http.listener.OnHttpListener; |
|
|
|
import com.hjq.http.listener.OnHttpListener; |
|
|
|
import com.lxj.xpopup.XPopup; |
|
|
|
import com.lxj.xpopup.XPopup; |
|
|
|
import com.unionmed.unionmedtv.R; |
|
|
|
import com.unionmed.unionmedtv.R; |
|
|
|
import com.unionmed.unionmedtv.activity.HomeActivity; |
|
|
|
import com.unionmed.unionmedtv.activity.HomeActivity; |
|
|
|
import com.unionmed.unionmedtv.activity.MainActivity; |
|
|
|
|
|
|
|
import com.unionmed.unionmedtv.api.AreaLoginApi; |
|
|
|
import com.unionmed.unionmedtv.api.AreaLoginApi; |
|
|
|
import com.unionmed.unionmedtv.api.GetCodeApi; |
|
|
|
import com.unionmed.unionmedtv.api.GetCodeApi; |
|
|
|
import com.unionmed.unionmedtv.api.GetNearDoctorApi; |
|
|
|
import com.unionmed.unionmedtv.api.GetCodeCallBackLsn; |
|
|
|
import com.unionmed.unionmedtv.api.MobileLoginApi; |
|
|
|
import com.unionmed.unionmedtv.api.MobileLoginApi; |
|
|
|
|
|
|
|
import com.unionmed.unionmedtv.api.QRCodeApi; |
|
|
|
|
|
|
|
import com.unionmed.unionmedtv.bean.QRCodeBean; |
|
|
|
|
|
|
|
import com.unionmed.unionmedtv.bean.ScanBean; |
|
|
|
import com.unionmed.unionmedtv.bean.TokenBean; |
|
|
|
import com.unionmed.unionmedtv.bean.TokenBean; |
|
|
|
import com.unionmed.unionmedtv.dialog.TipDialog; |
|
|
|
import com.unionmed.unionmedtv.dialog.TipDialog; |
|
|
|
import com.unionmed.unionmedtv.login.activity.LoginActivity; |
|
|
|
|
|
|
|
import com.unionmed.unionmedtv.network.ApiResponse; |
|
|
|
import com.unionmed.unionmedtv.network.ApiResponse; |
|
|
|
import com.unionmed.unionmedtv.network.HttpData; |
|
|
|
import com.unionmed.unionmedtv.network.HttpData; |
|
|
|
import com.unionmed.unionmedtv.utils.CacheUtil; |
|
|
|
import com.unionmed.unionmedtv.utils.CacheUtil; |
|
|
|
|
|
|
|
import com.uuzuche.lib_zxing.activity.CodeUtils; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.Timer; |
|
|
|
|
|
|
|
import java.util.TimerTask; |
|
|
|
|
|
|
|
|
|
|
|
import me.jessyan.autosize.utils.LogUtils; |
|
|
|
import me.jessyan.autosize.utils.LogUtils; |
|
|
|
|
|
|
|
|
|
|
@ -51,6 +60,10 @@ public class LoginPhoneFragment extends Fragment implements View.OnClickListener |
|
|
|
private EditText edit_code; |
|
|
|
private EditText edit_code; |
|
|
|
private TextView tv_getVerification; |
|
|
|
private TextView tv_getVerification; |
|
|
|
private TextView tv_login; |
|
|
|
private TextView tv_login; |
|
|
|
|
|
|
|
private ImageView iv_qrCode; |
|
|
|
|
|
|
|
private LinearLayout lin_code; |
|
|
|
|
|
|
|
private ProgressBar progress; |
|
|
|
|
|
|
|
private TextView tv_code_msg; |
|
|
|
|
|
|
|
|
|
|
|
public LoginPhoneFragment() { |
|
|
|
public LoginPhoneFragment() { |
|
|
|
// Required empty public constructor
|
|
|
|
// Required empty public constructor
|
|
|
@ -80,6 +93,7 @@ public class LoginPhoneFragment extends Fragment implements View.OnClickListener |
|
|
|
if (mRootView == null) { |
|
|
|
if (mRootView == null) { |
|
|
|
mRootView = inflater.inflate(R.layout.fragment_phone_login, container, false); |
|
|
|
mRootView = inflater.inflate(R.layout.fragment_phone_login, container, false); |
|
|
|
initView(mRootView); |
|
|
|
initView(mRootView); |
|
|
|
|
|
|
|
GenerateQRcode(); |
|
|
|
} |
|
|
|
} |
|
|
|
return mRootView; |
|
|
|
return mRootView; |
|
|
|
} |
|
|
|
} |
|
|
@ -94,6 +108,12 @@ public class LoginPhoneFragment extends Fragment implements View.OnClickListener |
|
|
|
tv_getVerification.setOnClickListener(this); |
|
|
|
tv_getVerification.setOnClickListener(this); |
|
|
|
tv_login = view.findViewById(R.id.tv_login); |
|
|
|
tv_login = view.findViewById(R.id.tv_login); |
|
|
|
tv_login.setOnClickListener(this); |
|
|
|
tv_login.setOnClickListener(this); |
|
|
|
|
|
|
|
iv_qrCode = view.findViewById(R.id.iv_qrCode); |
|
|
|
|
|
|
|
iv_qrCode.setOnClickListener(this); |
|
|
|
|
|
|
|
lin_code = view.findViewById(R.id.lin_code); |
|
|
|
|
|
|
|
lin_code.setOnClickListener(this); |
|
|
|
|
|
|
|
progress = view.findViewById(R.id.progress); |
|
|
|
|
|
|
|
tv_code_msg = view.findViewById(R.id.tv_code_msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -119,6 +139,145 @@ public class LoginPhoneFragment extends Fragment implements View.OnClickListener |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MobileLogin(edit_phone.getText().toString(), edit_code.getText().toString()); |
|
|
|
MobileLogin(edit_phone.getText().toString(), edit_code.getText().toString()); |
|
|
|
|
|
|
|
} else if (view.getId() == R.id.lin_code || view.getId() == R.id.iv_qrCode) { |
|
|
|
|
|
|
|
if(timer!=null){ |
|
|
|
|
|
|
|
timer.cancel(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
GenerateQRcode(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 生成二维码 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void GenerateQRcode() { |
|
|
|
|
|
|
|
lin_code.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
progress.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
tv_code_msg.setText("二维码生成中"); |
|
|
|
|
|
|
|
EasyHttp.post(getActivity()) |
|
|
|
|
|
|
|
.api(new QRCodeApi("Login", "")) |
|
|
|
|
|
|
|
.request(new OnHttpListener<HttpData<ApiResponse<QRCodeBean>>>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onSucceed(HttpData<ApiResponse<QRCodeBean>> apiResponseHttpData) { |
|
|
|
|
|
|
|
if (apiResponseHttpData.isRequestSucceed()) { |
|
|
|
|
|
|
|
if (apiResponseHttpData.getData().isInnerRequestSucceed()) { |
|
|
|
|
|
|
|
lin_code.setVisibility(View.GONE); |
|
|
|
|
|
|
|
iv_qrCode.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
Bitmap mBitmap = CodeUtils.createImage(apiResponseHttpData.getData().getData().getCode(), 400, 400, null); |
|
|
|
|
|
|
|
iv_qrCode.setImageBitmap(mBitmap); |
|
|
|
|
|
|
|
callbackLsn(apiResponseHttpData.getData().getData().getCode()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
lin_code.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
progress.setVisibility(View.GONE); |
|
|
|
|
|
|
|
tv_code_msg.setText("生成二维码失败,点击刷新"); |
|
|
|
|
|
|
|
iv_qrCode.setVisibility(View.INVISIBLE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
lin_code.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
progress.setVisibility(View.GONE); |
|
|
|
|
|
|
|
tv_code_msg.setText("生成二维码失败,点击刷新"); |
|
|
|
|
|
|
|
iv_qrCode.setVisibility(View.INVISIBLE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onFail(Exception e) { |
|
|
|
|
|
|
|
lin_code.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
progress.setVisibility(View.GONE); |
|
|
|
|
|
|
|
tv_code_msg.setText("生成二维码失败,点击刷新"); |
|
|
|
|
|
|
|
iv_qrCode.setVisibility(View.INVISIBLE); |
|
|
|
|
|
|
|
ToastUtils.showLong("获取二维码失败"); |
|
|
|
|
|
|
|
LogUtils.e("失败:" + e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Timer timer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//监听二维码 定时请求,监听二维码是否已回调(是否已绑定数据)
|
|
|
|
|
|
|
|
public void callbackLsn(String code) { |
|
|
|
|
|
|
|
timer = new Timer(); |
|
|
|
|
|
|
|
timer.schedule(new TimerTask() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
EasyHttp.post(getActivity()) |
|
|
|
|
|
|
|
.api(new GetCodeCallBackLsn(code)) |
|
|
|
|
|
|
|
.request(new OnHttpListener<HttpData<ApiResponse<ScanBean>>>() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onSucceed(HttpData<ApiResponse<ScanBean>> apiResponseHttpData) { |
|
|
|
|
|
|
|
if (apiResponseHttpData.isRequestSucceed()) { |
|
|
|
|
|
|
|
if (apiResponseHttpData.getData().isInnerRequestSucceed()) { |
|
|
|
|
|
|
|
TokenBean tokenBean = new Gson() |
|
|
|
|
|
|
|
.fromJson(apiResponseHttpData.getData().getData().getCallbackData().replace("\\", ""), TokenBean.class); |
|
|
|
|
|
|
|
CacheUtil.setToken(tokenBean); |
|
|
|
|
|
|
|
CacheUtil.setAccountNumber(tokenBean.getMobile()); |
|
|
|
|
|
|
|
CacheUtil.saveImUserAccount(tokenBean.getIm_useraccount()); |
|
|
|
|
|
|
|
CacheUtil.saveImUserPwd(tokenBean.getIm_password()); |
|
|
|
|
|
|
|
CacheUtil.saveImTokenRong(tokenBean.getIm_token()); |
|
|
|
|
|
|
|
CacheUtil.savePkey(tokenBean.getPreRegion().getPkey()); |
|
|
|
|
|
|
|
CacheUtil.saveipsvr(tokenBean.getPreRegion().getIpsvr()); |
|
|
|
|
|
|
|
CacheUtil.setIpAddress(tokenBean.getPreRegion()); |
|
|
|
|
|
|
|
if (tokenBean.getIsAtuh().equals("1") |
|
|
|
|
|
|
|
&& tokenBean.getFaceAuthFlag() == 1) { |
|
|
|
|
|
|
|
getAreaLogn(tokenBean.getIdentity_id(), |
|
|
|
|
|
|
|
tokenBean.getMobile(), |
|
|
|
|
|
|
|
tokenBean.getName(), |
|
|
|
|
|
|
|
tokenBean.getPreRegion().getPkey()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
LmiotDialog.hidden(); |
|
|
|
|
|
|
|
CacheUtil.setToken(null); |
|
|
|
|
|
|
|
new XPopup.Builder(getActivity()).isRequestFocus(true) |
|
|
|
|
|
|
|
.asCustom(new TipDialog(getActivity(), "请先前往手机app进行实名认证,认证成功后才可登录", new TipDialog.DialogClick() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void cancel() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void confirm() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
})).show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (timer != null) { |
|
|
|
|
|
|
|
timer.cancel(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (apiResponseHttpData.getData().getCode() == 500) { |
|
|
|
|
|
|
|
if (timer != null) { |
|
|
|
|
|
|
|
timer.cancel(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
lin_code.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
progress.setVisibility(View.GONE); |
|
|
|
|
|
|
|
iv_qrCode.setVisibility(View.INVISIBLE); |
|
|
|
|
|
|
|
tv_code_msg.setText("二维码失效,点击刷新"); |
|
|
|
|
|
|
|
ToastUtils.showLong("二维码失效"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (timer != null) { |
|
|
|
|
|
|
|
timer.cancel(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
lin_code.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
progress.setVisibility(View.INVISIBLE); |
|
|
|
|
|
|
|
tv_code_msg.setText("二维码失效,点击刷新"); |
|
|
|
|
|
|
|
ToastUtils.showLong("二维码失效"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onFail(Exception e) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, 0, 5000); // 设置定时任务的时间间隔为 5 秒
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onDestroy() { |
|
|
|
|
|
|
|
super.onDestroy(); |
|
|
|
|
|
|
|
if (timer != null) { |
|
|
|
|
|
|
|
timer.cancel(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -161,7 +320,7 @@ public class LoginPhoneFragment extends Fragment implements View.OnClickListener |
|
|
|
|
|
|
|
|
|
|
|
//手机号登录
|
|
|
|
//手机号登录
|
|
|
|
public void MobileLogin(String mobile, String code) { |
|
|
|
public void MobileLogin(String mobile, String code) { |
|
|
|
LmiotDialog.show(getActivity(),"登录中.."); |
|
|
|
LmiotDialog.show(getActivity(), "登录中.."); |
|
|
|
EasyHttp.post(getActivity()) |
|
|
|
EasyHttp.post(getActivity()) |
|
|
|
.api(new MobileLoginApi(mobile, code)) |
|
|
|
.api(new MobileLoginApi(mobile, code)) |
|
|
|
.request(new OnHttpListener<HttpData<ApiResponse<TokenBean>>>() { |
|
|
|
.request(new OnHttpListener<HttpData<ApiResponse<TokenBean>>>() { |
|
|
@ -202,7 +361,6 @@ public class LoginPhoneFragment extends Fragment implements View.OnClickListener |
|
|
|
} |
|
|
|
} |
|
|
|
})).show(); |
|
|
|
})).show(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LmiotDialog.hidden(); |
|
|
|
LmiotDialog.hidden(); |
|
|
|
ToastUtils.showLong(apiResponseHttpData.getData().getMessage()); |
|
|
|
ToastUtils.showLong(apiResponseHttpData.getData().getMessage()); |
|
|
@ -222,19 +380,26 @@ public class LoginPhoneFragment extends Fragment implements View.OnClickListener |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void getAreaLogn(String identity_id, String mobile, String name, String pkey) { |
|
|
|
public void getAreaLogn(String identity_id, String mobile, String name, String pkey) { |
|
|
|
|
|
|
|
EasyConfig.getInstance().addHeader("token", CacheUtil.getToken().getToken()); |
|
|
|
EasyHttp.post(this) |
|
|
|
EasyHttp.post(this) |
|
|
|
.api(new AreaLoginApi(identity_id, mobile, name, pkey)) |
|
|
|
.api(new AreaLoginApi(identity_id, mobile, name, pkey)) |
|
|
|
.request(new OnHttpListener<HttpData<AreaLoginApi>>() { |
|
|
|
.request(new OnHttpListener<HttpData<ApiResponse<AreaLoginApi>>>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onSucceed(HttpData<AreaLoginApi> personInfoBeanHttpData) { |
|
|
|
public void onSucceed(HttpData<ApiResponse<AreaLoginApi>> personInfoBeanHttpData) { |
|
|
|
LmiotDialog.hidden(); |
|
|
|
LmiotDialog.hidden(); |
|
|
|
if (personInfoBeanHttpData.isRequestSucceed()) { |
|
|
|
if (personInfoBeanHttpData.isRequestSucceed()) { |
|
|
|
CacheUtil.saveUserToken(personInfoBeanHttpData.getData().getUserToken()); |
|
|
|
if (personInfoBeanHttpData.getData().isInnerRequestSucceed()) { |
|
|
|
|
|
|
|
CacheUtil.saveUserToken(personInfoBeanHttpData.getData().getData().getUserToken()); |
|
|
|
HomeActivity.StartActivity(getActivity()); |
|
|
|
HomeActivity.StartActivity(getActivity()); |
|
|
|
getActivity().finish(); |
|
|
|
getActivity().finish(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
CacheUtil.setToken(null); |
|
|
|
CacheUtil.setToken(null); |
|
|
|
|
|
|
|
ToastUtils.showLong(personInfoBeanHttpData.getData().getMessage()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
CacheUtil.setToken(null); |
|
|
|
ToastUtils.showLong(personInfoBeanHttpData.getMessage()); |
|
|
|
ToastUtils.showLong(personInfoBeanHttpData.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|