diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 19e9151..f06c1e2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -51,6 +51,9 @@ + { - /** - * pkey : 15 - * ip : 47.118.51.167 - * port : 8065 - * fmsvr : rtmp://10.120.224.5/livepkgr/ - * msgsvr : http://120.195.56.245:3190/msg_server - * ipsvr : https://mobile.union-med.net/app/appintegrate/v1.8 - * msgip : 120.195.56.245 - * oder_num : 4 - * memo : 福州 - * svalue : rtmp://10.120.224.5/livepkgr/ - * filesvr : http://47.118.51.167:8999/eleand/ - */ - - private String pkey; - private String ip; - private String port; - private String fmsvr; - private String msgsvr; - private String ipsvr; - private String msgip; - private int oder_num; - private String memo; - private String svalue; - private String filesvr; - - public String getPkey() { - return pkey; - } - - public void setPkey(String pkey) { - this.pkey = pkey; - } - - public String getIp() { - return ip; - } - - public void setIp(String ip) { - this.ip = ip; - } - - public String getPort() { - return port; - } - - public void setPort(String port) { - this.port = port; - } - - public String getFmsvr() { - return fmsvr; - } - - public void setFmsvr(String fmsvr) { - this.fmsvr = fmsvr; - } - - public String getMsgsvr() { - return msgsvr; - } - - public void setMsgsvr(String msgsvr) { - this.msgsvr = msgsvr; - } - - public String getIpsvr() { - return ipsvr; - } - - public void setIpsvr(String ipsvr) { - this.ipsvr = ipsvr; - } - - public String getMsgip() { - return msgip; - } - - public void setMsgip(String msgip) { - this.msgip = msgip; - } - - public int getOder_num() { - return oder_num; - } - - public void setOder_num(int oder_num) { - this.oder_num = oder_num; - } - - public String getMemo() { - return memo; - } - - public void setMemo(String memo) { - this.memo = memo; - } - - public String getSvalue() { - return svalue; - } - - public void setSvalue(String svalue) { - this.svalue = svalue; - } - - public String getFilesvr() { - return filesvr; - } - - public void setFilesvr(String filesvr) { - this.filesvr = filesvr; - } - - @Override - public int compareTo(City city) { - try { - return PinyinHelper.getShortPinyin(this.memo) - .compareTo(PinyinHelper.getShortPinyin(city.memo)); - } catch (PinyinException e) { - e.printStackTrace(); - } - return 0; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - City city = (City) o; - return memo.equals(city.memo); - } - - @Override - public int hashCode() { - return Objects.hash(memo); - } - } - - public static class CurrentAddressBean { - /** - * addressKey : 435 - * pkey : 4262 - * name : 拒绝 - * sex : null - * mobile : 15905997060 - * address : 福建省福州市鼓楼区白马北路201-207号一号3号楼 - * detailAddress : 12 - * isCurrent : 1 - * isDefault : 1 - * xzqh : 3501 - * createTime : 1682577679 - * isDelete : 0 - */ - - private String addressKey; - private String pkey; - private String name; - private Object sex; - private String mobile; - private String address; - private String detailAddress; - private String isCurrent; - private String isDefault; - private String xzqh; - private String createTime; - private String isDelete; - - public String getAddressKey() { - return addressKey; - } - - public void setAddressKey(String addressKey) { - this.addressKey = addressKey; - } - - public String getPkey() { - return pkey; - } - - public void setPkey(String pkey) { - this.pkey = pkey; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Object getSex() { - return sex; - } - - public void setSex(Object sex) { - this.sex = sex; - } - - public String getMobile() { - return mobile; - } - - public void setMobile(String mobile) { - this.mobile = mobile; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getDetailAddress() { - return detailAddress; - } - - public void setDetailAddress(String detailAddress) { - this.detailAddress = detailAddress; - } - - public String getIsCurrent() { - return isCurrent; - } - - public void setIsCurrent(String isCurrent) { - this.isCurrent = isCurrent; - } - - public String getIsDefault() { - return isDefault; - } - - public void setIsDefault(String isDefault) { - this.isDefault = isDefault; - } - - public String getXzqh() { - return xzqh; - } - - public void setXzqh(String xzqh) { - this.xzqh = xzqh; - } - - public String getCreateTime() { - return createTime; - } - - public void setCreateTime(String createTime) { - this.createTime = createTime; - } - - public String getIsDelete() { - return isDelete; - } - - public void setIsDelete(String isDelete) { - this.isDelete = isDelete; - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/unionmed/unionmedtv/application/MyApplication.java b/app/src/main/java/com/unionmed/unionmedtv/application/MyApplication.java index 5a01d03..a25de43 100644 --- a/app/src/main/java/com/unionmed/unionmedtv/application/MyApplication.java +++ b/app/src/main/java/com/unionmed/unionmedtv/application/MyApplication.java @@ -2,6 +2,7 @@ package com.unionmed.unionmedtv.application; import android.app.Application; +import com.tencent.mmkv.MMKV; import com.unionmed.unionmedtv.network.RequestHandler; import com.unionmed.unionmedtv.network.RequestServer; import com.hjq.http.EasyConfig; @@ -22,10 +23,13 @@ public class MyApplication extends Application { .setServer(new RequestServer()) // 设置请求处理策略 .setHandler(new RequestHandler(this)) + .addHeader("client","IPTV") // 添加全局请求参数 //.addParam("token", "6666666") // 添加全局请求头 .addHeader("Content-Type", "application/json;charset=UTF-8") .into(); + + MMKV.initialize(this.getFilesDir().getAbsolutePath() + "/mmkv"); } } diff --git a/app/src/main/java/com/unionmed/unionmedtv/bean/TokenBean.java b/app/src/main/java/com/unionmed/unionmedtv/bean/TokenBean.java new file mode 100644 index 0000000..0d65cc2 --- /dev/null +++ b/app/src/main/java/com/unionmed/unionmedtv/bean/TokenBean.java @@ -0,0 +1,458 @@ +package com.unionmed.unionmedtv.bean; + +import com.github.stuxuhai.jpinyin.PinyinException; +import com.github.stuxuhai.jpinyin.PinyinHelper; + +import java.util.Objects; + +public class TokenBean { + /** + * name : 林瑞金 + * headImg : null + * mobile : 15905997060 + * preRegion : {"pkey":"15","ip":"47.118.51.167","port":"8065","fmsvr":"rtmp://10.120.224.5/livepkgr/","msgsvr":"http://120.195.56.245:3190/msg_server","ipsvr":"https://mobile.union-med.net/app/appintegrate/v1.8","msgip":"120.195.56.245","oder_num":4,"memo":"福州","svalue":"rtmp://10.120.224.5/livepkgr/","filesvr":"http://47.118.51.167:8999/eleand/"} + * isAtuh : 1 + * isuse : null + * online : null + * faceAuthFlag : 1 + * upkey : 4262 + * pkey : null + * identity_id : 350500199107135035 + * isSetPsw : 0 + * im_useraccount : 4262 + * im_password : null + * im_token : aMoc5MIihofCrtEW13iC7YL9uCPhRbbiDN4O4yV6HZC1i+9NneL2fU4Qn0g= + * currentAddress : {"addressKey":"435","pkey":"4262","name":"拒绝","sex":null,"mobile":"15905997060","address":"福建省福州市鼓楼区白马北路201-207号一号3号楼","detailAddress":"12","isCurrent":"1","isDefault":"1","xzqh":"3501","createTime":"1682577679","isDelete":"0"} + * userType : null + * token : c6011b69-cb6d-410f-a24f-75806cebcca0 + */ + + private String name; + private Object headImg; + private String mobile; + private City preRegion; + private String isAtuh; + private Object isuse; + private Object online; + private int faceAuthFlag; + private String upkey; + private Object pkey; + private String identity_id; + private String isSetPsw; + private String im_useraccount; + private String im_password; + private String im_token; + private CurrentAddressBean currentAddress; + private Object userType; + private String token; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Object getHeadImg() { + return headImg; + } + + public void setHeadImg(Object headImg) { + this.headImg = headImg; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public City getPreRegion() { + return preRegion; + } + + public void setPreRegion(City preRegion) { + this.preRegion = preRegion; + } + + public String getIsAtuh() { + return isAtuh; + } + + public void setIsAtuh(String isAtuh) { + this.isAtuh = isAtuh; + } + + public Object getIsuse() { + return isuse; + } + + public void setIsuse(Object isuse) { + this.isuse = isuse; + } + + public Object getOnline() { + return online; + } + + public void setOnline(Object online) { + this.online = online; + } + + public int getFaceAuthFlag() { + return faceAuthFlag; + } + + public void setFaceAuthFlag(int faceAuthFlag) { + this.faceAuthFlag = faceAuthFlag; + } + + public String getUpkey() { + return upkey; + } + + public void setUpkey(String upkey) { + this.upkey = upkey; + } + + public Object getPkey() { + return pkey; + } + + public void setPkey(Object pkey) { + this.pkey = pkey; + } + + public String getIdentity_id() { + return identity_id; + } + + public void setIdentity_id(String identity_id) { + this.identity_id = identity_id; + } + + public String getIsSetPsw() { + return isSetPsw; + } + + public void setIsSetPsw(String isSetPsw) { + this.isSetPsw = isSetPsw; + } + + public String getIm_useraccount() { + return im_useraccount; + } + + public void setIm_useraccount(String im_useraccount) { + this.im_useraccount = im_useraccount; + } + + public String getIm_password() { + return im_password; + } + + public void setIm_password(String im_password) { + this.im_password = im_password; + } + + public String getIm_token() { + return im_token; + } + + public void setIm_token(String im_token) { + this.im_token = im_token; + } + + public CurrentAddressBean getCurrentAddress() { + return currentAddress; + } + + public void setCurrentAddress(CurrentAddressBean currentAddress) { + this.currentAddress = currentAddress; + } + + public Object getUserType() { + return userType; + } + + public void setUserType(Object userType) { + this.userType = userType; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public static class City implements Comparable { + /** + * pkey : 15 + * ip : 47.118.51.167 + * port : 8065 + * fmsvr : rtmp://10.120.224.5/livepkgr/ + * msgsvr : http://120.195.56.245:3190/msg_server + * ipsvr : https://mobile.union-med.net/app/appintegrate/v1.8 + * msgip : 120.195.56.245 + * oder_num : 4 + * memo : 福州 + * svalue : rtmp://10.120.224.5/livepkgr/ + * filesvr : http://47.118.51.167:8999/eleand/ + */ + + private String pkey; + private String ip; + private String port; + private String fmsvr; + private String msgsvr; + private String ipsvr; + private String msgip; + private int oder_num; + private String memo; + private String svalue; + private String filesvr; + + public String getPkey() { + return pkey; + } + + public void setPkey(String pkey) { + this.pkey = pkey; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getPort() { + return port; + } + + public void setPort(String port) { + this.port = port; + } + + public String getFmsvr() { + return fmsvr; + } + + public void setFmsvr(String fmsvr) { + this.fmsvr = fmsvr; + } + + public String getMsgsvr() { + return msgsvr; + } + + public void setMsgsvr(String msgsvr) { + this.msgsvr = msgsvr; + } + + public String getIpsvr() { + return ipsvr; + } + + public void setIpsvr(String ipsvr) { + this.ipsvr = ipsvr; + } + + public String getMsgip() { + return msgip; + } + + public void setMsgip(String msgip) { + this.msgip = msgip; + } + + public int getOder_num() { + return oder_num; + } + + public void setOder_num(int oder_num) { + this.oder_num = oder_num; + } + + public String getMemo() { + return memo; + } + + public void setMemo(String memo) { + this.memo = memo; + } + + public String getSvalue() { + return svalue; + } + + public void setSvalue(String svalue) { + this.svalue = svalue; + } + + public String getFilesvr() { + return filesvr; + } + + public void setFilesvr(String filesvr) { + this.filesvr = filesvr; + } + + @Override + public int compareTo(City city) { + try { + return PinyinHelper.getShortPinyin(this.memo) + .compareTo(PinyinHelper.getShortPinyin(city.memo)); + } catch (PinyinException e) { + e.printStackTrace(); + } + return 0; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + City city = (City) o; + return memo.equals(city.memo); + } + + @Override + public int hashCode() { + return Objects.hash(memo); + } + } + + public static class CurrentAddressBean { + /** + * addressKey : 435 + * pkey : 4262 + * name : 拒绝 + * sex : null + * mobile : 15905997060 + * address : 福建省福州市鼓楼区白马北路201-207号一号3号楼 + * detailAddress : 12 + * isCurrent : 1 + * isDefault : 1 + * xzqh : 3501 + * createTime : 1682577679 + * isDelete : 0 + */ + + private String addressKey; + private String pkey; + private String name; + private Object sex; + private String mobile; + private String address; + private String detailAddress; + private String isCurrent; + private String isDefault; + private String xzqh; + private String createTime; + private String isDelete; + + public String getAddressKey() { + return addressKey; + } + + public void setAddressKey(String addressKey) { + this.addressKey = addressKey; + } + + public String getPkey() { + return pkey; + } + + public void setPkey(String pkey) { + this.pkey = pkey; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Object getSex() { + return sex; + } + + public void setSex(Object sex) { + this.sex = sex; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getDetailAddress() { + return detailAddress; + } + + public void setDetailAddress(String detailAddress) { + this.detailAddress = detailAddress; + } + + public String getIsCurrent() { + return isCurrent; + } + + public void setIsCurrent(String isCurrent) { + this.isCurrent = isCurrent; + } + + public String getIsDefault() { + return isDefault; + } + + public void setIsDefault(String isDefault) { + this.isDefault = isDefault; + } + + public String getXzqh() { + return xzqh; + } + + public void setXzqh(String xzqh) { + this.xzqh = xzqh; + } + + public String getCreateTime() { + return createTime; + } + + public void setCreateTime(String createTime) { + this.createTime = createTime; + } + + public String getIsDelete() { + return isDelete; + } + + public void setIsDelete(String isDelete) { + this.isDelete = isDelete; + } + } +} diff --git a/app/src/main/java/com/unionmed/unionmedtv/login/activity/LoginActivity.java b/app/src/main/java/com/unionmed/unionmedtv/login/activity/LoginActivity.java index 5d52f52..2d5fdfc 100644 --- a/app/src/main/java/com/unionmed/unionmedtv/login/activity/LoginActivity.java +++ b/app/src/main/java/com/unionmed/unionmedtv/login/activity/LoginActivity.java @@ -1,11 +1,15 @@ package com.unionmed.unionmedtv.login.activity; +import android.content.Intent; import android.os.Bundle; + import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; import com.unionmed.unionmedtv.R; +import com.unionmed.unionmedtv.activity.MainActivity; import com.unionmed.unionmedtv.login.activity.fragment.LoginPhoneFragment; +import com.unionmed.unionmedtv.utils.CacheUtil; public class LoginActivity extends FragmentActivity { @Override @@ -13,9 +17,14 @@ public class LoginActivity extends FragmentActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); if (savedInstanceState == null) { - getSupportFragmentManager().beginTransaction() - .replace(R.id.main_browse_fragment, new LoginPhoneFragment()) - .commitNow(); + if (CacheUtil.isLogin()) { + Intent intent = new Intent(LoginActivity.this, MainActivity.class); + startActivity(intent); + } else { + getSupportFragmentManager().beginTransaction() + .replace(R.id.main_browse_fragment, new LoginPhoneFragment()) + .commitNow(); + } } } } diff --git a/app/src/main/java/com/unionmed/unionmedtv/login/activity/fragment/LoginAccountFragment.java b/app/src/main/java/com/unionmed/unionmedtv/login/activity/fragment/LoginAccountFragment.java index 57188ed..a9c6387 100644 --- a/app/src/main/java/com/unionmed/unionmedtv/login/activity/fragment/LoginAccountFragment.java +++ b/app/src/main/java/com/unionmed/unionmedtv/login/activity/fragment/LoginAccountFragment.java @@ -1,19 +1,35 @@ package com.unionmed.unionmedtv.login.activity.fragment; import android.app.Dialog; +import android.content.Intent; import android.os.Bundle; +import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.EditText; import android.widget.TextView; import androidx.fragment.app.Fragment; +import com.blankj.utilcode.util.EncryptUtils; +import com.hjq.http.EasyHttp; +import com.hjq.http.listener.OnHttpListener; import com.lxj.xpopup.XPopup; import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.interfaces.OnConfirmListener; import com.unionmed.unionmedtv.R; +import com.unionmed.unionmedtv.activity.MainActivity; +import com.unionmed.unionmedtv.api.AccountLoginApi; +import com.unionmed.unionmedtv.api.MobileLoginApi; +import com.unionmed.unionmedtv.bean.TokenBean; import com.unionmed.unionmedtv.dialog.TipDialog; +import com.unionmed.unionmedtv.network.ApiResponse; +import com.unionmed.unionmedtv.network.HttpData; +import com.unionmed.unionmedtv.utils.CacheUtil; +import com.unionmed.unionmedtv.utils.ToastUtils; + +import me.jessyan.autosize.utils.LogUtils; public class LoginAccountFragment extends Fragment implements View.OnClickListener { private static final String ARG_PARAM1 = "param1"; @@ -23,6 +39,9 @@ public class LoginAccountFragment extends Fragment implements View.OnClickListen private String mParam2; private View mRootView; private TextView tv_scan_code_login; + private EditText edit_phone; + private EditText edit_password; + private TextView tv_login; public LoginAccountFragment() { // Required empty public constructor @@ -59,6 +78,11 @@ public class LoginAccountFragment extends Fragment implements View.OnClickListen public void initView(View view) { tv_scan_code_login = view.findViewById(R.id.tv_scan_code_login); tv_scan_code_login.setOnClickListener(this); + edit_phone = view.findViewById(R.id.edit_phone); + edit_phone.setText(CacheUtil.getAccountNumber()); + edit_password = view.findViewById(R.id.edit_password); + tv_login = view.findViewById(R.id.tv_login); + tv_login.setOnClickListener(this); } @Override @@ -78,6 +102,50 @@ public class LoginAccountFragment extends Fragment implements View.OnClickListen getActivity().getSupportFragmentManager().beginTransaction() .replace(R.id.main_browse_fragment, new LoginPhoneFragment()) .commitNow(); + } else if (view.getId() == R.id.tv_login) { + if (TextUtils.isEmpty(edit_phone.getText().toString())) { + ToastUtils.s(getActivity(), "请输入手机号"); + return; + } + if (TextUtils.isEmpty(edit_password.getText().toString())) { + ToastUtils.s(getActivity(), "请输入密码"); + return; + } + AccountLogin(edit_phone.getText().toString(), + EncryptUtils.encryptMD5ToString(edit_password.getText().toString()).toLowerCase()); + } } + + //手机号登录 + public void AccountLogin(String mobile, String password) { + EasyHttp.post(getActivity()) + .api(new AccountLoginApi(mobile, password)) + .request(new OnHttpListener>>() { + + @Override + public void onSucceed(HttpData> apiResponseHttpData) { + LogUtils.e("成功:" + apiResponseHttpData.getCode()); + if (apiResponseHttpData.isRequestSucceed()) { + if (apiResponseHttpData.getData().getCode() == 200) { + TokenBean tokenBean = apiResponseHttpData.getData().getData(); + CacheUtil.setToken(tokenBean); + CacheUtil.setAccountNumber(tokenBean.getMobile()); + CacheUtil.saveImUserAccount(tokenBean.getIm_useraccount()); + CacheUtil.saveImUserPwd(tokenBean.getIm_password()); + CacheUtil.saveImTokenRong(tokenBean.getIm_token()); + Intent intent = new Intent(getActivity(), MainActivity.class); + getActivity().startActivity(intent); + } + } + } + + + @Override + public void onFail(Exception e) { + ToastUtils.s(getActivity(), "登录失败"); + LogUtils.e("失败:" + e); + } + }); + } } \ No newline at end of file diff --git a/app/src/main/java/com/unionmed/unionmedtv/login/activity/fragment/LoginPhoneFragment.java b/app/src/main/java/com/unionmed/unionmedtv/login/activity/fragment/LoginPhoneFragment.java index bd876a9..940a9e2 100644 --- a/app/src/main/java/com/unionmed/unionmedtv/login/activity/fragment/LoginPhoneFragment.java +++ b/app/src/main/java/com/unionmed/unionmedtv/login/activity/fragment/LoginPhoneFragment.java @@ -20,6 +20,7 @@ import com.unionmed.unionmedtv.activity.MainActivity; import com.unionmed.unionmedtv.api.GetCodeApi; import com.unionmed.unionmedtv.api.GetNearDoctorApi; import com.unionmed.unionmedtv.api.MobileLoginApi; +import com.unionmed.unionmedtv.bean.TokenBean; import com.unionmed.unionmedtv.network.ApiResponse; import com.unionmed.unionmedtv.network.HttpData; import com.unionmed.unionmedtv.utils.CacheUtil; @@ -79,6 +80,7 @@ public class LoginPhoneFragment extends Fragment implements View.OnClickListener tv_account_login = view.findViewById(R.id.tv_account_login); tv_account_login.setOnClickListener(this); edit_phone = view.findViewById(R.id.edit_phone); + edit_phone.setText(CacheUtil.getAccountNumber()); edit_code = view.findViewById(R.id.edit_code); tv_getVerification = view.findViewById(R.id.tv_getVerification); tv_getVerification.setOnClickListener(this); @@ -122,20 +124,22 @@ public class LoginPhoneFragment extends Fragment implements View.OnClickListener public void onSucceed(HttpData> apiResponseHttpData) { LogUtils.e("成功:" + apiResponseHttpData); ToastUtils.s(getActivity(), "获取验证码成功"); - if (apiResponseHttpData.getData().getCode() == 200) { - tv_getVerification.setEnabled(false); - new CountDownTimer(60 * 1000, 1000) { - @Override - public void onTick(long l) { - tv_getVerification.setText("已发送(" + (l / 1001) + ") s"); - } - - @Override - public void onFinish() { - tv_getVerification.setText("获取验证码"); - tv_getVerification.setEnabled(true); - } - }.start(); + if (apiResponseHttpData.isRequestSucceed()) { + if (apiResponseHttpData.getData().getCode() == 200) { + tv_getVerification.setEnabled(false); + new CountDownTimer(60 * 1000, 1000) { + @Override + public void onTick(long l) { + tv_getVerification.setText("已发送(" + (l / 1001) + ") s"); + } + + @Override + public void onFinish() { + tv_getVerification.setText("获取验证码"); + tv_getVerification.setEnabled(true); + } + }.start(); + } } } @@ -151,26 +155,29 @@ public class LoginPhoneFragment extends Fragment implements View.OnClickListener public void MobileLogin(String mobile, String code) { EasyHttp.post(getActivity()) .api(new MobileLoginApi(mobile, code)) - .request(new OnHttpListener>>() { + .request(new OnHttpListener>>() { @Override - public void onSucceed(HttpData> apiResponseHttpData) { + public void onSucceed(HttpData> apiResponseHttpData) { LogUtils.e("成功:" + apiResponseHttpData); - if (apiResponseHttpData.getData().getCode() == 200) { - MobileLoginApi.TokenBean tokenBean=apiResponseHttpData.getData().getData(); - CacheUtil.setToken(tokenBean); - CacheUtil.setAccountNumber(tokenBean.getMobile()); - CacheUtil.saveImUserAccount(tokenBean.getIm_useraccount()); - CacheUtil.saveImUserPwd(tokenBean.getIm_password()); - CacheUtil.saveImTokenRong(tokenBean.getIm_token()); - Intent intent=new Intent(getActivity(),MainActivity.class); - getActivity().startActivity(intent); + if (apiResponseHttpData.isRequestSucceed()) { + if (apiResponseHttpData.getData().isInnerRequestSucceed()) { + ToastUtils.s(getActivity(), "登录成功"); + TokenBean tokenBean = apiResponseHttpData.getData().getData(); + CacheUtil.setToken(tokenBean); + CacheUtil.setAccountNumber(tokenBean.getMobile()); + CacheUtil.saveImUserAccount(tokenBean.getIm_useraccount()); + CacheUtil.saveImUserPwd(tokenBean.getIm_password()); + CacheUtil.saveImTokenRong(tokenBean.getIm_token()); + Intent intent = new Intent(getActivity(), MainActivity.class); + getActivity().startActivity(intent); + } } } @Override public void onFail(Exception e) { - ToastUtils.s(getActivity(), "获取验证码失败"); + ToastUtils.s(getActivity(), "登录失败"); LogUtils.e("失败:" + e); } }); diff --git a/app/src/main/java/com/unionmed/unionmedtv/utils/CacheUtil.java b/app/src/main/java/com/unionmed/unionmedtv/utils/CacheUtil.java index b7343d2..9466adc 100644 --- a/app/src/main/java/com/unionmed/unionmedtv/utils/CacheUtil.java +++ b/app/src/main/java/com/unionmed/unionmedtv/utils/CacheUtil.java @@ -7,6 +7,7 @@ import com.google.gson.Gson; import com.tencent.mmkv.MMKV; import com.unionmed.unionmedtv.R; import com.unionmed.unionmedtv.api.MobileLoginApi; +import com.unionmed.unionmedtv.bean.TokenBean; public class CacheUtil { private static MMKV kv = MMKV.mmkvWithID(StringUtils.getString(R.string.mmap_id)); @@ -14,19 +15,19 @@ public class CacheUtil { /** * 获取保存的用户信息 */ - public static MobileLoginApi.TokenBean getToken() { + public static TokenBean getToken() { String tokenStr = kv.decodeString(StringUtils.getString(R.string.token_id)); if (TextUtils.isEmpty(tokenStr)) { return null; } else { - return new Gson().fromJson(tokenStr, MobileLoginApi.TokenBean.class); + return new Gson().fromJson(tokenStr, TokenBean.class); } } /** * 设置用户信息 */ - public static void setToken(MobileLoginApi.TokenBean token) { + public static void setToken(TokenBean token) { if (token == null) { kv.encode(StringUtils.getString(R.string.token_id), ""); setIsLogin(false); @@ -108,6 +109,12 @@ public class CacheUtil { return kv.decodeString(StringUtils.getString(R.string.im_token), ""); } + /** + * 是否已经登录 + */ + public static Boolean isLogin() { + return kv.decodeBool(StringUtils.getString(R.string.is_login), false); + } /** * 设置是否已经登录 diff --git a/app/src/main/res/layout/fragment_account_login.xml b/app/src/main/res/layout/fragment_account_login.xml index 66d1c05..8d442f4 100644 --- a/app/src/main/res/layout/fragment_account_login.xml +++ b/app/src/main/res/layout/fragment_account_login.xml @@ -35,6 +35,7 @@ android:inputType="number" android:paddingLeft="15dp" android:textColorHint="#ffffff" + android:textColor="#ffffff" android:textSize="21sp" />