验证码
parent
eefb623bc0
commit
15cbb46413
@ -0,0 +1,211 @@
|
||||
package com.rehome.dywoa.ui.activity
|
||||
|
||||
|
||||
import android.text.Editable
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import com.google.gson.Gson
|
||||
import com.rehome.dywoa.Contans
|
||||
import com.rehome.dywoa.R
|
||||
import com.rehome.dywoa.base.BaseActivityOaToolbarViewBinding
|
||||
import com.rehome.dywoa.bean.YzmBean
|
||||
import com.rehome.dywoa.databinding.ActivityWjmmGetVerificationCodeBinding
|
||||
import com.rehome.dywoa.utils.GsonUtils
|
||||
import com.rehome.dywoa.utils.HttpListener
|
||||
import com.rehome.dywoa.utils.NohttpUtils
|
||||
import com.rehome.dywoa.utils.RSAUtils
|
||||
import com.rehome.dywoa.utils.UiUtlis
|
||||
import com.yolanda.nohttp.NoHttp
|
||||
import com.yolanda.nohttp.RequestMethod
|
||||
import java.util.*
|
||||
|
||||
class WjmmGetVerificationCodeActivity :
|
||||
BaseActivityOaToolbarViewBinding<ActivityWjmmGetVerificationCodeBinding>() {
|
||||
|
||||
private var token: String = ""
|
||||
private var token_exp: String = ""
|
||||
|
||||
override fun getViewBinding() = ActivityWjmmGetVerificationCodeBinding.inflate(layoutInflater)
|
||||
|
||||
override fun getToolbar() = binding.toolbarView.toolbar
|
||||
|
||||
override fun initView() {
|
||||
initToolbar("修改密码", "") {}
|
||||
|
||||
}
|
||||
|
||||
override fun initData() {
|
||||
var account = intent.getStringExtra("account")
|
||||
if(account!=null){
|
||||
binding.txGh.setText(account)
|
||||
}
|
||||
binding.buttonDjs.setOnClickListener(View.OnClickListener {
|
||||
if (TextUtils.isEmpty(binding.txGh.text.toString().trim())) {
|
||||
binding.txGh.error = "没有满足大写、小写、数字、符号"
|
||||
showToast("请先输入工号!")
|
||||
} else {
|
||||
if (TextUtils.isEmpty(
|
||||
binding.sjh.text.toString().trim()
|
||||
) || binding.sjh.text.toString().trim().length != 11
|
||||
) {
|
||||
binding.sjh.error = "没有满足大写、小写、数字、符号"
|
||||
showToast("手机号输入不正确")
|
||||
} else {
|
||||
binding.buttonDjs.start()
|
||||
getYzm()
|
||||
}
|
||||
}
|
||||
})
|
||||
binding.buttonNext.setOnClickListener(View.OnClickListener {
|
||||
if (TextUtils.isEmpty(binding.txGh.text.toString().trim())) {
|
||||
binding.txGh.error = "没有满足大写、小写、数字、符号"
|
||||
showToast("请先输入工号!")
|
||||
} else if (TextUtils.isEmpty(
|
||||
binding.sjh.text.toString().trim()
|
||||
) || binding.sjh.text.toString().trim().length != 11
|
||||
) {
|
||||
binding.sjh.error = "没有满足大写、小写、数字、符号"
|
||||
showToast("手机号输入不正确")
|
||||
} else if (TextUtils.isEmpty(binding.yzm.text.toString().trim())) {
|
||||
binding.yzm.error = "没有满足大写、小写、数字、符号"
|
||||
showToast("请输入验证码")
|
||||
} else {
|
||||
checkVerificationCode()
|
||||
}
|
||||
})
|
||||
|
||||
// binding.txGh.setText("ZHPS_Admin")
|
||||
// binding.sjh.setText("15307858521")
|
||||
}
|
||||
|
||||
private fun getYzm() {
|
||||
val json: String = getYzmParam()
|
||||
|
||||
val url = Contans.IP + Contans.GETYZMANDCHECKYZMANDMODIFYMIMA
|
||||
val request = NoHttp.createStringRequest(url, RequestMethod.POST)
|
||||
request.setDefineRequestBodyForJson(json)
|
||||
showLog(url)
|
||||
|
||||
NohttpUtils.getInstance().add(this, 0, request, object : HttpListener<String?> {
|
||||
override fun onSucceed(what: Int, response: com.yolanda.nohttp.rest.Response<String?>?) {
|
||||
val jsonResult = response?.get()
|
||||
|
||||
showLog("-----getYzm------")
|
||||
showLog(jsonResult)
|
||||
|
||||
val jsonDecode = RSAUtils.decryptBASE64StrClient(jsonResult)
|
||||
if (TextUtils.isEmpty(jsonDecode)) {
|
||||
showToast(UiUtlis.getString(context, R.string.data_error))
|
||||
} else {
|
||||
val bean: YzmBean? =
|
||||
GsonUtils.GsonToBean(jsonDecode, YzmBean::class.java)
|
||||
showLog(jsonDecode);
|
||||
if (bean != null && bean.rows != null && bean.rows.size > 0 && bean.rows[0].result == "1") {
|
||||
showToast(bean.rows[0].msg)
|
||||
binding.yzm.visibility = View.VISIBLE
|
||||
binding.verificationCodeLine.visibility = View.VISIBLE
|
||||
binding.buttonNext.visibility = View.VISIBLE
|
||||
if(bean.rows[0].token!=null){
|
||||
token = bean.rows[0].token
|
||||
}
|
||||
if(bean.rows[0].token_exp!=null){
|
||||
token_exp = bean.rows[0].token_exp
|
||||
}
|
||||
} else {
|
||||
if (bean != null) {
|
||||
showToast(bean.rows[0].msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailed(what: Int, response: com.yolanda.nohttp.rest.Response<String?>?) {
|
||||
Log.i("login", "onError")
|
||||
}
|
||||
}, true, true, "请稍候...")
|
||||
|
||||
}
|
||||
|
||||
//调用接口检查输入的验证码是否正确
|
||||
private fun checkVerificationCode() {
|
||||
|
||||
val json: String = getCheckYzmParam()
|
||||
val url = Contans.IP + Contans.GETYZMANDCHECKYZMANDMODIFYMIMA
|
||||
val request = NoHttp.createStringRequest(url, RequestMethod.POST)
|
||||
request.setDefineRequestBodyForJson(json)
|
||||
showLog(url)
|
||||
|
||||
|
||||
NohttpUtils.getInstance().add(this, 0,token, request, object : HttpListener<String?> {
|
||||
override fun onSucceed(what: Int, response: com.yolanda.nohttp.rest.Response<String?>?) {
|
||||
val jsonResult = response?.get()
|
||||
|
||||
showLog("-----CheckYzm------")
|
||||
showLog(jsonResult)
|
||||
|
||||
val jsonDecode = RSAUtils.decryptBASE64StrClient(jsonResult)
|
||||
if (TextUtils.isEmpty(jsonDecode)) {
|
||||
showToast(UiUtlis.getString(context, R.string.data_error))
|
||||
} else {
|
||||
val bean: YzmBean? =
|
||||
GsonUtils.GsonToBean(jsonDecode, YzmBean::class.java)
|
||||
showLog(jsonDecode);
|
||||
if (bean != null && bean.rows != null && bean.rows.size > 0 && bean.rows[0].result == "2") {
|
||||
//验证码正确
|
||||
// val intent = Intent(
|
||||
// context,
|
||||
// WjmmActivity::class.java
|
||||
// )
|
||||
// intent.putExtra("gh", binding.txGh.text.toString().trim())
|
||||
// intent.putExtra("sjh", binding.sjh.text.toString().trim())
|
||||
// if(!TextUtils.isEmpty(token)){
|
||||
// intent.putExtra("token", token)
|
||||
// intent.putExtra("token_exp", token_exp)
|
||||
// startActivity(intent)
|
||||
// }else{
|
||||
// showToast("验证码校验失败")
|
||||
// }
|
||||
} else {
|
||||
if (bean != null) {
|
||||
showToast(bean.rows[0].msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailed(what: Int, response: com.yolanda.nohttp.rest.Response<String?>?) {
|
||||
Log.i("login", "onError")
|
||||
}
|
||||
}, true, true, "请稍候...")
|
||||
}
|
||||
|
||||
fun getYzmParam(): String {
|
||||
|
||||
val param= mutableMapOf<String,String>()
|
||||
param["account"] = Objects.requireNonNull<Editable>(binding.txGh.text).toString().trim()
|
||||
|
||||
val json = Gson().toJson(param)
|
||||
val jsonEncrypt = RSAUtils.encryptBASE64Str(json)
|
||||
showLog(json);
|
||||
showLog(jsonEncrypt)
|
||||
return jsonEncrypt
|
||||
}
|
||||
|
||||
fun getCheckYzmParam(): String {
|
||||
|
||||
val param= mutableMapOf<String,String>()
|
||||
param["userid"] = Objects.requireNonNull<Editable>(binding.txGh.text).toString().trim()
|
||||
param["type"] = "3"
|
||||
param["telphone"] = Objects.requireNonNull<Editable>(binding.sjh.text).toString().trim()
|
||||
param["verificationcode"] = Objects.requireNonNull<Editable>(binding.yzm.text).toString().trim()
|
||||
param["token"] = token
|
||||
param["token_exp"] = token_exp
|
||||
|
||||
val json = Gson().toJson(param)
|
||||
val jsonEncrypt = RSAUtils.encryptBASE64Str(json)
|
||||
showLog(json);
|
||||
return jsonEncrypt
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
package com.rehome.dywoa.weiget;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatTextView;
|
||||
|
||||
/**
|
||||
* author : Android 轮子哥
|
||||
* github : https://github.com/getActivity/AndroidProject
|
||||
* time : 2018/10/18
|
||||
* desc : 验证码倒计时
|
||||
*/
|
||||
public final class CountdownView extends AppCompatTextView implements Runnable {
|
||||
|
||||
/** 倒计时秒数 */
|
||||
private int mTotalSecond = 60;
|
||||
/** 秒数单位文本 */
|
||||
private static final String TIME_UNIT = "S";
|
||||
|
||||
/** 当前秒数 */
|
||||
private int mCurrentSecond;
|
||||
/** 记录原有的文本 */
|
||||
private CharSequence mRecordText;
|
||||
|
||||
public CountdownView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public CountdownView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public CountdownView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置倒计时总秒数
|
||||
*/
|
||||
public void setTotalTime(int totalTime) {
|
||||
this.mTotalSecond = totalTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始倒计时
|
||||
*/
|
||||
public void start() {
|
||||
mRecordText = getText();
|
||||
setEnabled(false);
|
||||
mCurrentSecond = mTotalSecond;
|
||||
post(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束倒计时
|
||||
*/
|
||||
public void stop() {
|
||||
setText(mRecordText);
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
// 设置点击的属性
|
||||
setClickable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
// 移除延迟任务,避免内存泄露
|
||||
removeCallbacks(this);
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void run() {
|
||||
if (mCurrentSecond == 0) {
|
||||
stop();
|
||||
} else {
|
||||
mCurrentSecond--;
|
||||
setText(mCurrentSecond + " " + TIME_UNIT);
|
||||
postDelayed(this, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- 禁用状态 -->
|
||||
<item android:color="@color/white" android:state_enabled="false" />
|
||||
|
||||
<!-- 按压状态 -->
|
||||
<item android:color="@color/white" android:state_pressed="true" />
|
||||
|
||||
<!-- 焦点状态 -->
|
||||
<item android:color="@color/white" android:state_focused="true" />
|
||||
|
||||
<!-- 默认状态 -->
|
||||
<item android:color="@color/colorPrimaryDark" />
|
||||
|
||||
</selector>
|
||||
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- 禁用状态 -->
|
||||
<item android:color="@color/white" android:state_enabled="false" />
|
||||
|
||||
<!-- 按压状态 -->
|
||||
<item android:color="@color/white" android:state_pressed="true" />
|
||||
|
||||
<!-- 焦点状态 -->
|
||||
<item android:color="@color/white" android:state_focused="true" />
|
||||
|
||||
<!-- 默认状态 -->
|
||||
<item android:color="@color/colorAccent" />
|
||||
|
||||
</selector>
|
||||
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 默认获取验证码按钮样式 -->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- 禁用状态 -->
|
||||
<item android:state_enabled="false">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="30dp" />
|
||||
<solid android:color="@color/colorButtonDisable" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<!-- 按压状态 -->
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="30dp" />
|
||||
<solid android:color="@color/colorAccent" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<!-- 焦点状态 -->
|
||||
<item android:state_focused="true">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="30dp" />
|
||||
<solid android:color="@color/colorAccent"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<!-- 默认状态 -->
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="30dp" />
|
||||
<stroke android:color="@color/colorPrimaryDark"
|
||||
android:width="1dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</selector>
|
||||
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 默认获取验证码按钮样式 -->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- 禁用状态 -->
|
||||
<item android:state_enabled="false">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="30dp" />
|
||||
<solid android:color="@color/colorButtonDisable" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<!-- 按压状态 -->
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="30dp" />
|
||||
<solid android:color="@color/colorAccent" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<!-- 焦点状态 -->
|
||||
<item android:state_focused="true">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="30dp" />
|
||||
<solid android:color="@color/colorAccent"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<!-- 默认状态 -->
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="30dp" />
|
||||
<stroke android:color="@color/colorAccent"
|
||||
android:width="1dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</selector>
|
||||
@ -0,0 +1,133 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".ui.activity.WjmmGetVerificationCodeActivity">
|
||||
|
||||
<include
|
||||
android:id="@+id/toolbarView"
|
||||
layout="@layout/layout_base" />
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/white">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="40dp"
|
||||
tools:layoutAnimation="@null">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_tipTop"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
android:gravity="start"
|
||||
android:text="@string/the_first_step_tip_first"
|
||||
android:textColor="@color/login_title_color"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_tipTopDesc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:gravity="start"
|
||||
android:text="@string/the_first_step_tip_first_desc"
|
||||
android:textColor="@color/textColor"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText
|
||||
android:id="@+id/tx_gh"
|
||||
style="@style/EditTextStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:hint="请输入工号(必填)"
|
||||
android:maxLength="20"
|
||||
android:maxLines="1" />
|
||||
|
||||
<View style="@style/HorizontalLineStyle" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="0px"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.rehome.dywoa.weiget.RegexEditText
|
||||
android:id="@+id/sjh"
|
||||
style="@style/EditTextStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="输入手机号码(必填)"
|
||||
android:inputType="textVisiblePassword"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
app:regexType="mobile" />
|
||||
|
||||
<View
|
||||
style="@style/HorizontalLineStyle"
|
||||
android:layout_gravity="bottom" />
|
||||
</FrameLayout>
|
||||
|
||||
<com.rehome.dywoa.weiget.CountdownView
|
||||
android:id="@+id/button_djs"
|
||||
style="@style/CountdownViewStyle" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText
|
||||
android:id="@+id/yzm"
|
||||
style="@style/EditTextStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:hint="@string/common_code_input_hint"
|
||||
android:inputType="number"
|
||||
android:maxLength="6"
|
||||
android:singleLine="true"
|
||||
android:visibility="gone" />
|
||||
|
||||
<View
|
||||
android:id="@+id/verificationCodeLine"
|
||||
style="@style/HorizontalLineStyle"
|
||||
android:visibility="gone" />
|
||||
|
||||
<com.rehome.dywoa.weiget.CountdownView
|
||||
android:id="@+id/buttonNext"
|
||||
style="@style/CountdownViewBigStyle"
|
||||
android:layout_marginTop="20dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_tip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="40dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:gravity="start"
|
||||
android:text=""
|
||||
android:textColor="@color/red"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</LinearLayout>
|
||||
Loading…
Reference in New Issue