Android Integrated Mob Platform to Acquire Short Message Verification Code

Keywords: Android SDK Mobile Junit

First, when using the SMS authentication code of Mob platform, you need to register your account on the official website and obtain the developer's qualification to apply for AppKey and AppSecret.

Register Mob Account Official Address: http://www.mob.com After registering, Click to enter the background.


Enter the background and click on the SMS Verification Code to select Enable Click Enter


Get AppKey and AppSecret as follows

2. After getting Key, download the SDK we need and then develop it at http://www.mob.com/#/download Detail/SMS/ Android You can choose Eclipse and Android We chose Android Studio for the two versions of Studio


Create a new Android Studio project and put the jar package and SMSDK. AAR file in the SDK SMSSDK folder we downloaded into our project libs as follows


Then add the dependency attention aar file to build.gradle, which is the version you downloaded when you downloaded SDK

  1. repositories{  
  2.     flatDir{  
  3.         dirs 'libs' //That's the directory address where you put aar  
  4.     }  
  5. }  
  6.   
  7. dependencies {  
  8.     compile fileTree(include: ['*.jar'], dir: 'libs')  
  9.     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {  
  10.         exclude group: 'com.android.support', module: 'support-annotations'  
  11.     })  
  12.     compile 'com.android.support:appcompat-v7:24.2.1'  
  13.     testCompile 'junit:junit:4.12'  
  14.     compile files('libs/MobTools-2016.1012.1447.jar')  
  15.     compile files('libs/MobCommons-2016.1012.1447.jar')  
  16.     compile name:'SMSSDK-2.1.2',ext:'aar'  
  17.     compile name:'SMSSDKGUI-2.1.2',ext:'aar'  
  18. }  
3. Start writing our code layout file with a simple Button button

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:id="@+id/activity_main"  
  5.     android:layout_width="match_parent"  
  6.     android:layout_height="match_parent"  
  7.     tools:context="com.shiran.smsdemo.MainActivity">  
  8.   
  9.     <Button  
  10.         android:id="@+id/button_Sms"  
  11.         android:layout_width="match_parent"  
  12.         android:layout_height="wrap_content"  
  13.         android:layout_centerInParent="true"  
  14.         android:text="Get the authentication code"/>  
  15. </RelativeLayout>  
Next up is the code in our Activity

  1. package com.shiran.smsdemo;  
  2.   
  3. import android.support.v7.app.AppCompatActivity;  
  4. import android.os.Bundle;  
  5. import android.view.View;  
  6. import android.widget.Button;  
  7.   
  8. import java.util.HashMap;  
  9. import java.util.Random;  
  10.   
  11. import cn.smssdk.EventHandler;  
  12. import cn.smssdk.SMSSDK;  
  13. import cn.smssdk.gui.RegisterPage;  
  14.   
  15. public class MainActivity extends AppCompatActivity implements View.OnClickListener{  
  16.     private Button mButton = null;  
  17.   
  18.     @Override  
  19.     protected void onCreate(Bundle savedInstanceState) {  
  20.         super.onCreate(savedInstanceState);  
  21.         setContentView(R.layout.activity_main);  
  22.         //Fill in AppKey and AppSecret for the application  
  23.         SMSSDK.initSDK(this"1906c8bda69aa""a0bb14448c09bb3a03be461a18c512ff");//Initialize SDK  
  24.         mButton = (Button) findViewById(R.id.button_Sms);  
  25.         mButton.setOnClickListener(this);  
  26. }  
  27.   
  28.     @Override  
  29.     public void onClick(View v) {  
  30.         if(mButton == v){  
  31.      //Open the registration interface  
  32.      RegisterPage registerPage = new RegisterPage();  
  33.      registerPage.setRegisterCallback(new EventHandler() {//Event call listener class  
  34.   
  35.      @Override  
  36.      public void afterEvent(int event, int result, Object data) {//Short message SDK operation callback  
  37.       super.afterEvent(event, result, data);  
  38.   
  39.          //Resolve registration results  
  40.       if (result == SMSSDK.RESULT_COMPLETE) {//If the status is complete, the registration is successful  
  41.           //Getting data in Data  
  42.           HashMap<String, Object> dataMaps = (HashMap<String, Object>) data;  
  43.           //Access to information about the country in which the mobile phone number is located  
  44.           String country = (String) dataMaps.get("country");  
  45.           //Get the number of the phone that received the authentication code  
  46.           String phone = (String) dataMaps.get("phone");  
  47.           //Submit information to mob registration  
  48.           submitInfo(country, phone);  
  49.       }  
  50.   
  51.  }  
  52. });  
  53.   
  54.    //Step 3: Display the registration interface  
  55.    registerPage.show(MainActivity.this);  
  56.   
  57.     }  
  58. }  
  59.     private void submitInfo(String country, String phone) {  
  60.         Random r = new Random();  
  61.         String uid = Math.abs(r.nextInt()) + "";  
  62.         String nickName = "Set up a nickname";  
  63.         SMSSDK.submitUserInfo(uid, nickName, null, country, phone);//Submit user information and return it in the interception  
  64.     }  
  65. }  

When Mob is enabled by default, only validation can be done, that is, after the first validation of a mobile phone number, the next validation can be done intelligently, and the smart validation can be turned off in the Mob background management SMS settings as follows:


Run the test and paste out the screenshots by the way.





test When I use the test machine, I use my own mobile phone to receive short messages. This is the authentication code received by the mobile phone.

Posted by xionhack on Sat, 20 Apr 2019 09:27:34 -0700