I. Brief introduction to verification process of SMS SDK verification code
After filling in the user name and password, SMS authentication can be performed. As email authentication is cumbersome, SMS authentication is generally used.
The core process of SMS verification is as follows:
If it is to do their own SMS verification function, it is best to follow the above process. In order to save money, we usually use the third-party SMS verification SDK for development. Take MOB’s SMS verification SDK as an example. The SDK has encapsulated the above process, and users only need to know the API interface to perform SMS verification. For the trial period, there’s a limit of 20 per day.
2. SMS SDK access
1. Register in the WEBSITE of SMS SDK, and then register the APP to obtain APPKey and other information.
2. Integrate according to official documents. Note that in Android Studio Library dependencies are made through Module information. In addition, if jar package conflicts (duplicates) occur, it is better to create an additional globalLibrary and put that JAR in it, delete the other modules and reference globalLibrary.
3. Use SMS SDK
1. Generally speaking, SDK initialization is required, and APPKey and other information are passed in during initialization. Methods that are deregistered should also be called in onDestroy() to avoid memory leaks.
SMSSDK.initSDK(.......) ;Copy the code
2. Develop according to official documents. The use of each SET of SDK is different, so you need to read the documents carefully. Encountered do not understand, in addition to the document, the official Demo can also refer to or Copy.
Points to note:
1. Generally, the request for SMS verification code requires the country code and phone number as parameters, which is 86 in China. It is best to check the validity of the phone number, such as length and regular expression matching. Examples are as follows:
* @param phone * @param code */ private void checkPhoneNum(String phone, String code) { if (code.startsWith("+")) { code = code.substring(1); } if (textutils.isempty (phone)) {toastutils.showtoast (this, "please input your phone number "); return; } if (code == "86") { if (phone.length() ! = 11) {ToastUtils. ShowToast (this, "phone length wrong "); return; }} / / regular match China mobile phone number String rule = "^ 1 (8 | | | | 5 4) \ \ d {9}"; Pattern p = Pattern.compile(rule); Matcher m = p.matcher(phone); if (! M.matches ()) {ToastUtils. ShowToast (this, "You entered the format of the mobile phone number is not correct "); return; }}Copy the code
2. The interval for requesting the SMS verification code should be longer than 60 seconds (depending on the SPECIFIC SDK). Otherwise, the server will return “Request too frequently”. So let’s customize the button timer:
public class CountTimerView extends CountDownTimer { public static final int TIME_COUNT = 61000; // Time prevents display from 59s (take countdown 60s as example) private TextView BTN; private int endStrRid; /** * countDownInterval countDownInterval countDownInterval countDownInterval countDownInterval For general purposes MY argument is set to TextView) * parameter endStrRid after the countdown ends, */ public CountTimerView(long \ countDownInterval, TextView BTN, int endStrRid) { super(millisInFuture, countDownInterval); this.btn = btn; this.endStrRid = endStrRid; Public CountTimerView(TextView BTN, int endStrRid) {super(TIME_COUNT, 1000);} public CountTimerView(TextView BTN, int endStrRid) {super(TIME_COUNT, 1000); this.btn = btn; this.endStrRid = endStrRid; } public CountTimerView(TextView btn) { super(TIME_COUNT, 1000); this.btn = btn; this.endStrRid = R.string.smssdk_resend_identify_code; } @override public void onFinish() {btn.settext (endStrRid); btn.setEnabled(true); } @override public void onTick(long ^ ^ ^ untilfinished) {btn.setenabled (false); Btn. setText(^ ^ ^ ^ 5 +); btn.setText(^ ^ 5 +); }}Copy the code
4. Complete process of SMS verification
1. User data User name and password
2. Check the validity of the user name and password
3. Invoke the interface of SMS SDK to obtain the verification code and obtain the verification code
4. The user receives the message and enters the verification code
5. Obtain the verification code entered by the user and invoke the interface for verifying the SMS SDK verification code
6. After the verification is passed, call your server’s registration API in the callback to register (in fact, this is the core code), successfully register, destroy the Activity, jump to the main Activity.
If you feel that my words are helpful to you, welcome to pay attention to my public number:
My group welcomes everyone to come in and discuss all kinds of technical and non-technical topics. If you are interested, please add my wechat huannan88 and I will take you into our group.