第二阶段每日汇报20230512

今天主要进行了验证登录的第二次调试,主要是解决了验证码不能进行下一次重发的问题

代码如下:

private void initView() {

et_phoneNum = findViewById(R.id.et_phoneNum);
et_password = findViewById(R.id.user_password);
btn_getMsg = findViewById(R.id.btn_getMsg);
btn_login = findViewById(R.id.btn_login);
imageView = findViewById(R.id.wechat_login);
btn_login.setOnClickListener(this);
btn_getMsg.setOnClickListener(this);


}


Handler handler = new Handler() {
@Override
public void handleMessage(@NonNull Message msg) {
if (msg.what == -9) {
btn_getMsg.setText("重新发送(" + i + ")");
} else if (msg.what == -8) {
btn_getMsg.setText("获取验证码");
btn_getMsg.setClickable(true);
i = 30;
} else {
int i = msg.arg1;
int i1 = msg.arg2;
Object o = msg.obj;
if (i1 == SMSSDK.RESULT_COMPLETE) {
// 短信注册成功后,返回MainActivity,然后提示
if (i == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) {
Toast.makeText(LoginActivity.this, "提交验证码成功", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
Bundle bundle = new Bundle();
bundle.putString("userName", et_phoneNum.getText().toString().trim());
intent.putExtras(bundle);
startActivity(intent);

} else if (i == SMSSDK.EVENT_GET_VOICE_VERIFICATION_CODE) {
Toast.makeText(LoginActivity.this, "正在获取验证码", Toast.LENGTH_SHORT).show();
}
}
}
}
};

 

@Override
public void onClick(View view) {
String phoneNum = et_phoneNum.getText().toString();
switch (view.getId()){
case R.id.btn_getMsg:
// 1. 判断手机号是不是11位并且看格式是否合理
if (!judgePhoneNums(phoneNum)){
return;
}
// 2. 通过sdk发送短信验证
SMSSDK.getVerificationCode("86",phoneNum);
// 3. 把按钮变成不可点击,并且显示倒计时(正在获取)
btn_getMsg.setClickable(false);
btn_getMsg.setText("重新发送(" + i + ")");
new Thread(new Runnable() {
@Override
public void run() {
for ( ; i > 0; i--) {
handler.sendEmptyMessage(-9);
if (i <= 0 ){
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
handler.sendEmptyMessage(-8);
}
}).start();
break;

case R.id.btn_login:
if (et_phoneNum == null){
Toast.makeText(LoginActivity.this,"手机号不能为空",Toast.LENGTH_SHORT).show();
Log.d(TAG, "onClick: 手机号不能为空");
}
if (et_password == null){
Toast.makeText(LoginActivity.this,"验证码不能为空",Toast.LENGTH_SHORT).show();
}
//将收到的验证码和手机号提交再次核对
SMSSDK.submitVerificationCode("86", phoneNum, et_password
.getText().toString());
break;
}
}
效果图如下:

posted @   一直队  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
点击右上角即可分享
微信分享提示