package com.moretickets.platform; import com.alibaba.fastjson.JSONException; import com.alibaba.fastjson.JSONObject; import sun.rmi.runtime.Log; import java.util.regex.Matcher; import java.util.regex.Pattern; public class SendSMSCode { private int countSeconds = 60;//倒计时秒数 private EditText mobile_login, yanzhengma; private Button getyanzhengma1, login_btn; private Context mContext; private String usersuccess; private Handler mCountHandler = newHandler () { @Override public void the handleMessage (the Message MSG) { Super .handleMessage (MSG); IF (countSeconds> 0 ) { - countSeconds; getyanzhengma1.setText ( "Get codes after)" "(" + countSeconds + ) ; mCountHandler.sendEmptyMessageDelayed ( 0, 1000 ); } the else { countSeconds = 60 ; getyanzhengma1.setText ( "Please re-obtain codes" ); } } }; Private String userinfomsg; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; setContentView(R.layout.activity_login); initView(); initEvent(); initData(); } private void initView() { mobile_login = (EditText) findViewById(R.id.mobile_login); getyanzhengma1 = (Button) findViewById(R.id.getyanzhengma1); yanzhengma = (EditText) findViewById(R.id.yanzhengma); login_btn = (Button) findViewById(R.id.login_btn); } private void initEvent() { getyanzhengma1.setOnClickListener(this); login_btn.setOnClickListener(this); } private void initData() { } @Override public void onClick(View v) { switch (v.getId()) { case R.id.getyanzhengma1: if (countSeconds == 60) { String mobile = mobile_login.getText().toString(); Log.e("tag", "mobile==" + mobile); getMobiile(mobile); } else { Toast.makeText(LoginActivity.this, "不能重复发送验证码", Toast.LENGTH_SHORT).show(); } break; case R.id.login_btn: login(); break; default: break; } } // get information log public void Login () { String Mobile = mobile_login.getText () toString () TRIM ();.. String verifyCode = .. Yanzhengma.getText () toString () TRIM (); RequestParams the params = new new RequestParams ( "where the interface into your login request"); . x.http () POST (the params, new new Callback.ProgressCallback <String> () { @Override public void the OnWaiting () { } @Override public void OnStarted ( ) { } @Override public void onLoading(long total, long current, boolean isDownloading) { } @Override public void onSuccess(String result) { try { JSONObject jsonObject = new JSONObject(result); Log.e("tag", "登陆的result=" + jsonObject); String success = jsonObject.optString("success"); String data = jsonObject.optString("data"); MSG String{jsonObject.optString = ( "MSG" ); IF ( "to true" .equals (Success)) { Log.e ( "Tag", "landing = Data" + Data); the JSONObject JSON = new new the JSONObject (Data); token json.optString = ( "token" ); userId = json.optString ( "userId" ); // I write here as I had asked, and you can also change the appropriate // obtain user information of state getUserInfo (); } the else Toast.makeText(LoginActivity.this, msg, Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onError(Throwable ex, boolean isOnCallback) { } @Override public void onCancelled(CancelledException cex) { } @Override public void onFinished() { } }); } // get codes information, determines whether the phone number Private void getMobiile (Mobile String) { IF ( "" .equals (Mobile)) { Log.e ( "Tag", "Mobile =" + Mobile ); new new AlertDialog.Builder (mContext) .setTitle ( "prompt") .setMessage ( "phone number can not be empty") .setCancelable ( to true ) the .Show (); } the else IF (isMobileNO (Mobile) == to false ) { new new AlertDialog.Builder (mContext) .setTitle ( "Tip") .setMessage ( "Please enter the correct phone number").setCancelable(true).show(); } the else { Log.e ( "Tag", "entered the correct phone number" ); requestVerifyCode (Mobile); } } // get codes information, the verification code Private void requestVerifyCode (String Mobile) { RequestParams requestParams = new new requestParams ( "here is your PIN request interfaces allow you to background, what is added after the parameters"); x.http () POST (requestParams,. new new Callback.ProgressCallback <String> () { @Override public void The OnWaiting () { } @Override public void onStarted() { } @Override public void onLoading(long total, long current, boolean isDownloading) { } @Override public void onSuccess(String result) { try { JSONObject jsonObject2 = new JSONObject(result); Log.e("tag", "jsonObject2" + jsonObject2); String state = jsonObject2.getString("success"); VerifyCode StringJsonObject2.getString = ( "MSG" ); Log.e ( "Tag", "get codes ==" + verifyCode); IF ( "to true" .equals (State)) { . Toast.makeText (LoginActivity the this , verifyCode , Toast.LENGTH_SHORT) the .Show (); startCountBack (); // this is a request for parameters } the else { Toast.makeText (LoginActivity. the this , verifyCode, Toast.LENGTH_SHORT) the .Show (); } } the catch(JSONException E) { e.printStackTrace (); } } @Override public void the onError (the Throwable EX, Boolean isOnCallback) { ex.printStackTrace (); } @Override public void onCancelled (CancelledException CEX) { } @Override public void onFinished () { } }) ; } // a regular expression determined telephone numbers public static BooleanisMobileNO (Tel String) { the Pattern P = of Pattern.compile ( "^ (13 is [0-9] | 15 ([0-3] | [5-9]) | 14 [5,7,9] |. 17 [. 1 , 3,5,6,7,8] | 18 is [0-9]) \\ {D} $. 8 " ); Matcher m = p.matcher (Tel); System.out.println (m.matches () + "---" ); return m.matches (); } // get codes information, counting operation Private void startCountBack () { ((the Activity) mContext) .runOnUiThread ( new new the Runnable () { @Override public void RUN () { getyanzhengma1.setText (countSeconds + "" ); mCountHandler.sendEmptyMessage ( 0 ); } }); } }