Git Product home page Git Product logo

sms-captcha's Introduction

SmsCaptcha

SmsCaptcha 是一个实现自动获取短信验证码的库。它通过注册 ContentObserver 来监听新短信并进行查询和解析验证码。

Download

使用方法

添加依赖:

compile 'com.parkingwang:sms-captcha:0.1'
//
implementation 'com.parkingwang:sms-captcha:0.1'

Java 代码:

注册观察者

        mCaptchaObserver = SmsCaptcha.with(this)
                .captchaLength(4)
                .addressLike("10657%")
                .fillTo(mSmsCode)
                .createAndRegister();

界面销毁时注销观察者

        mCaptchaObserver.unregister();

完整注册代码:

        mCaptchaObserver = SmsCaptcha.with(this)
                // 验证码长度
                .captchaLength(4)
                // 验证码长度可能不固定
                //.captchaLength(4, 6)
                .address("10086")
                //发送地址以10657开头
                //.addressLike("10657%")
                .contentStartWith("尊敬的客户")
                // 短信开头
                //.contentStartWith(".*客户")
                .captchaText("动态密码")
                // 自动填充
                //.fillTo(mEditText)
                // 自定义获取到验证码后的行为
                .onReceive(new CaptchaObserver.CaptchaListener() {
                    @Override
                    public void onCaptchaReceived(String code) {
                        Log.e("xxxx", code);
                    }
                })
                .createAndRegister();

API 文档

http://parkingwang.github.io/sms-captcha

部分手机做了验证码防窃取,会导致无法获取包含验证码的短信,如华为EMUI等。

sms-captcha's People

Contributors

msdx avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.