安卓 短信验证MobSMS集成

概念及原理

了解MobSMS

 

主要API

初始化接口

 

短信验证接口

 

短信验证回调

 

 

代码部分

MobSMS添加到项目中:

S1.下载官方SDK文件link

S2.添加并配置SDK库文件:

    添加aar/jar文件到\app\libs项目目录

    配置build.gradle

repositories{

    flatDir{

        dirs 'libs' // SMSSDK-2.1.4.aar/SMSSDKGUI-2.1.4.aar文件目录

    }

}

dependencies {

    compile fileTree(include: ['*.jar'], dir: 'libs')

    compile name: 'SMSSDK-2.1.4', ext: 'aar'

    compile name: 'SMSSDKGUI-2.1.4', ext: 'aar'

    compile files('libs/MobTools-2017.0321.1624.jar')

    compile files('libs/MobCommons-2017.0321.1624.jar')

}

S3.配置manifest.xml文件:

<uses-permission android:name="android.permission.READ_CONTACTS" />

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.RECEIVE_SMS" />

<uses-permission android:name="android.permission.READ_SMS" />

<uses-permission android:name="android.permission.GET_TASKS" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

 

<activity

android:name="com.mob.tools.MobUIShell"

android:theme="@android:style/Theme.Translucent.NoTitleBar"

android:configChanges="keyboardHidden|orientation|screenSize"

android:windowSoftInputMode="stateHidden|adjustResize"/>

S4.获取AppKey/AppSecret:

 

http://dashboard.mob.com/#/sms/index

应用 => 添加应用 => Android => 添加

 

调用MobSMS短信服务:

// MobSMS SDK初始化
SMSSDK.initSDK(this, "您的appkey", "您的appsecret");
// 获取验证码
SMSSDK.getVerificationCode("86", PhoneNumber, null);
// 提交验证码
SMSSDK.submitVerificationCode("86", PhoneNumber,VerifyCode);
// 短信验证回调
    EventHandler eh = new EventHandler() {
        @Override
        public void afterEvent(int event, int result, Object data) {
            if (result == SMSSDK.RESULT_COMPLETE) {
                //回调完成
                if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) {
                    //提交验证码成功
                    Log.i("EventHandler", "提交验证码成功");
                } else if (event == SMSSDK.EVENT_GET_VERIFICATION_CODE) {
                    //获取验证码成
                    Log.i("EventHandler", "获取验证码成功");
                } else if (event == SMSSDK.EVENT_GET_SUPPORTED_COUNTRIES) {
                    //返回支持发送验证码的国家列表
                    Log.i("EventHandler", "返回支持发送验证码的国家列表");
                }
            } else {
                ((Throwable) data).printStackTrace();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        infoText.setText("短信验证失败");
                    }
                });
                Log.i("EventHandler", "回调失败");
            }
        }
    };

  

参考文档:

    MobSMS 下载SDK

    Github项目

    官方SDK集成文档 参考

    无GUI接口概述

    Android 短信SDK操作回调

posted @ 2017-06-01 23:51  zhen-Android  阅读(1429)  评论(0编辑  收藏  举报