标签:amp bre utils user res cti create 手机 自己的
今日主要绘制了首页,圆盘页面,个人页面
效果如下:
今日也了解了获取验证码登录的部分,在网上了解到需要短信平台的接口,在网上找了几个但是注册需要营业执照,
验证码只能暂时搁置,只有一个代码框架,没有实际功能:
package com.example.cloudlibrary; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.os.CountDownTimer; import android.text.TextUtils; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import org.xutils.common.Callback; import org.xutils.http.RequestParams; import org.xutils.x; public class RegisterActivity extends AppCompatActivity implements View.OnClickListener{ private static final String TAG = "MainActivity"; private EditText register_username; private EditText register_userpass; private EditText register_userpass2; private EditText register_userphone; private EditText register_code; private TextView register_getcode; private Button register_submit; private int type = 1; private CountDownTimer mCountDownTimer = new CountDownTimer(60000, 1000) { @Override public void onTick(long l) { register_getcode.setText((l / 1000 )+ "秒后可重发"); } @Override public void onFinish() { register_getcode.setEnabled(true); register_getcode.setText("获取验证码"); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); register_username = (EditText) findViewById(R.id.register_username); register_userpass = (EditText) findViewById(R.id.register_userpass); register_userpass2 = (EditText) findViewById(R.id.register_userpass2); register_userphone= (EditText) findViewById(R.id.register_userphone); register_code = (EditText) findViewById(R.id.register_code); register_getcode = (TextView)findViewById(R.id.register_getcode); register_submit = (Button) findViewById(R.id.register_submit); register_getcode.setOnClickListener(this); register_submit.setOnClickListener(this); } @Override public void onClick(View v) { String phone = register_userphone.getText().toString().trim(); String captcha =register_code.getText().toString().trim(); String password = register_userpass.getText().toString().trim(); String repassword = register_userpass2.getText().toString().trim(); String name = register_username.getText().toString().trim(); switch (v.getId()) { case R.id.register_getcode: register_getcode.requestFocus(); if (!judgePhoneNums(phone)) { return; } else { mCountDownTimer.start(); //这里的服务器接口是无效的需要换成你自己获取验证码的接口地址 RequestParams params = new RequestParams("http://api.php/Public/getSmsCode"); String str = String.valueOf(type); //需要携带的参数 params.addBodyParameter("phone", phone); params.addBodyParameter("type", str); x.http().get(params, new Callback.CacheCallback<String>() { @Override public void onSuccess(String result) { Log.e(TAG, result.toString()); } @Override public void onError(Throwable ex, boolean isOnCallback) { } @Override public void onCancelled(CancelledException cex) { } @Override public void onFinished() { } @Override public boolean onCache(String result) { return false; } }); } break; case R.id.register_submit: if (!judgePhoneNums(phone)) { return; } else if(TextUtils.isEmpty(captcha)) { Toast.makeText(this, "验证码不能为空", Toast.LENGTH_SHORT).show(); } else if(password.length() < 6 ) { Toast.makeText(this, "请输入长度大于6位的密码", Toast.LENGTH_SHORT).show(); } else if(!TextUtils.equals(password,repassword)) { Toast.makeText(this, "两次输入的密码不一致", Toast.LENGTH_SHORT).show(); } else if(register_submit == v) { //这里的服务器接口是无效的需要换成你自己的注册接口地址 RequestParams params = new RequestParams("http://api.php/Public/smsRegister"); //需要带入的参数 params.addBodyParameter("phone", phone); params.addBodyParameter("captcha", captcha); params.addBodyParameter("password", password); params.addBodyParameter("repassword", repassword); x.http().post(params, new Callback.CacheCallback<String>() { @Override public void onSuccess(String result) { Log.e(TAG, result.toString()); } @Override public void onError(Throwable ex, boolean isOnCallback) { } @Override public void onCancelled(CancelledException cex) { } @Override public void onFinished() { } @Override public boolean onCache(String result) { return false; } }); break; } } } private boolean judgePhoneNums(String phoneNums) { if (isMatchLength(phoneNums, 11) && isMobileNO(phoneNums)) { return true; } Toast.makeText(this, "请输入正确的手机号",Toast.LENGTH_SHORT).show(); return false; } /** * 判断一个字符串的位数 * @param str * @param length * @return */ public static boolean isMatchLength(String str, int length) { if (str.isEmpty()) { return false; } else { return str.length() == length ? true : false; } } /** * 验证手机格式 */ public static boolean isMobileNO(String mobileNums) { String strTel = "[1][358]\\d{9}"; if (TextUtils.isEmpty(mobileNums)) return false; else return mobileNums.matches(strTel); }
验证码搁置,所以今天想尝试手机上传数据到Mysql数据库,本以为可以再手机端直接相连,
但是通过网上资料了解到app要通过web服务器交互,由web服务器写入数据库。
明日将主要解决app端与web服务器的数据交互。
标签:amp bre utils user res cti create 手机 自己的
原文地址:https://www.cnblogs.com/fengchuiguobanxia/p/14672478.html