短信验证模板
来源:互联网 发布:autodesk软件卸载工具 编辑:程序博客网 时间:2024/06/08 08:03
XML文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <RelativeLayout style="@style/Title_layout"> <RelativeLayout android:id="@+id/mime_authen_back" style="@style/Title_back_layout"> <ImageView style="@style/red_Title_back" /> </RelativeLayout> <TextView style="@style/Title_text" android:text="身份验证" /> </RelativeLayout> <TextView android:id="@+id/authentication" android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginLeft="10dp" android:gravity="center_vertical" android:text="请输入" android:textColor="#000" /> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:background="#fff" android:gravity="center_vertical" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:text="短信验证" android:textColor="#000" /> <View android:layout_width="1dp" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:background="#666" /> <EditText android:id="@+id/authen_writecode" android:layout_width="100dp" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="@null" android:hint="短信验证码" /> <TextView android:id="@+id/authen_getcode" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="90dp" android:text="获取验证码" android:textColor="#f00" /> </LinearLayout> <TextView android:id="@+id/authenticaiton_measure" android:layout_width="300dp" android:layout_height="45dp" android:layout_gravity="center_horizontal" android:layout_marginTop="15dp" android:background="@drawable/log_background" android:gravity="center" android:text="确定" android:textColor="#fefefe" android:textSize="20sp" /></LinearLayout>Activity文件
import android.annotation.TargetApi;import android.app.ProgressDialog;import android.content.Intent;import android.content.SharedPreferences;import android.graphics.Color;import android.os.Handler;import android.os.Message;import android.os.Bundle;import android.view.View;import android.view.Window;import android.view.WindowManager;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;import com.android.volley.AuthFailureError;import com.android.volley.RequestQueue;import com.android.volley.Response;import com.android.volley.VolleyError;import com.android.volley.toolbox.StringRequest;import com.umeng.analytics.MobclickAgent;import com.yyekt.Constants;import com.yyekt.R;import com.yyekt.appliaciton.App;import com.yyekt.utils.MyLog;import com.yyekt.utils.VolleyUtils;import org.json.JSONException;import org.json.JSONObject;import java.util.HashMap;import java.util.Map;public class AuthenticationActivity extends BaseActivity implements View.OnClickListener { private TextView authen_getcode,authenticaiton_measure,authentication; private EditText authen_writecode; private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg != null) { if (msg.what == 88) { if (msg.arg1 > 0) { authen_getcode.setText("(" + msg.arg1 + ")" + "秒可用"); authen_getcode.setTextColor(Color.GRAY); } else { authen_getcode.setEnabled(true); authen_getcode.setText("获取验证码"); authen_getcode.setTextColor(Color.RED); } } } } }; private String strContent; private String phone; private RequestQueue requestQueue; private String nickName,sex,head; private Bundle bundle; private ProgressDialog progressDialog; private String uid,deviceToken; private JSONObject result; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_authentication); progressDialog = new ProgressDialog(this); progressDialog.setMessage("正在加载..."); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); Intent intent = getIntent(); phone = intent.getStringExtra("phone"); authentication=(TextView)findViewById(R.id.authentication); authentication.setText("请输入"+phone+"收到的短信验证码"); requestQueue= VolleyUtils.getQueue(getApplicationContext()); authen_getcode=(TextView)findViewById(R.id.authen_getcode); authen_getcode.setOnClickListener(this); authenticaiton_measure=(TextView)findViewById(R.id.authenticaiton_measure); authenticaiton_measure.setOnClickListener(this); authen_writecode=(EditText)findViewById(R.id.authen_writecode); findViewById(R.id.mime_authen_back).setOnClickListener(this); } @Override public void onClick(View v) { int id = v.getId(); switch (id){ case R.id.authen_getcode: progressDialog.show(); //获取验证码 StringRequest stringRequest= new StringRequest(StringRequest.Method.POST,Constants.USING_LIBRARY + Constants.VERIFICAITON_CODE, new Response.Listener<String>() { @Override public void onResponse(String s) { try { MyLog.e("Authentication--onclick--url=",Constants.USING_LIBRARY + Constants.VERIFICAITON_CODE); JSONObject jsonObject = new JSONObject(s); MyLog.e("jsonObject",jsonObject.toString()); String msg = jsonObject.getString("message"); String errorCode = jsonObject.getString("errorCode"); String jsessionid = jsonObject.getString("result"); App.jsessionid = jsessionid; boolean success = jsonObject.getBoolean("success"); if(success){ strContent=msg; App.jsessionid = jsessionid; authen_getcode.setEnabled(false); progressDialog.cancel(); Toast.makeText(AuthenticationActivity.this, msg, Toast.LENGTH_LONG).show(); Thread thread = new Thread(new Runnable() { int cout = 60; boolean flag = true; @Override public void run() { while (flag) { if (cout == 0) { flag = false; } Message message = Message.obtain(); message.what = 88; message.arg1 = cout--; handler.sendMessage(message); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }); thread.start(); }else{ progressDialog.cancel(); Toast.makeText(AuthenticationActivity.this, msg, Toast.LENGTH_LONG).show(); } } catch (Exception e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { } }) { @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> map = new HashMap<String, String>(); map.put("username", phone); map.put("mark", "3"); return map; } }; requestQueue.add(stringRequest); break; case R.id.authenticaiton_measure: //确定 final String writCode=authen_writecode.getText().toString().trim(); final String soleId = App.getSoleId(this); StringRequest stringRequest1= new StringRequest(StringRequest.Method.POST,Constants.USING_LIBRARY + Constants.LOGIN_VERIFICATION+";jsessionid="+App.jsessionid, new Response.Listener<String>() { @Override public void onResponse(String s) { JSONObject jsonObject = null;// try {// jsonObject = new JSONObject(s);// MyLog.e("kkk","authentication--queding--jsonobject"+jsonObject.toString());// String msg = jsonObject.getString("message");// String errorCode = jsonObject.getString("errorCode");// String jsessionid = jsonObject.getString("result");// boolean success = jsonObject.getBoolean("success");// if(success){// Toast.makeText(AuthenticationActivity.this,msg , Toast.LENGTH_SHORT).show();// result = jsonObject.getJSONObject("result");// MyLog.e("kkk", "authentication--soleId"+result.getString("soleId"));// MyLog.e("kkk","authentication--jsessionid"+result.getString("sessionId"));// writeConfig(result);// Intent intent1 = new Intent();// intent1.putExtra("nickname", result.getString("nickname"));// intent1.putExtra("sex", result.getString("sex"));// intent1.putExtra("head", result.getString("head"));// setResult(88, intent1);// finish();// }else{// Toast.makeText(AuthenticationActivity.this,msg+"!!" , Toast.LENGTH_SHORT).show();// }// } catch (JSONException e) {// e.printStackTrace();// }} }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { } }) { @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> map = new HashMap<String, String>(); map.put("username", phone); map.put("messageCode", writCode);// MyLog.e("kkk", "authentication--queding--messagecode=" + writCode);// MyLog.e("kkk","authentication--queding--soleId="+soleId);// MyLog.e("kkk","authentication--queding--phone="+phone); return map; } }; requestQueue.add(stringRequest1); break; case R.id.mime_authen_back: finish(); break; } } public void writeConfig(JSONObject obj) throws JSONException { SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE); SharedPreferences.Editor edit = sp.edit(); edit.putString("id", obj.getString("id")); edit.commit(); }}
0 0
- 短信验证模板
- 短信验证码之签名和模板
- 添加短信内容模板,腾讯云短信开发案例-短信平台验证码开发4
- 短信验证
- 短信验证
- 短信验证
- 短信验证
- 短信验证
- 短信验证
- 短信验证
- 短信验证
- 短信验证
- 短信验证
- 短信验证
- 短信验证
- 短信验证
- 短信验证
- 短信验证
- LPC1778/1788的初步开发问题
- 746 D. Green and Black Tea codeforces
- CAD的一些命令,希望对大家有帮助哦!!!
- 如何查看知道某一个网站是由哪种编程语言写的?绝对准确全面!(精)
- sql server分页查询
- 短信验证模板
- androidstudio导入so简单的方法
- 骑士旅行pascal解题程序
- # Android 极光推送服务器端和移动端
- 可变长度参数列表讲解
- python 学习笔记1
- PostgreSQL学习篇9.8 位串类型
- python编写windows桌面程序(小Demo)
- sybase 利用backup server进行备份