个人应用,需要短信验证这么一个功能的话,mob的短信验证还是不错的。下面说一下集成过程

1.mob平台注册账号http://www.mob.com/

2.创建一个应用。对应会生成一个Appkey和 App Secret。

3.在新建项目左边栏目,将SMSSDK产品添加进去

4.下载SMDSDK,导入工程。(参照官方集成指南http://wiki.mob.com/sdk-sms-android-3-0-0/)

5.布局代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical"><android.support.v7.widget.Toolbar style="@style/ToolBar"><RelativeLayout style="@style/ToolBarContainerRelative"><ImageButton style="@style/ToolBarBackButton" /><TextView
                style="@style/ToolBarTitle"
                android:text="@string/login_phone_title"
                android:textColor="@color/top_bar_text_color" /></RelativeLayout></android.support.v7.widget.Toolbar><RelativeLayout
        android:id="@+id/login_country_layout"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:orientation="horizontal"
        android:paddingLeft="13dp"
        android:paddingRight="13dp"><TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:gravity="center"
            android:text="@string/login_country"
            android:textSize="@dimen/text_size_md_subheading" /><TextView
            android:id="@+id/login_country_tx"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:gravity="center"
            android:text="@string/login_country_act_title"
            android:textColor="@color/top_bar_text_color"
            android:textSize="@dimen/text_size_md_subheading" /></RelativeLayout><View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:background="@color/edit_hint_color" /><LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_marginTop="15dp"
        android:paddingLeft="13dp"
        android:orientation="horizontal"><TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="@dimen/text_size_md_subheading"
            android:text="+"/><TextView
            android:id="@+id/login_country_code"
            style="@style/LoginEdit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@null"
            android:text="86"
            android:digits="1234567890"
            android:maxLength="4"
            android:minLines="1" /><EditText
            android:id="@+id/login_name"
            style="@style/LoginEdit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:digits="1234567890"
            android:maxLength="11"
            android:background="@null"
            android:inputType="number"
            android:hint="@string/login_name_tip" /></LinearLayout><View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:background="@color/edit_hint_color" /><LinearLayout
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:orientation="horizontal"
        android:visibility="visible"
        ><!--android:layout_marginTop="@dimen/login_margin_btn"-->
        <EditText
            android:id="@+id/login_captcha"
            style="@style/LoginEdit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:layout_weight="1"
            android:drawablePadding="10dp"
            android:hint="@string/login_captcha_tip"
            android:inputType="number"
            android:background="@null"
            android:maxLength="4"
            android:paddingTop="20dp" /><Button
            android:id="@+id/login_captcha_countdown"
            style="@style/PrimaryButton_get"
            android:layout_gravity="center"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:text="@string/login_captcha_get"
            android:textColor="@color/colorPrimaryDark" /></LinearLayout><View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:background="@color/edit_hint_color" /><Button
        android:id="@+id/login_btn"
        android:layout_marginTop="40dp"
        android:text="@string/login"
        android:textColor="@color/colorPrimaryDark"
        style="@style/login_btn_style"
         /></LinearLayout>
//JAVA代码
package com.like.smartplug;import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;import com.jakewharton.rxbinding.view.RxView;import org.json.JSONObject;import java.util.concurrent.TimeUnit;import Base.BaseActivity;
import cn.smssdk.EventHandler;
import cn.smssdk.SMSSDK;
import cn.smssdk.utils.SMSLog;
import rx.functions.Action1;
import util.UtilCommon;import static com.like.smartplug.R.id.login_btn;/**
 * Created by like on 2017/5/17.
 */

public class SmsLoginActivity extends BaseActivity {private EditText edit_phone_login,edit_verify_code;private Button btn_get_verify,btn_commit_verify_code;private boolean flag = true;private CountDownTimer countDownTimer;//倒计时
    @Override
    public int getLayoutId() {return R.layout.activity_smslogin;}@Override
    public void init() {SMSSDK.initSDK(this, "1df0a48ca2b91", "053c87f0fecab8479fa9193386b69f3c");EventHandler eh=new EventHandler(){@Override
            public void afterEvent(int event, int result, Object data) {Message msg = new Message();msg.arg1 = event; //事件类型
                msg.arg2 = result;  //操作结果,为SMSSDK.RESULT_COMPLETE表示成功,为SMSSDK.RESULT_ERROR表示失败
                msg.obj = data;   //操作结果,如果result=SMSSDK.RESULT_ERROR,则类型为Throwable,如果result=SMSSDK.RESULT_COMPLETE需根据event判断:
                handlersm.sendMessage(msg);  //发送消息,等待UI处理
            }};SMSSDK.registerEventHandler(eh); //注册短信回调
    }@Override
    public void findid(Bundle savedInstanceState) {edit_phone_login= (EditText) findViewById(R.id.login_name);edit_verify_code= (EditText) findViewById(R.id.login_captcha);btn_get_verify= (Button) findViewById(R.id.login_captcha_countdown);btn_commit_verify_code= (Button) findViewById(login_btn);}@Override
    public void setlistener() {RxView.clicks(btn_get_verify).throttleFirst(UtilCommon.VIEW_THROTTLE_TIME, TimeUnit.MILLISECONDS).subscribe(new Action1<Void>() {@Override
                    public void call(Void aVoid) {String phone=edit_phone_login.getText().toString().trim();if (TextUtils.isEmpty(phone)){shortToast(getResources().getString(R.string.phone_null));return;}else if (!judgePhoneNumss(phone)){return;}SMSSDK.getVerificationCode("86",phone);edit_verify_code.requestFocus();countDownTimer = new CountDownTimer(60000, 1000) {@Override
                            public void onTick(long millisUntilFinished) {btn_get_verify.setText(getString(R.string.login_captcha_countdown,millisUntilFinished / 1000));}@Override
                            public void onFinish() {btn_get_verify.setText(R.string.login_captcha_get);countDownTimer = null;}}.start();}});RxView.clicks(btn_commit_verify_code).throttleFirst(UtilCommon.VIEW_THROTTLE_TIME,TimeUnit.MILLISECONDS).subscribe(new Action1<Void>() {@Override
                    public void call(Void aVoid) {if (TextUtils.isEmpty(edit_verify_code.getText().toString())){shortToast(getResources().getString(R.string.verify_code_null));return;}String phone=edit_phone_login.getText().toString().trim();String verifycode=edit_verify_code.getText().toString().trim();SMSSDK.submitVerificationCode("86",phone,verifycode);showLoadingDialog();}});}//UI线程处理handler的消息,这个handler用于接收短信回调事件
    Handler handlersm=new Handler(){@Override
        public void handleMessage(Message msg) {super.handleMessage(msg);int event = msg.arg1;int result = msg.arg2;Object data = msg.obj;Log.e("event", "event="+event);if (result == SMSSDK.RESULT_COMPLETE){if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE)//提交验证码成功,验证通过
                {Log.i("info", "handleMessage: "+getResources().getString(R.string.verify_succ));dismissLoadingDialog();Intent intent=new Intent(getApplication(),MainActivity.class);startActivity(intent);finish();}else if (event == SMSSDK.EVENT_GET_VERIFICATION_CODE)//服务器验证码发送成功
                {Log.i("info", "handleMessage: "+getResources().getString(R.string.verify_send));shortToast(getResources().getString(R.string.verify_send));}else if (event ==SMSSDK.EVENT_GET_SUPPORTED_COUNTRIES)//返回支持发送验证码的国家列表
                {shortToast(getResources().getString(R.string.get_country_code_succ));}}else
            {int status=0;try {dismissLoadingDialog();((Throwable) data).printStackTrace();Throwable throwable = (Throwable) data;JSONObject object = new JSONObject(throwable.getMessage());String des = object.optString("detail");status = object.optInt("status");if (!TextUtils.isEmpty(des)) {shortToast(des);return;}} catch (Exception e) {SMSLog.getInstance().w(e);}}}};//判断手机号码是否合理
    public boolean judgePhoneNumss(String number) {if (isMatchLength(number, 11)&& isMobileNO(number)) {return true;}shortToast(getResources().getString(R.string.input_phone_error));return false;}//判断一个字符串的位数
    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) {/*
        * 移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
        * 联通:130、131、132、152、155、156、185、186 电信:133、153、180、189、(1349卫通)
        * 总结起来就是第一位必定为1,第二位必定为3或5或8,其他位置的可以为0-9
        */
        String telRegex = "[1][3578]\\d{9}";// "[1]"代表第1位为数字1,"[358]"代表第二位可以为3、5、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。
        if (TextUtils.isEmpty(mobileNums))return false;else
            return mobileNums.matches(telRegex);}@Override
    protected void onDestroy() {super.onDestroy();SMSSDK.unregisterAllEventHandler();}
}
//这是2.1.4.版的,最新的SDK请参照官网开发指南进行集成,写这篇博客主要是想把这个思路写一下。看下效果图

使用MOB免费短信验证码进行登录(注册)相关推荐

  1. 20、实现短信验证码的登录注册功能

    实现短信验证码的登录注册功能 第一步:查看接口内容 为什么用@RequestBody因为其中我们前端传过来的是json数据那么后端我们就要用@requestBody注解来接收了. 查看写这个实体类 这 ...

  2. java发送QQ邮箱验证码实现登录注册、邮箱验证码防刷校验

    文章目录 一:前台功能实现 1.1 页面编写 1.2 发送验证码--sendEmailCode 1.2.1 远程调用发送接口 1.2.1 接口防刷校验--60s内只能发送一次 二:获取QQ邮箱授权码 ...

  3. springboot项目使用短信验证码的登录注册功能

    一. 操作流程 用户输入手机号,点击发送验证码按钮 前端将手机号发送给后端 后端生成一个6位的随机数通过短信发送给用户,之后手机号为key,随机数为value,存入缓存中,最后将短信发送是否成功的结果 ...

  4. 超详细编写登录注册页面(内含验证码登录)

    最近做项目,着实出师不利,刚登录就遇到bug,特在此记录一下,以此为鉴.首先,说明一下,这个登录页面内含验证码登录,当然也会有验证码验证,还有数据库没有设置加密,当然项目也没有强制要求,主要因为麻烦, ...

  5. 基于登录注册用ajax实现手机验证码功能

    文章目录 基于登录发送验证码 输入验证码后完成登录逻辑 用户登录条件 基于注册发送验证码 输入验证码后完成注册逻辑 用户注册条件 这几天做的项目接触到了用手机验证码完成一些功能,例如登录.注册.以及修 ...

  6. Flask项目实战——6—(前台用户模型、前台登录注册、图形验证码、手机短信验证码、添加表单验证短信验证码请求)

    1.前台用户模型 前台用户模型定义 创建前台模型文件 apps/front/models.py # -*- encoding: utf-8 -*- """ @File : ...

  7. 登录注册 图片验证码生成

    登录注册时,需要添加图片验证码校验防止恶意攻击.步骤如下: 1.后台生成图片验证码流,并记录code值到Session或Redis 中 2.请求过来后,附带图片验证码,从session或redis中获 ...

  8. App开发中利用Mob实现免费短信验证码

    涉及到用户注册的App经常会涉及到短信验证码,但是对于独立开发者来说,不可能因为几百几千个用户就去购买上千成本的短信验证码服务,因此,实现免费验证码便是开发中很重要的一个诀窍. 可能很多用户都已经知道 ...

  9. Mob秒验(一键登录注册)是什么意思?

    好奇一键登录是怎么实现的吗?进来了解一下? 自动识别当前手机使用的手机卡号,并且直接使用这个号码进行登录,这就是一键登录.这种登录方式的好处是显而易见的.它可以更方便.快捷地完成注册.登录流程,将原本 ...

最新文章

  1. 依赖包 全局_composer 更新指定的依赖包
  2. The substring() Method in JDK 6 and JDK 7
  3. 【黑客免杀攻防】读书笔记4 - 壳在免杀中的应用
  4. 3D网页游戏场景打包与加载
  5. Spring - @CompentScan全解
  6. Autolisp:利用AuoCAD之Lisp编程案例之自动智能获取所选对象的面积并标注在指定位置
  7. 【项目管理】进度管理
  8. Educational Codeforces Round 40 (Rated for Div. 2)
  9. 洛谷P4219 大融合(LCT、虚子树)
  10. MySQL进阶:从删库到跑路
  11. 四、python沉淀之路--元组
  12. 编程小工具总结(一) 取色器
  13. MATLAB车道识别与交通标志识别
  14. 解决:蓝奏云下载链接没法打开问题
  15. android加载大量图片内存优化,Android图片加载内存优化
  16. nexus5 博通芯片WIFI详解 (2)
  17. 科幻计算机类小说,五本超级火爆的科幻类小说,每一本都让你欲罢不能
  18. 富文本框TinyMCE4.8上传本地图片基本配置(前端篇)
  19. 5G通信技术书籍分享(持续更新)
  20. Python免费下载哔哩哔哩视频,只需一行代码!

热门文章

  1. 51cto学院微信支付实战对接开发视频教程
  2. 服务器显卡芯片,Intel服务器独立显卡官方美图:单卡四芯原来如此
  3. ios 应用特殊节日页面整体变灰
  4. matlab simulink 磷酸铁锂电池仿真
  5. 【HTCVR】VRTK基本功能脚本说明
  6. BI商业智能培训系列——(一)概述
  7. CPU内核部件之:MMU、MPU、ITCM、DTCM、CCM、Cache
  8. 【转】面向程序员的数据库访问性能优化法则
  9. Lua官网及下载地址
  10. lua os(操作系统)库