expert-app/app/src/main/java/cn/shangyu/gdxzExpert/activity/BindNumberActivity.java
2025-11-18 15:12:24 +08:00

513 lines
22 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cn.shangyu.gdxzExpert.activity;
import static cn.shangyu.gdxzExpert.activity.LoginNewActivity.PatientUrl;
import static cn.shangyu.gdxzExpert.activity.RegistActivity.MSG_SEND;
import static cn.shangyu.gdxzExpert.umeng.PushHelper.addUMToken;
import static cn.shangyu.gdxzExpert.utils.CommonUtil.getDeviceInfo;
import static cn.shangyu.gdxzExpert.utils.UIUtils.getHandler;
import static cn.shangyu.gdxzExpert.utils.Url.getsendSms;
import static cn.shangyu.gdxzExpert.utils.Url.umGetMobile;
import static cn.shangyu.gdxzExpert.utils.Url.umVerifyLogin;
import static cn.shangyu.gdxzExpert.utils.Url.wechatBindMobile;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import com.netease.nimlib.sdk.AbortableFuture;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.RequestCallbackWrapper;
import com.netease.nimlib.sdk.ResponseCode;
import com.netease.nimlib.sdk.StatusBarNotificationConfig;
import com.netease.nimlib.sdk.auth.AuthService;
import com.netease.nimlib.sdk.auth.LoginInfo;
import com.umeng.message.PushAgent;
import com.umeng.umverify.UMResultCode;
import com.umeng.umverify.UMVerifyHelper;
import com.umeng.umverify.listener.UMTokenResultListener;
import com.umeng.umverify.model.UMTokenRet;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import cn.shangyu.gdxzExpert.R;
import cn.shangyu.gdxzExpert.base.BaseActivity;
import cn.shangyu.gdxzExpert.http.OnCallBackFromNet;
import cn.shangyu.gdxzExpert.netease.DemoCache;
import cn.shangyu.gdxzExpert.netease.config.preference.Preferences;
import cn.shangyu.gdxzExpert.netease.config.preference.UserPreferences;
import cn.shangyu.gdxzExpert.umeng.AuthPageConfig;
import cn.shangyu.gdxzExpert.umeng.BaseUIConfig;
import cn.shangyu.gdxzExpert.utils.Constant;
import cn.shangyu.gdxzExpert.utils.SharePrefUtil;
import cn.shangyu.gdxzExpert.utils.StringUtil;
import cn.shangyu.gdxzExpert.utils.ToastUtil;
import cn.shangyu.gdxzExpert.utils.UIUtils;
import cn.shangyu.gdxzExpert.utils.ValidateUtils;
import cn.shangyu.gdxzExpert.widget.LoadingPage;
import cn.shangyu.gdxzExpert.widget.TimeButton;
public class BindNumberActivity extends BaseActivity implements OnCallBackFromNet {
private TimeButton mTb_message;
private EditText usernameEditText,messageEditText;
private Button bt_login;
private String currentUsername,wechat_user_info;
private String currentPassword;
private String checkInfo;
private UMTokenResultListener mTokenResultListener;
private UMVerifyHelper mPhoneNumberAuthHelper;
private AuthPageConfig mUIConfig;
@Override
public void setTitle() {
top_title.setText("绑定手机");
}
@Override
public View onCreateSuccessedView() {
View view = UIUtils.inflate(R.layout.activity_bind_number);
usernameEditText = (EditText) view.findViewById(R.id.username);// 账号
// 设置输入框获得焦点hint提示消失添加监听
usernameEditText.setOnFocusChangeListener(onFocusAutoClearHintListener);
messageEditText = (EditText) view.findViewById(R.id.et_get_message);
mTb_message = (TimeButton) view.findViewById(R.id.tb_send_message);
mTb_message.onCreate();
mTb_message.clearTimer();
mTb_message.setTextBefore("获取验证码").setLenght(60 * 1000);
bt_login = (Button) view.findViewById(R.id.bt_login);// 登录
mTb_message.setOnClickListener(this);
bt_login.setOnClickListener(this);// 登录
wechat_user_info=getIntent().getStringExtra("wechat_user_info");
sdkInit();
return view;
}
private void login()
{
Map<String, String> param = new HashMap<>();
param.put("mobile",currentUsername);
param.put("current_spec",getDeviceInfo());
param.put("wechat_user_info",wechat_user_info);
param.put("sms", currentPassword);
sendJsonPostParamtoNetSignMD5(wechatBindMobile,param,101,this);
}
@Override
public LoadingPage.ResultState onLoad() {
return LoadingPage.ResultState.STATE_SUCCESSED;
}
@Override
protected void processClick(View v) {
// AGP 8.0+ R.id 不再是 final 常量,不能用于 switch改用 if-else
int id = v.getId();
if (id == R.id.bt_login) {
// 登录
View view = getWindow().peekDecorView();
if (view != null) {
InputMethodManager inputmanger = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
if (TextUtils.isEmpty(currentUsername)) {
currentUsername = usernameEditText.getText().toString();
}
currentPassword = messageEditText.getText().toString();
if (TextUtils.isEmpty(currentUsername)) {
ToastUtil.showToast("手机号码不为空");
return;
}
if (!ValidateUtils.isMobileNum(currentUsername)) {
ToastUtil.showToast("手机号码不正确");
return;
}
if (TextUtils.isEmpty(currentPassword)) {
ToastUtil.showToast("验证码不为空");
return;
}
login();
} else if (id == R.id.tb_send_message) {
// 短信验证码
currentUsername = usernameEditText.getText().toString();
Map<String, String> param = new HashMap<>();
param.put("mobile",currentUsername);
param.put("type","7");
sendJsonPostParamtoNetSignMD5(getsendSms,param,MSG_SEND,this);
}
}
public void sdkInit() {
// showProgressDialog("网络检测中");
mTokenResultListener = new UMTokenResultListener() {
@Override
public void onTokenSuccess(String s) {
// closeProgressDialog();
mPhoneNumberAuthHelper.hideLoginLoading();
UMTokenRet tokenRet = null;
try {
tokenRet = UMTokenRet.fromJson(s);
if(UMResultCode.CODE_ERROR_ENV_CHECK_SUCCESS.equals(tokenRet.getCode()))
{
mPhoneNumberAuthHelper.getLoginToken(BindNumberActivity.this,3000);
}
else if(UMResultCode.CODE_ERROR_ENV_CHECK_SUCCESS.equals(tokenRet.getCode()))
{
mPhoneNumberAuthHelper.getLoginToken(BindNumberActivity.this,3000);
}
else if (UMResultCode.CODE_START_AUTHPAGE_SUCCESS.equals(tokenRet.getCode())) {
Log.d("LoginTAG", "唤起授权页成功:" + s);
}
else if (UMResultCode.CODE_GET_TOKEN_SUCCESS.equals(tokenRet.getCode())) {
Log.d("LoginTAG", "获取token成功" + s);
// mPhoneNumberAuthHelper.hideLoginLoading();
// mPhoneNumberAuthHelper.quitLoginPage();
getResultWithToken(tokenRet.getToken());
}
else
{
ToastUtil.showMessage(s);
}
} catch (Exception e) {
e.printStackTrace();
Log.d("LoginTAG", "获取token失败" + e.toString());
}
}
@Override
public void onTokenFailed(String s) {
Log.d("LoginTAG", "获取token失败" + s);
mPhoneNumberAuthHelper.hideLoginLoading();
// Toast.makeText(BindNumberActivity.this, s, Toast.LENGTH_SHORT).show();
}
};
mPhoneNumberAuthHelper = UMVerifyHelper.getInstance(this, mTokenResultListener);
// mPhoneNumberAuthHelper.setAuthSDKInfo("UW4GwA7BR6ezYeEym4Dp4foswuAY4SLnFMauEQYaeMAEMzoa8n7TPIVRxIzi7wmoNYgAufQ7kw1GeRIdyouCHNol4UboQ6RGzVjyXFQLrgZjM8yjsEGiDYOPRzn1/EchKMOO3jtYM3XOTqSNnNk/r0NcBdisBINbskO7IojS33SUoym0IIk7xMAIOsKIb/67wM/GrCB0jxs3Jpiv9spflMP+GtwwpvZY9VXOCLWFshi1nhC63GIg0KFHF+wsDZoS9fAlKnRnayReYRQf9dayywdoh8XXrpoeZpu2rnkUDlkqXDZ11fHA5rC5znhkstd7");
//联通升级
mPhoneNumberAuthHelper.setAuthSDKInfo("ekYGnmwFM/LIyP8CwBJtN7OPVgg9UJuLlAS2yfVvhHYxbd3zx5mzRtkCU2S+81j5t1NjiHwDiirFISu8mApJhsOHqpqq9fDVfmsrcLhEfDUuzlVpPTVYcN0+B2Rxm+zK1FzLVq6VGf+GOLW2NLmH5VbJXLDX5wPdedcHSgsJikyD6+OypaDr/01DjsVLt8ElMqxcrptYWccUAAPQdvucA0tcjQcUN6beJpcB3zSTZghbvt0K6gjrNfzTb3ypudW5iPb55XYEGeqh0K3YmNphTLhiL+GC5oGJ+tNfsjICKau//5TTTmYGAw==");
mUIConfig = BaseUIConfig.init(1,this, mPhoneNumberAuthHelper);
mUIConfig.configAuthPage();
mPhoneNumberAuthHelper.checkEnvAvailable(2);
}
String token;
public void getResultWithToken(String token) {
this.token=token;
showProgressDialog("正在绑定");
Map<String, String> param = new HashMap<>();
param.put("token",token);
sendJsonPostParamtoNetSignMD5(umGetMobile,param,201,this);
}
@Override
public void onCallbackFromThread(String resultJson) {
}
@Override
public void onCallBackFromThread(String resultJson, int resultCode) {
Log.e("LoginTAG", "resultJson "+resultJson+" resultCode"+resultCode);
switch (resultCode)
{
case MSG_SEND:
try {
JSONObject objs = new JSONObject(resultJson);
String retcode = objs.getString("code");
String message = objs.getString("message");
if (retcode.equals("200")) {
mTb_message.startTimer();
} else {
ToastUtil.showToast(message);
mTb_message.clearTimer();
}
} catch (JSONException e) {
// TODO Auto-generated catch block
ToastUtil.showToast("获取验证码失败,请重试");
mTb_message.clearTimer();
e.printStackTrace();
}
break;
case 202:
closeProgressDialog();
case 101:
try {
JSONObject objs = new JSONObject(resultJson);
String retcode = objs.optString("code");
String message = objs.optString("msg");
if ("200".equals(retcode)) {
getSaveUserInfor(2,objs);
// 得到个人资料,并保存
// getSaveUserInfor(2,objs);
}
else {
ToastUtil.showToast(message);
}
} catch (JSONException e) {
e.printStackTrace();
}
break;
case 201:
try {
JSONObject objs = new JSONObject(resultJson);
String retcode = objs.getString("code");
String message = objs.getString("message");
if (retcode.equals("200")) {
if(objs.optJSONObject("data")!=null)
{
if(objs.optJSONObject("data").optJSONObject("data")!=null
&&!StringUtil.isEmpty(objs.optJSONObject("data").optJSONObject("data").optString("mobile")))
{
Map<String, String> param = new HashMap<>();
// param.put("token",token);
param.put("mobile",objs.optJSONObject("data").optJSONObject("data").optString("mobile"));
param.put("current_spec", getDeviceInfo());
param.put("wechat_user_info",wechat_user_info);
sendJsonPostParamtoNetSignMD5(umVerifyLogin,param,202,this);
Log.e("LoginTAG", "param "+param.toString());
}
}
} else {
ToastUtil.showToast(message);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
ToastUtil.showToast("一键登录失败");
e.printStackTrace();
}
break;
}
}
// 保存个人信息
public void getSaveUserInfor(int type,JSONObject objs) throws JSONException {
JSONObject date = objs.getJSONObject("data");
String uuid = date.optString("uuid");
String realName = date.optString("realName");
String mobile = date.optString("mobile");
String photo = date.optString("photo");
String email = date.optString("email");
String birthDate = date.optString("birthDate");
String hospitalUuid = date.optString("hospitalUuid");
String hospitalName = date.optString("hospitalName");
String officeUuid = date.optString("officeUuid");
String officeName = date.optString("officeName");
String officePhone = date.optString("officePhone");
String positionUuid = date.optString("positionUuid");
String positionName = date.optString("positionName");
String intro = date.optString("intro");
String certificate = date.optString("certificate");
String certificateImg = date.optString("certificateImg");
String qrcode = date.optString("qrcode");
checkInfo = date.optString("checkInfo");
String cityId = date.optString("cityId");
String countyId = date.optString("countyId");
String provId = date.optString("provId");
int isStar = date.optInt("isStar");
int sex = date.optInt("sex");
int state = date.optInt("state");// 审核状态( 1.待审核 2.审核中 3.需要补充修改资料 4.再次提交审核 5.拒绝 6.已通过
SharePrefUtil.saveString(ct, Constant.USERID, uuid);
SharePrefUtil.saveString(ct, Constant.uuid, uuid);// 唯一标识我的uuid
SharePrefUtil.saveString(ct, Constant.realName, realName);// 真实姓名
SharePrefUtil.saveString(ct, Constant.mobile, mobile);// 手机号
if (!StringUtil.isEmpty(currentUsername)
&& ValidateUtils.isMobileNum(currentUsername)) {
SharePrefUtil.saveString(ct, Constant.SP_IS_FIRST_NAME,
Constant.mobile, currentUsername);// 手机号,这个为了重新登录后回显之前的手机号
} else if (!StringUtil.isEmpty(mobile)
&& ValidateUtils.isMobileNum(mobile)) {
SharePrefUtil.saveString(ct, Constant.SP_IS_FIRST_NAME,
Constant.mobile, mobile);// 手机号,这个为了重新登录后回显之前的手机号
}
SharePrefUtil.saveString(ct, Constant.photo, photo);// 头像路径
SharePrefUtil.saveString(ct, "email", email);// 邮箱
SharePrefUtil.saveString(ct, "birthDate", birthDate);// 出生日期
SharePrefUtil.saveString(ct, "hospitalUuid", hospitalUuid);// 坐诊医院uuid
SharePrefUtil.saveString(ct, "hospitalName", hospitalName);// 坐诊医院名称
SharePrefUtil.saveString(ct, "officeUuid", officeUuid);// 科室uuid
SharePrefUtil.saveString(ct, "officeName", officeName);// 科室名称
SharePrefUtil.saveString(ct, "officePhone", officePhone);// 科室电话
SharePrefUtil.saveString(ct, "positionUuid", positionUuid);// //职称uuid
SharePrefUtil.saveString(ct, "positionName", positionName);// //职称名称
SharePrefUtil.saveString(ct, "intro", intro);// 简介
SharePrefUtil.saveString(ct, "certificate", certificate);// 执业资格证
SharePrefUtil.saveString(ct, "certificateImg", certificateImg);// 执业资格证图片
SharePrefUtil.saveString(ct, "qrcode", qrcode);// 二维码
SharePrefUtil.saveString(ct, "checkInfo", checkInfo);// 审核信息
SharePrefUtil.saveString(ct, "cityId", cityId);// 市id
SharePrefUtil.saveString(ct, "countyId", countyId);// //区县id
SharePrefUtil.saveString(ct, "provId", provId);// 省id
SharePrefUtil.saveInt(ct, "isStar", isStar);// 是否是肝胆名医 0否 1是
SharePrefUtil.saveInt(ct, "sex", sex);// 性别0.男 1.女)
SharePrefUtil.saveInt(ct, "state", state);// 审核状态( 1.待审核
addUMToken(PushAgent.getInstance(this).getRegistrationId());
// 2.审核中3.需要补充修改资料
// 4.再次提交审核5.拒绝 6.已通过)
// 进行判断是否进入主页面还是进入设置页面
if(type==1)//老的登录
{
getLoginInfo(state,objs);
}
else
{
getLoginInfo(state,date);//友盟一键登录
}
}
public void getYunxin(JSONObject objs) throws JSONException {
String yx_accid =objs.getString("YX_accid");
String yx_token =objs.getString("YX_token");
SharePrefUtil.saveString(ct, Constant.yx_accid, yx_accid);
SharePrefUtil.saveString(ct, Constant.yx_token, yx_token);
}
public void getLoginInfo(int state,JSONObject objs) throws JSONException {
Log.d("LoginTAG","state "+state);
if (state != 6) {
// 需要完善资料,跳转到完善资料页面
// ToastUtil.showToast("登录成功,请完善资料");
// 启动登录设置信息界面
Log.d("LoginTAG","state1 "+state);
Intent intent = new Intent(this, LoginSetInfoActivity.class);
intent.putExtra("checkInfo", checkInfo);
intent.putExtra("state", state);
startActivity(intent);
closeProgressDialog();
SharePrefUtil.saveBoolean(ct, Constant.IS_LOGIN, false);
this.finish();
} else {
getYunxin(objs);
// 获取患者列表
String USERID = SharePrefUtil.getString(ct, Constant.USERID, "");
// 获取患者列表存到数据库
BaseActivity.getPatientList(this, PatientUrl, USERID);
String yx_accid =SharePrefUtil.getString(ct, Constant.yx_accid, "");
String yx_token =SharePrefUtil.getString(ct, Constant.yx_token, "");
doLauncherAction();
// 登录
loginYunxin(yx_accid,yx_token);
}
};
private void doLauncherAction() {
closeProgressDialog();
// ( 1.待审核 2.审核中 3.需要补充修改资料 4.再次提交审核 5.拒绝
// 6.已通过)
// 注册成功跳转
Intent intent = new Intent();
// if(BigModule())
// {
// intent.setClass(this, BigMainActivity.class);
//
// }
// else
// {
intent.setClass(this, MainActivity.class);
// }
intent.putExtra("launcher_from", 1);
startActivity(intent);
Constant.islogout = 2;
// 保存登陆
SharePrefUtil.saveBoolean(ct, Constant.IS_LOGIN, true);
// 1登入系统 2退出系统 3专家客户端在手机前台运行 4.专家客户端在手机后台运行
BaseActivity.foreBack(BindNumberActivity.this, 1);
}
public void loginYunxin(String yx_accid,String yx_token)
{
// 演示15s后手动登录登录成功后可以正常收发数据
getHandler().postDelayed(() -> {
AbortableFuture<LoginInfo> loginRequest = NIMClient.getService(AuthService.class).login(
new LoginInfo(yx_accid, yx_token));
loginRequest.setCallback(new RequestCallbackWrapper() {
@Override
public void onResult(int code, Object result, Throwable exception) {
Log.i("test", "real login, code=" + code);
if (code == ResponseCode.RES_SUCCESS) {
DemoCache.setAccount(yx_accid);
saveLoginInfo(yx_accid, yx_token);
// 初始化消息提醒配置
initNotificationConfig();
finish();
}
}
});
}, 5 * 1000);
}
private void saveLoginInfo(final String account, final String token) {
Preferences.saveUserAccount(account);
Preferences.saveUserToken(token);
}
private void initNotificationConfig() {
// 初始化消息提醒
NIMClient.toggleNotification(UserPreferences.getNotificationToggle());
// 加载状态栏配置
StatusBarNotificationConfig statusBarNotificationConfig = UserPreferences.getStatusConfig();
if (statusBarNotificationConfig == null) {
statusBarNotificationConfig = DemoCache.getNotificationConfig();
UserPreferences.setStatusConfig(statusBarNotificationConfig);
}
// 更新配置
NIMClient.updateStatusBarNotificationConfig(statusBarNotificationConfig);
}
/**
* 设置输入框获得焦点hint提示消失
*/
public static View.OnFocusChangeListener onFocusAutoClearHintListener = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
EditText textView = (EditText) v;
String hint;
if (hasFocus) {
hint = textView.getHint().toString();
textView.setTag(hint);
textView.setHint("");
} else {
hint = textView.getTag().toString();
textView.setHint(hint);
}
}
};
@Override
protected void onDestroy() {
super.onDestroy();
mUIConfig.release();
}
}